Skip to content

Commit

Permalink
Handle plural acronyms in doc_markdown
Browse files Browse the repository at this point in the history
  • Loading branch information
smoelius committed Mar 4, 2024
1 parent 5214ab5 commit cc4c8db
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
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

0 comments on commit cc4c8db

Please sign in to comment.