Skip to content

Commit 70a7dd6

Browse files
doc_comments_missing_terminal_punctuation: remove the parens special treatment
1 parent ec5aa66 commit 70a7dd6

File tree

4 files changed

+31
-24
lines changed

4 files changed

+31
-24
lines changed

clippy_lints/src/doc/doc_comments_missing_terminal_punctuation.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ pub fn check(cx: &LateContext<'_>, doc: &str, fragments: Fragments<'_>) {
2727
}
2828

2929
#[must_use]
30-
/// If punctuation is missing, returns the docstring and the offset
31-
/// where new punctuation should be inserted.
30+
/// If punctuation is missing, returns the offset where new punctuation should be inserted.
3231
fn is_missing_punctuation(doc_string: &str) -> Option<usize> {
3332
const TERMINAL_PUNCTUATION_MARKS: &[char] = &['.', '?', '!', '…'];
3433

@@ -63,19 +62,19 @@ fn is_missing_punctuation(doc_string: &str) -> Option<usize> {
6362
Event::Code(..) | Event::Text(..) | Event::Start(Tag::Link { .. }) | Event::End(TagEnd::Link)
6463
if no_report_depth == 0 && !offset.is_empty() =>
6564
{
66-
text_offset = Some(offset);
65+
text_offset = Some(offset.end);
6766
},
6867
_ => {},
6968
}
7069
}
7170

7271
let text_offset = text_offset?;
73-
if doc_string[..text_offset.end]
74-
.trim_end_matches(|c: char| c.is_whitespace() || c == ')' || c == ']' || c == '}')
72+
if doc_string[..text_offset]
73+
.trim_end()
7574
.ends_with(TERMINAL_PUNCTUATION_MARKS)
7675
{
7776
None
7877
} else {
79-
Some(text_offset.end)
78+
Some(text_offset)
8079
}
8180
}

tests/ui/doc/doc_comments_missing_terminal_punctuation.fixed

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,10 @@ mod module {
8080
}
8181

8282
enum Trailers {
83-
/// (Sometimes the last sentence is in parentheses, and that's ok.)
84-
ParensPassing,
85-
/// (But sometimes it is missing a period).
83+
/// Sometimes the doc comment ends with parentheses (like this).
84+
//~^ doc_comments_missing_terminal_punctuation
85+
EndsWithParens,
86+
/// (Sometimes the last sentence is in parentheses, but there is no special treatment of this.).
8687
//~^ doc_comments_missing_terminal_punctuation
8788
ParensFailing,
8889
/// **Sometimes the last sentence is in bold, and that's ok.**

tests/ui/doc/doc_comments_missing_terminal_punctuation.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,10 @@ mod module {
8080
}
8181

8282
enum Trailers {
83-
/// (Sometimes the last sentence is in parentheses, and that's ok.)
84-
ParensPassing,
85-
/// (But sometimes it is missing a period)
83+
/// Sometimes the doc comment ends with parentheses (like this)
84+
//~^ doc_comments_missing_terminal_punctuation
85+
EndsWithParens,
86+
/// (Sometimes the last sentence is in parentheses, but there is no special treatment of this.)
8687
//~^ doc_comments_missing_terminal_punctuation
8788
ParensFailing,
8889
/// **Sometimes the last sentence is in bold, and that's ok.**

tests/ui/doc/doc_comments_missing_terminal_punctuation.stderr

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,58 +44,64 @@ LL | //! inner attributes too
4444
| ^ help: end the doc comment with some punctuation: `.`
4545

4646
error: doc comments should end with a terminal punctuation mark
47-
--> tests/ui/doc/doc_comments_missing_terminal_punctuation.rs:85:47
47+
--> tests/ui/doc/doc_comments_missing_terminal_punctuation.rs:83:68
4848
|
49-
LL | /// (But sometimes it is missing a period)
50-
| ^ help: end the doc comment with some punctuation: `.`
49+
LL | /// Sometimes the doc comment ends with parentheses (like this)
50+
| ^ help: end the doc comment with some punctuation: `.`
51+
52+
error: doc comments should end with a terminal punctuation mark
53+
--> tests/ui/doc/doc_comments_missing_terminal_punctuation.rs:86:100
54+
|
55+
LL | /// (Sometimes the last sentence is in parentheses, but there is no special treatment of this.)
56+
| ^ help: end the doc comment with some punctuation: `.`
5157

5258
error: doc comments should end with a terminal punctuation mark
53-
--> tests/ui/doc/doc_comments_missing_terminal_punctuation.rs:90:47
59+
--> tests/ui/doc/doc_comments_missing_terminal_punctuation.rs:91:47
5460
|
5561
LL | /// **But sometimes it is missing a period**
5662
| ^ help: end the doc comment with some punctuation: `.`
5763

5864
error: doc comments should end with a terminal punctuation mark
59-
--> tests/ui/doc/doc_comments_missing_terminal_punctuation.rs:95:46
65+
--> tests/ui/doc/doc_comments_missing_terminal_punctuation.rs:96:46
6066
|
6167
LL | /// _But sometimes it is missing a period_
6268
| ^ help: end the doc comment with some punctuation: `.`
6369

6470
error: doc comments should end with a terminal punctuation mark
65-
--> tests/ui/doc/doc_comments_missing_terminal_punctuation.rs:100:56
71+
--> tests/ui/doc/doc_comments_missing_terminal_punctuation.rs:101:56
6672
|
6773
LL | /// Doc comments can end with an [inline link](#anchor)
6874
| ^ help: end the doc comment with some punctuation: `.`
6975

7076
error: doc comments should end with a terminal punctuation mark
71-
--> tests/ui/doc/doc_comments_missing_terminal_punctuation.rs:104:65
77+
--> tests/ui/doc/doc_comments_missing_terminal_punctuation.rs:105:65
7278
|
7379
LL | /// Some doc comments contain [link reference definitions][spec]
7480
| ^ help: end the doc comment with some punctuation: `.`
7581

7682
error: doc comments should end with a terminal punctuation mark
77-
--> tests/ui/doc/doc_comments_missing_terminal_punctuation.rs:129:57
83+
--> tests/ui/doc/doc_comments_missing_terminal_punctuation.rs:130:57
7884
|
7985
LL | /// Doc comments with trailing blank lines are supported
8086
| ^ help: end the doc comment with some punctuation: `.`
8187

8288
error: doc comments should end with a terminal punctuation mark
83-
--> tests/ui/doc/doc_comments_missing_terminal_punctuation.rs:137:30
89+
--> tests/ui/doc/doc_comments_missing_terminal_punctuation.rs:138:30
8490
|
8591
LL | /// Only the last sentence is
8692
| ^ help: end the doc comment with some punctuation: `.`
8793

8894
error: doc comments should end with a terminal punctuation mark
89-
--> tests/ui/doc/doc_comments_missing_terminal_punctuation.rs:144:33
95+
--> tests/ui/doc/doc_comments_missing_terminal_punctuation.rs:145:33
9096
|
9197
LL | /// This ends with a code `span`
9298
| ^ help: end the doc comment with some punctuation: `.`
9399

94100
error: doc comments should end with a terminal punctuation mark
95-
--> tests/ui/doc/doc_comments_missing_terminal_punctuation.rs:153:27
101+
--> tests/ui/doc/doc_comments_missing_terminal_punctuation.rs:154:27
96102
|
97103
LL | * Block doc comments work
98104
| ^ help: end the doc comment with some punctuation: `.`
99105

100-
error: aborting due to 16 previous errors
106+
error: aborting due to 17 previous errors
101107

0 commit comments

Comments
 (0)