Skip to content

Handle plural acronyms in doc_markdown #12419

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion clippy_lints/src/doc/markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,14 @@ fn check_word(cx: &LateContext<'_>, word: &str, span: Span) {
return false;
}

let s = s.strip_suffix('s').unwrap_or(s);
let s = if let Some(prefix) = s.strip_suffix("es")
&& prefix.chars().all(|c| c.is_ascii_uppercase())
&& matches!(prefix.chars().last(), Some('S' | 'X'))
{
prefix
} else {
s.strip_suffix('s').unwrap_or(s)
};

s.chars().all(char::is_alphanumeric)
&& s.chars().filter(|&c| c.is_uppercase()).take(2).count() > 1
Expand Down
5 changes: 5 additions & 0 deletions tests/ui/doc/doc-fixable.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -230,3 +230,8 @@ fn issue_11568() {}

/// There is no try (`do()` or `do_not()`).
fn parenthesized_word() {}

/// `ABes`
/// OSes
/// UXes
fn plural_acronym_test() {}
5 changes: 5 additions & 0 deletions tests/ui/doc/doc-fixable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,3 +230,8 @@ fn issue_11568() {}

/// There is no try (do() or do_not()).
fn parenthesized_word() {}

/// ABes
/// OSes
/// UXes
fn plural_acronym_test() {}
13 changes: 12 additions & 1 deletion tests/ui/doc/doc-fixable.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -341,5 +341,16 @@ help: try
LL | /// There is no try (do() or `do_not()`).
| ~~~~~~~~~~

error: aborting due to 31 previous errors
error: item in documentation is missing backticks
--> tests/ui/doc/doc-fixable.rs:234:5
|
LL | /// ABes
| ^^^^
|
help: try
|
LL | /// `ABes`
| ~~~~~~

error: aborting due to 32 previous errors