Skip to content

Commit 4a99a06

Browse files
committed
Review comments & Add testing
1 parent 565cf5a commit 4a99a06

File tree

4 files changed

+137
-31
lines changed

4 files changed

+137
-31
lines changed

clippy_lints/src/doc/markdown.rs

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rustc_span::{BytePos, Pos, Span};
77
use url::Url;
88

99
use crate::doc::{DOC_MARKDOWN, Fragments};
10-
use std::ops::{ControlFlow, Range};
10+
use std::ops::Range;
1111

1212
pub fn check(
1313
cx: &LateContext<'_>,
@@ -70,19 +70,15 @@ pub fn check(
7070
let fragment_offset = word.as_ptr() as usize - text.as_ptr() as usize;
7171

7272
// Adjust for the current word
73-
if check_word(
73+
check_word(
7474
cx,
7575
word,
7676
fragments,
7777
&fragment_range,
7878
fragment_offset,
7979
code_level,
8080
blockquote_level,
81-
)
82-
.is_break()
83-
{
84-
return;
85-
}
81+
);
8682
}
8783
}
8884

@@ -94,7 +90,7 @@ fn check_word(
9490
fragment_offset: usize,
9591
code_level: isize,
9692
blockquote_level: isize,
97-
) -> ControlFlow<()> {
93+
) {
9894
/// Checks if a string is upper-camel-case, i.e., starts with an uppercase and
9995
/// contains at least two uppercase letters (`Clippy` is ok) and one lower-case
10096
/// letter (`NASA` is ok).[
@@ -135,9 +131,8 @@ fn check_word(
135131
&& !url.cannot_be_a_base()
136132
{
137133
let Some(fragment_span) = fragments.span(cx, range.clone()) else {
138-
return ControlFlow::Break(());
134+
return;
139135
};
140-
141136
let span = Span::new(
142137
fragment_span.lo() + BytePos::from_usize(fragment_offset),
143138
fragment_span.lo() + BytePos::from_usize(fragment_offset + word.len()),
@@ -154,19 +149,19 @@ fn check_word(
154149
format!("<{word}>"),
155150
Applicability::MachineApplicable,
156151
);
157-
return ControlFlow::Continue(());
152+
return;
158153
}
159154

160155
// We assume that mixed-case words are not meant to be put inside backticks. (Issue #2343)
161156
//
162157
// We also assume that backticks are not necessary if inside a quote. (Issue #10262)
163158
if code_level > 0 || blockquote_level > 0 || (has_underscore(word) && has_hyphen(word)) {
164-
return ControlFlow::Break(());
159+
return;
165160
}
166161

167162
if has_underscore(word) || word.contains("::") || is_camel_case(word) || word.ends_with("()") {
168163
let Some(fragment_span) = fragments.span(cx, range.clone()) else {
169-
return ControlFlow::Break(());
164+
return;
170165
};
171166

172167
let span = Span::new(
@@ -188,5 +183,4 @@ fn check_word(
188183
},
189184
);
190185
}
191-
ControlFlow::Continue(())
192186
}

tests/ui/doc/doc_markdown-issue_13097.fixed

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,37 @@
1-
// This test checks that words starting with capital letters and ending with "ified" don't
2-
// trigger the lint.
3-
41
#![deny(clippy::doc_markdown)]
2+
#![allow(clippy::doc_lazy_continuation)]
3+
4+
mod issue13097 {
5+
// This test checks that words starting with capital letters and ending with "ified" don't
6+
// trigger the lint.
7+
pub enum OutputFormat {
8+
/// `HumaNified`
9+
//~^ ERROR: item in documentation is missing backticks
10+
Plain,
11+
// Should not warn!
12+
/// JSONified console output
13+
Json,
14+
}
15+
}
516

17+
#[rustfmt::skip]
618
pub enum OutputFormat {
7-
/// `HumaNified`
8-
//~^ ERROR: item in documentation is missing backticks
19+
/**
20+
* `HumaNified`
21+
//~^ ERROR: item in documentation is missing backticks
22+
* Before \u{08888} `HumaNified` \{u08888} After
23+
//~^ ERROR: item in documentation is missing backticks
24+
* meow meow \[`meow_meow`\] meow meow?
25+
//~^ ERROR: item in documentation is missing backticks
26+
* \u{08888} `meow_meow` \[meow meow] meow?
27+
//~^ ERROR: item in documentation is missing backticks
28+
* Above
29+
* \u{08888}
30+
* \[hi\](<https://example.com>) `HumaNified` \[example](<https://example.com>)
31+
//~^ ERROR: item in documentation is missing backticks
32+
* \u{08888}
33+
* Below
34+
*/
935
Plain,
1036
// Should not warn!
1137
/// JSONified console output

tests/ui/doc/doc_markdown-issue_13097.rs

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,37 @@
1-
// This test checks that words starting with capital letters and ending with "ified" don't
2-
// trigger the lint.
3-
41
#![deny(clippy::doc_markdown)]
2+
#![allow(clippy::doc_lazy_continuation)]
3+
4+
mod issue13097 {
5+
// This test checks that words starting with capital letters and ending with "ified" don't
6+
// trigger the lint.
7+
pub enum OutputFormat {
8+
/// HumaNified
9+
//~^ ERROR: item in documentation is missing backticks
10+
Plain,
11+
// Should not warn!
12+
/// JSONified console output
13+
Json,
14+
}
15+
}
516

17+
#[rustfmt::skip]
618
pub enum OutputFormat {
7-
/// HumaNified
8-
//~^ ERROR: item in documentation is missing backticks
19+
/**
20+
* HumaNified
21+
//~^ ERROR: item in documentation is missing backticks
22+
* Before \u{08888} HumaNified \{u08888} After
23+
//~^ ERROR: item in documentation is missing backticks
24+
* meow meow \[meow_meow\] meow meow?
25+
//~^ ERROR: item in documentation is missing backticks
26+
* \u{08888} meow_meow \[meow meow] meow?
27+
//~^ ERROR: item in documentation is missing backticks
28+
* Above
29+
* \u{08888}
30+
* \[hi\](<https://example.com>) HumaNified \[example](<https://example.com>)
31+
//~^ ERROR: item in documentation is missing backticks
32+
* \u{08888}
33+
* Below
34+
*/
935
Plain,
1036
// Should not warn!
1137
/// JSONified console output
Lines changed: 67 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,79 @@
11
error: item in documentation is missing backticks
2-
--> tests/ui/doc/doc_markdown-issue_13097.rs:7:9
2+
--> tests/ui/doc/doc_markdown-issue_13097.rs:8:13
33
|
4-
LL | /// HumaNified
5-
| ^^^^^^^^^^
4+
LL | /// HumaNified
5+
| ^^^^^^^^^^
66
|
77
note: the lint level is defined here
8-
--> tests/ui/doc/doc_markdown-issue_13097.rs:4:9
8+
--> tests/ui/doc/doc_markdown-issue_13097.rs:1:9
99
|
1010
LL | #![deny(clippy::doc_markdown)]
1111
| ^^^^^^^^^^^^^^^^^^^^
1212
help: try
1313
|
14-
LL - /// HumaNified
15-
LL + /// `HumaNified`
14+
LL - /// HumaNified
15+
LL + /// `HumaNified`
1616
|
1717

18-
error: aborting due to 1 previous error
18+
error: item in documentation is missing backticks
19+
--> tests/ui/doc/doc_markdown-issue_13097.rs:20:8
20+
|
21+
LL | * HumaNified
22+
| ^^^^^^^^^^
23+
|
24+
help: try
25+
|
26+
LL - * HumaNified
27+
LL + * `HumaNified`
28+
|
29+
30+
error: item in documentation is missing backticks
31+
--> tests/ui/doc/doc_markdown-issue_13097.rs:22:25
32+
|
33+
LL | * Before \u{08888} HumaNified \{u08888} After
34+
| ^^^^^^^^^^
35+
|
36+
help: try
37+
|
38+
LL - * Before \u{08888} HumaNified \{u08888} After
39+
LL + * Before \u{08888} `HumaNified` \{u08888} After
40+
|
41+
42+
error: item in documentation is missing backticks
43+
--> tests/ui/doc/doc_markdown-issue_13097.rs:24:20
44+
|
45+
LL | * meow meow \[meow_meow\] meow meow?
46+
| ^^^^^^^^^
47+
|
48+
help: try
49+
|
50+
LL - * meow meow \[meow_meow\] meow meow?
51+
LL + * meow meow \[`meow_meow`\] meow meow?
52+
|
53+
54+
error: item in documentation is missing backticks
55+
--> tests/ui/doc/doc_markdown-issue_13097.rs:26:18
56+
|
57+
LL | * \u{08888} meow_meow \[meow meow] meow?
58+
| ^^^^^^^^^
59+
|
60+
help: try
61+
|
62+
LL - * \u{08888} meow_meow \[meow meow] meow?
63+
LL + * \u{08888} `meow_meow` \[meow meow] meow?
64+
|
65+
66+
error: item in documentation is missing backticks
67+
--> tests/ui/doc/doc_markdown-issue_13097.rs:30:38
68+
|
69+
LL | * \[hi\](<https://example.com>) HumaNified \[example](<https://example.com>)
70+
| ^^^^^^^^^^
71+
|
72+
help: try
73+
|
74+
LL - * \[hi\](<https://example.com>) HumaNified \[example](<https://example.com>)
75+
LL + * \[hi\](<https://example.com>) `HumaNified` \[example](<https://example.com>)
76+
|
77+
78+
error: aborting due to 6 previous errors
1979

0 commit comments

Comments
 (0)