Skip to content

Commit e545a73

Browse files
committed
lint per line instead of by block
1 parent 37fca1d commit e545a73

File tree

2 files changed

+47
-79
lines changed

2 files changed

+47
-79
lines changed
Lines changed: 8 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,20 @@
1-
use clippy_utils::diagnostics::span_lint_and_then;
2-
use clippy_utils::source::snippet_opt;
1+
use clippy_utils::diagnostics::span_lint_and_sugg;
32
use rustc_errors::Applicability;
43
use rustc_lint::LateContext;
5-
use rustc_span::Span;
4+
use rustc_span::{BytePos, Span};
65

76
use super::DOC_COMMENT_DOUBLE_SPACE_LINEBREAK;
87

98
pub fn check(cx: &LateContext<'_>, collected_breaks: &[Span]) {
10-
let replacements: Vec<_> = collect_doc_replacements(cx, collected_breaks);
11-
12-
if let Some((&(lo_span, _), &(hi_span, _))) = replacements.first().zip(replacements.last()) {
13-
span_lint_and_then(
9+
for r_span in collected_breaks {
10+
span_lint_and_sugg(
1411
cx,
1512
DOC_COMMENT_DOUBLE_SPACE_LINEBREAK,
16-
lo_span.to(hi_span),
13+
r_span.with_hi(r_span.lo() + BytePos(2)),
1714
"doc comment uses two spaces for a hard line break",
18-
|diag| {
19-
diag.multipart_suggestion(
20-
"replace this double space with a backslash",
21-
replacements,
22-
Applicability::MachineApplicable,
23-
);
24-
},
15+
"replace this double space with a backslash",
16+
"\\".to_owned(),
17+
Applicability::MachineApplicable,
2518
);
2619
}
2720
}
28-
29-
fn collect_doc_replacements(cx: &LateContext<'_>, spans: &[Span]) -> Vec<(Span, String)> {
30-
spans
31-
.iter()
32-
.map(|span| {
33-
// we already made sure the snippet exists when collecting spans
34-
let s = snippet_opt(cx, *span).expect("snippet was already validated to exist");
35-
let after_newline = s.trim_start_matches(' ');
36-
37-
let new_comment = format!("\\{after_newline}");
38-
(*span, new_comment)
39-
})
40-
.collect()
41-
}
Lines changed: 39 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,65 @@
11
error: doc comment uses two spaces for a hard line break
22
--> tests/ui/doc/doc_comment_double_space_linebreak.rs:7:43
33
|
4-
LL | //! Should warn on double space linebreaks
5-
| ___________________________________________^
6-
LL | | //! in file/module doc comment
7-
| |____^
4+
LL | //! Should warn on double space linebreaks
5+
| ^^ help: replace this double space with a backslash: `\`
86
|
97
= note: `-D clippy::doc-comment-double-space-linebreak` implied by `-D warnings`
108
= help: to override `-D warnings` add `#[allow(clippy::doc_comment_double_space_linebreak)]`
11-
help: replace this double space with a backslash
12-
|
13-
LL ~ //! Should warn on double space linebreaks\
14-
LL ~ //! in file/module doc comment
15-
|
169

1710
error: doc comment uses two spaces for a hard line break
1811
--> tests/ui/doc/doc_comment_double_space_linebreak.rs:35:51
1912
|
20-
LL | /// Should warn when doc comment uses double space
21-
| ___________________________________________________^
22-
LL | | /// as a line-break, even when there are multiple
23-
LL | | /// in a row
24-
| |____^
25-
|
26-
help: replace this double space with a backslash
27-
|
28-
LL ~ /// Should warn when doc comment uses double space\
29-
LL ~ /// as a line-break, even when there are multiple\
30-
LL ~ /// in a row
13+
LL | /// Should warn when doc comment uses double space
14+
| ^^ help: replace this double space with a backslash: `\`
15+
16+
error: doc comment uses two spaces for a hard line break
17+
--> tests/ui/doc/doc_comment_double_space_linebreak.rs:36:50
3118
|
19+
LL | /// as a line-break, even when there are multiple
20+
| ^^ help: replace this double space with a backslash: `\`
3221

3322
error: doc comment uses two spaces for a hard line break
3423
--> tests/ui/doc/doc_comment_double_space_linebreak.rs:44:12
3524
|
36-
LL | /// 🌹 are 🟥
37-
| ______________^
38-
LL | | /// 🌷 are 🟦
39-
LL | | /// 📎 is 😎
40-
LL | | /// and so are 🫵
41-
LL | | /// (hopefully no formatting weirdness linting this)
42-
| |____^
25+
LL | /// 🌹 are 🟥
26+
| ^^ help: replace this double space with a backslash: `\`
27+
28+
error: doc comment uses two spaces for a hard line break
29+
--> tests/ui/doc/doc_comment_double_space_linebreak.rs:45:12
4330
|
44-
help: replace this double space with a backslash
31+
LL | /// 🌷 are 🟦
32+
| ^^ help: replace this double space with a backslash: `\`
33+
34+
error: doc comment uses two spaces for a hard line break
35+
--> tests/ui/doc/doc_comment_double_space_linebreak.rs:46:11
4536
|
46-
LL ~ /// 🌹 are 🟥\
47-
LL ~ /// 🌷 are 🟦\
48-
LL ~ /// 📎 is 😎\
49-
LL ~ /// and so are 🫵\
50-
LL ~ /// (hopefully no formatting weirdness linting this)
37+
LL | /// 📎 is 😎
38+
| ^^ help: replace this double space with a backslash: `\`
39+
40+
error: doc comment uses two spaces for a hard line break
41+
--> tests/ui/doc/doc_comment_double_space_linebreak.rs:47:17
5142
|
43+
LL | /// and so are 🫵
44+
| ^^ help: replace this double space with a backslash: `\`
5245

5346
error: doc comment uses two spaces for a hard line break
5447
--> tests/ui/doc/doc_comment_double_space_linebreak.rs:86:16
5548
|
56-
LL | /// here we mix
57-
| ________________^
58-
LL | | /// double spaces\
59-
LL | | /// and also
60-
LL | | /// adding backslash\
61-
LL | | /// to some of them
62-
LL | | /// to see how that looks
63-
| |____^
64-
|
65-
help: replace this double space with a backslash
49+
LL | /// here we mix
50+
| ^^ help: replace this double space with a backslash: `\`
51+
52+
error: doc comment uses two spaces for a hard line break
53+
--> tests/ui/doc/doc_comment_double_space_linebreak.rs:88:13
6654
|
67-
LL ~ /// here we mix\
68-
LL ~ /// double spaces\
69-
LL ~ /// and also\
70-
LL ~ /// adding backslash\
71-
LL ~ /// to some of them\
72-
LL ~ /// to see how that looks
55+
LL | /// and also
56+
| ^^ help: replace this double space with a backslash: `\`
57+
58+
error: doc comment uses two spaces for a hard line break
59+
--> tests/ui/doc/doc_comment_double_space_linebreak.rs:90:20
7360
|
61+
LL | /// to some of them
62+
| ^^ help: replace this double space with a backslash: `\`
7463

75-
error: aborting due to 4 previous errors
64+
error: aborting due to 10 previous errors
7665

0 commit comments

Comments
 (0)