Skip to content

Commit 52c74f6

Browse files
doc_comments_missing_terminal_punctuation: exclude tables and code blocks
1 parent 75aaa88 commit 52c74f6

File tree

4 files changed

+27
-16
lines changed

4 files changed

+27
-16
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
@@ -47,15 +47,14 @@ fn is_missing_punctuation(doc_string: &str) -> Option<usize> {
4747
) => {
4848
no_report_depth += 1;
4949
},
50+
Event::End(TagEnd::FootnoteDefinition) => {
51+
no_report_depth -= 1;
52+
},
5053
Event::End(
51-
TagEnd::CodeBlock
52-
| TagEnd::FootnoteDefinition
53-
| TagEnd::Heading(_)
54-
| TagEnd::HtmlBlock
55-
| TagEnd::List(_)
56-
| TagEnd::Table,
54+
TagEnd::CodeBlock | TagEnd::Heading(_) | TagEnd::HtmlBlock | TagEnd::List(_) | TagEnd::Table,
5755
) => {
5856
no_report_depth -= 1;
57+
text_offset = None;
5958
},
6059
Event::InlineHtml(_) | Event::Start(Tag::Image { .. }) | Event::End(TagEnd::Image) => {
6160
text_offset = None;

tests/ui/doc/doc_comments_missing_terminal_punctuation.fixed

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,14 @@ enum Exceptions {
4040
/// <https://spec.commonmark.org/0.31.2/#autolinks>.
4141
//~^ doc_comments_missing_terminal_punctuation
4242
MarkdownAutolink,
43+
/// This table introduction ends with a colon:
44+
///
4345
/// | Exception | Note |
4446
/// | -------------- | ----- |
4547
/// | Markdown table | A-ok |
4648
MarkdownTable,
49+
/// Here is a snippet
50+
///
4751
/// ```
4852
/// // Code blocks are no issues.
4953
/// ```
@@ -105,6 +109,8 @@ struct LinkRefDefinition;
105109

106110
// List items do not always need to end with a period.
107111
enum UnorderedLists {
112+
/// This list has an introductory sentence:
113+
///
108114
/// - A list item
109115
Dash,
110116
/// + A list item

tests/ui/doc/doc_comments_missing_terminal_punctuation.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,14 @@ enum Exceptions {
4040
/// <https://spec.commonmark.org/0.31.2/#autolinks>
4141
//~^ doc_comments_missing_terminal_punctuation
4242
MarkdownAutolink,
43+
/// This table introduction ends with a colon:
44+
///
4345
/// | Exception | Note |
4446
/// | -------------- | ----- |
4547
/// | Markdown table | A-ok |
4648
MarkdownTable,
49+
/// Here is a snippet
50+
///
4751
/// ```
4852
/// // Code blocks are no issues.
4953
/// ```
@@ -105,6 +109,8 @@ struct LinkRefDefinition;
105109

106110
// List items do not always need to end with a period.
107111
enum UnorderedLists {
112+
/// This list has an introductory sentence:
113+
///
108114
/// - A list item
109115
Dash,
110116
/// + A list item

tests/ui/doc/doc_comments_missing_terminal_punctuation.stderr

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,61 +32,61 @@ LL | /// <https://spec.commonmark.org/0.31.2/#autolinks>
3232
| ^ help: end the doc comment with some punctuation: `.`
3333

3434
error: doc comments should end with a terminal punctuation mark
35-
--> tests/ui/doc/doc_comments_missing_terminal_punctuation.rs:67:15
35+
--> tests/ui/doc/doc_comments_missing_terminal_punctuation.rs:71:15
3636
|
3737
LL | /// U+0001
3838
| ^ help: end the doc comment with some punctuation: `.`
3939

4040
error: doc comments should end with a terminal punctuation mark
41-
--> tests/ui/doc/doc_comments_missing_terminal_punctuation.rs:74:29
41+
--> tests/ui/doc/doc_comments_missing_terminal_punctuation.rs:78:29
4242
|
4343
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:81:46
47+
--> tests/ui/doc/doc_comments_missing_terminal_punctuation.rs:85:46
4848
|
4949
LL | /// (But sometimes it is missing a period)
5050
| ^ help: end the doc comment with some punctuation: `.`
5151

5252
error: doc comments should end with a terminal punctuation mark
53-
--> tests/ui/doc/doc_comments_missing_terminal_punctuation.rs:86:47
53+
--> tests/ui/doc/doc_comments_missing_terminal_punctuation.rs:90:47
5454
|
5555
LL | /// **But sometimes it is missing a period**
5656
| ^ help: end the doc comment with some punctuation: `.`
5757

5858
error: doc comments should end with a terminal punctuation mark
59-
--> tests/ui/doc/doc_comments_missing_terminal_punctuation.rs:91:46
59+
--> tests/ui/doc/doc_comments_missing_terminal_punctuation.rs:95:46
6060
|
6161
LL | /// _But sometimes it is missing a period_
6262
| ^ help: end the doc comment with some punctuation: `.`
6363

6464
error: doc comments should end with a terminal punctuation mark
65-
--> tests/ui/doc/doc_comments_missing_terminal_punctuation.rs:96:56
65+
--> tests/ui/doc/doc_comments_missing_terminal_punctuation.rs:100:56
6666
|
6767
LL | /// Doc comments can end with an [inline link](#anchor)
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:100:65
71+
--> tests/ui/doc/doc_comments_missing_terminal_punctuation.rs:104:65
7272
|
7373
LL | /// Some doc comments contain [link reference definitions][spec]
7474
| ^ help: end the doc comment with some punctuation: `.`
7575

7676
error: doc comments should end with a terminal punctuation mark
77-
--> tests/ui/doc/doc_comments_missing_terminal_punctuation.rs:123:57
77+
--> tests/ui/doc/doc_comments_missing_terminal_punctuation.rs:129:57
7878
|
7979
LL | /// Doc comments with trailing blank lines are supported
8080
| ^ help: end the doc comment with some punctuation: `.`
8181

8282
error: doc comments should end with a terminal punctuation mark
83-
--> tests/ui/doc/doc_comments_missing_terminal_punctuation.rs:131:30
83+
--> tests/ui/doc/doc_comments_missing_terminal_punctuation.rs:137:30
8484
|
8585
LL | /// Only the last sentence is
8686
| ^ help: end the doc comment with some punctuation: `.`
8787

8888
error: doc comments should end with a terminal punctuation mark
89-
--> tests/ui/doc/doc_comments_missing_terminal_punctuation.rs:143:27
89+
--> tests/ui/doc/doc_comments_missing_terminal_punctuation.rs:149:27
9090
|
9191
LL | * Block doc comments work
9292
| ^ help: end the doc comment with some punctuation: `.`

0 commit comments

Comments
 (0)