about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-03-05 10:47:40 +0000
committerbors <bors@rust-lang.org>2024-03-05 10:47:40 +0000
commiteb4a441c090acfca1232f39ae2c7c3f520d66473 (patch)
treeca5fa86739584732579be0490547a74efae14c35
parent193456e0a592b3b7a17413a73e2c941e7a0a27e2 (diff)
parentcc4c8db0fd9e85ba0f686eb938e97e8c9d987ca4 (diff)
downloadrust-eb4a441c090acfca1232f39ae2c7c3f520d66473.tar.gz
rust-eb4a441c090acfca1232f39ae2c7c3f520d66473.zip
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`
-rw-r--r--clippy_lints/src/doc/markdown.rs9
-rw-r--r--tests/ui/doc/doc-fixable.fixed5
-rw-r--r--tests/ui/doc/doc-fixable.rs5
-rw-r--r--tests/ui/doc/doc-fixable.stderr13
4 files changed, 30 insertions, 2 deletions
diff --git a/clippy_lints/src/doc/markdown.rs b/clippy_lints/src/doc/markdown.rs
index a58219c2946..3bedd425141 100644
--- a/clippy_lints/src/doc/markdown.rs
+++ b/clippy_lints/src/doc/markdown.rs
@@ -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
diff --git a/tests/ui/doc/doc-fixable.fixed b/tests/ui/doc/doc-fixable.fixed
index 16f7bafd44b..178d4a1aa2b 100644
--- a/tests/ui/doc/doc-fixable.fixed
+++ b/tests/ui/doc/doc-fixable.fixed
@@ -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() {}
diff --git a/tests/ui/doc/doc-fixable.rs b/tests/ui/doc/doc-fixable.rs
index 4058b2bad74..01edb44c64c 100644
--- a/tests/ui/doc/doc-fixable.rs
+++ b/tests/ui/doc/doc-fixable.rs
@@ -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() {}
diff --git a/tests/ui/doc/doc-fixable.stderr b/tests/ui/doc/doc-fixable.stderr
index 7db9ff2b83b..ac876306b39 100644
--- a/tests/ui/doc/doc-fixable.stderr
+++ b/tests/ui/doc/doc-fixable.stderr
@@ -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