Skip to content

Commit eb4a441

Browse files
committed
Auto merge of #12419 - smoelius:plural-acronyms, r=dswij
Handle plural acronyms in `doc_markdown` Prevent `doc_markdown` from triggering on words like `OSes` and `UXes`. changelog: handle plural acronyms in `doc_markdown`
2 parents 193456e + cc4c8db commit eb4a441

File tree

4 files changed

+30
-2
lines changed

4 files changed

+30
-2
lines changed

clippy_lints/src/doc/markdown.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,14 @@ fn check_word(cx: &LateContext<'_>, word: &str, span: Span) {
6060
return false;
6161
}
6262

63-
let s = s.strip_suffix('s').unwrap_or(s);
63+
let s = if let Some(prefix) = s.strip_suffix("es")
64+
&& prefix.chars().all(|c| c.is_ascii_uppercase())
65+
&& matches!(prefix.chars().last(), Some('S' | 'X'))
66+
{
67+
prefix
68+
} else {
69+
s.strip_suffix('s').unwrap_or(s)
70+
};
6471

6572
s.chars().all(char::is_alphanumeric)
6673
&& s.chars().filter(|&c| c.is_uppercase()).take(2).count() > 1

tests/ui/doc/doc-fixable.fixed

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,3 +230,8 @@ fn issue_11568() {}
230230

231231
/// There is no try (`do()` or `do_not()`).
232232
fn parenthesized_word() {}
233+
234+
/// `ABes`
235+
/// OSes
236+
/// UXes
237+
fn plural_acronym_test() {}

tests/ui/doc/doc-fixable.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,3 +230,8 @@ fn issue_11568() {}
230230

231231
/// There is no try (do() or do_not()).
232232
fn parenthesized_word() {}
233+
234+
/// ABes
235+
/// OSes
236+
/// UXes
237+
fn plural_acronym_test() {}

tests/ui/doc/doc-fixable.stderr

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,5 +341,16 @@ help: try
341341
LL | /// There is no try (do() or `do_not()`).
342342
| ~~~~~~~~~~
343343

344-
error: aborting due to 31 previous errors
344+
error: item in documentation is missing backticks
345+
--> tests/ui/doc/doc-fixable.rs:234:5
346+
|
347+
LL | /// ABes
348+
| ^^^^
349+
|
350+
help: try
351+
|
352+
LL | /// `ABes`
353+
| ~~~~~~
354+
355+
error: aborting due to 32 previous errors
345356

0 commit comments

Comments
 (0)