Skip to content

Commit 75aaa88

Browse files
doc_comments_missing_terminal_punctuation: exclude doc attributes to avoid FP
1 parent 61b1f19 commit 75aaa88

5 files changed

+25
-41
lines changed

clippy_lints/src/doc/doc_comments_missing_terminal_punctuation.rs

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,19 @@ const MSG: &str = "doc comments should end with a terminal punctuation mark";
1010
const PUNCTUATION_SUGGESTION: char = '.';
1111

1212
pub fn check(cx: &LateContext<'_>, doc: &str, fragments: Fragments<'_>) {
13-
if let Some(offset) = is_missing_punctuation(doc) {
14-
if let Some(span) = fragments.span(cx, offset..offset) {
15-
clippy_utils::diagnostics::span_lint_and_sugg(
16-
cx,
17-
DOC_COMMENTS_MISSING_TERMINAL_PUNCTUATION,
18-
span,
19-
MSG,
20-
"end the doc comment with some punctuation",
21-
PUNCTUATION_SUGGESTION.to_string(),
22-
Applicability::MaybeIncorrect,
23-
);
24-
} else {
25-
let span = fragments.fragments.last().unwrap().span;
26-
// Seems more difficult to preserve the formatting of `#[doc]` attrs, so we do not provide
27-
// suggestions for them; they are much rarer anyway.
28-
clippy_utils::diagnostics::span_lint(cx, DOC_COMMENTS_MISSING_TERMINAL_PUNCTUATION, span, MSG);
29-
}
13+
// This ignores `#[doc]` attributes, which we do not handle.
14+
if let Some(offset) = is_missing_punctuation(doc)
15+
&& let Some(span) = fragments.span(cx, offset..offset)
16+
{
17+
clippy_utils::diagnostics::span_lint_and_sugg(
18+
cx,
19+
DOC_COMMENTS_MISSING_TERMINAL_PUNCTUATION,
20+
span,
21+
MSG,
22+
"end the doc comment with some punctuation",
23+
PUNCTUATION_SUGGESTION.to_string(),
24+
Applicability::MaybeIncorrect,
25+
);
3026
}
3127
}
3228

tests/ui/doc/doc_comments_missing_terminal_punctuation.fixed

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,3 +145,9 @@ struct EmptyDocComment;
145145
*/
146146
//~^^^ doc_comments_missing_terminal_punctuation
147147
struct BlockDocComment;
148+
149+
/// Sometimes a doc attribute is used for concatenation
150+
/// ```
151+
#[doc = ""]
152+
/// ```
153+
struct DocAttribute;

tests/ui/doc/doc_comments_missing_terminal_punctuation.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,3 +145,9 @@ struct EmptyDocComment;
145145
*/
146146
//~^^^ doc_comments_missing_terminal_punctuation
147147
struct BlockDocComment;
148+
149+
/// Sometimes a doc attribute is used for concatenation
150+
/// ```
151+
#[doc = ""]
152+
/// ```
153+
struct DocAttribute;

tests/ui/doc/doc_comments_missing_terminal_punctuation_unfixable.rs

Lines changed: 0 additions & 13 deletions
This file was deleted.

tests/ui/doc/doc_comments_missing_terminal_punctuation_unfixable.stderr

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)