Skip to content

Commit 5ca9ca1

Browse files
doc_comments_missing_terminal_punctuation: accept punctuation in quotes
1 parent 70a7dd6 commit 5ca9ca1

File tree

4 files changed

+32
-8
lines changed

4 files changed

+32
-8
lines changed

clippy_lints/src/doc/doc_comments_missing_terminal_punctuation.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,19 @@ fn is_missing_punctuation(doc_string: &str) -> Option<usize> {
5959
Event::InlineHtml(_) | Event::Start(Tag::Image { .. }) | Event::End(TagEnd::Image) => {
6060
text_offset = None;
6161
},
62-
Event::Code(..) | Event::Text(..) | Event::Start(Tag::Link { .. }) | Event::End(TagEnd::Link)
62+
Event::Code(..) | Event::Start(Tag::Link { .. }) | Event::End(TagEnd::Link)
6363
if no_report_depth == 0 && !offset.is_empty() =>
6464
{
6565
text_offset = Some(offset.end);
6666
},
67+
Event::Text(..) if no_report_depth == 0 && !offset.is_empty() => {
68+
// American-style quotes require punctuation to be placed inside closing quotation marks.
69+
if doc_string[..offset.end].trim_end().ends_with('"') {
70+
text_offset = Some(offset.end - 1);
71+
} else {
72+
text_offset = Some(offset.end);
73+
}
74+
},
6775
_ => {},
6876
}
6977
}

tests/ui/doc/doc_comments_missing_terminal_punctuation.fixed

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,11 @@ enum Trailers {
9696
/// _But sometimes it is missing a period._
9797
//~^ doc_comments_missing_terminal_punctuation
9898
UnderscoreFailing,
99+
/// This comment ends with "a quote."
100+
QuotePassing,
101+
/// This comment ends with "a quote."
102+
//~^ doc_comments_missing_terminal_punctuation
103+
QuoteFailing,
99104
}
100105

101106
/// Doc comments can end with an [inline link](#anchor).

tests/ui/doc/doc_comments_missing_terminal_punctuation.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,11 @@ enum Trailers {
9696
/// _But sometimes it is missing a period_
9797
//~^ doc_comments_missing_terminal_punctuation
9898
UnderscoreFailing,
99+
/// This comment ends with "a quote."
100+
QuotePassing,
101+
/// This comment ends with "a quote"
102+
//~^ doc_comments_missing_terminal_punctuation
103+
QuoteFailing,
99104
}
100105

101106
/// Doc comments can end with an [inline link](#anchor)

tests/ui/doc/doc_comments_missing_terminal_punctuation.stderr

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,40 +68,46 @@ LL | /// _But sometimes it is missing a period_
6868
| ^ help: end the doc comment with some punctuation: `.`
6969

7070
error: doc comments should end with a terminal punctuation mark
71-
--> tests/ui/doc/doc_comments_missing_terminal_punctuation.rs:101:56
71+
--> tests/ui/doc/doc_comments_missing_terminal_punctuation.rs:101:40
72+
|
73+
LL | /// This comment ends with "a quote"
74+
| ^ help: end the doc comment with some punctuation: `.`
75+
76+
error: doc comments should end with a terminal punctuation mark
77+
--> tests/ui/doc/doc_comments_missing_terminal_punctuation.rs:106:56
7278
|
7379
LL | /// Doc comments can end with an [inline link](#anchor)
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:105:65
83+
--> tests/ui/doc/doc_comments_missing_terminal_punctuation.rs:110:65
7884
|
7985
LL | /// Some doc comments contain [link reference definitions][spec]
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:130:57
89+
--> tests/ui/doc/doc_comments_missing_terminal_punctuation.rs:135:57
8490
|
8591
LL | /// Doc comments with trailing blank lines are supported
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:138:30
95+
--> tests/ui/doc/doc_comments_missing_terminal_punctuation.rs:143:30
9096
|
9197
LL | /// Only the last sentence is
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:145:33
101+
--> tests/ui/doc/doc_comments_missing_terminal_punctuation.rs:150:33
96102
|
97103
LL | /// This ends with a code `span`
98104
| ^ help: end the doc comment with some punctuation: `.`
99105

100106
error: doc comments should end with a terminal punctuation mark
101-
--> tests/ui/doc/doc_comments_missing_terminal_punctuation.rs:154:27
107+
--> tests/ui/doc/doc_comments_missing_terminal_punctuation.rs:159:27
102108
|
103109
LL | * Block doc comments work
104110
| ^ help: end the doc comment with some punctuation: `.`
105111

106-
error: aborting due to 17 previous errors
112+
error: aborting due to 18 previous errors
107113

0 commit comments

Comments
 (0)