Skip to content

Commit 60191cf

Browse files
committed
doc_comment_double_space_linebreak: Use multi spans and suggestions
1 parent 2fd51b8 commit 60191cf

File tree

2 files changed

+44
-46
lines changed

2 files changed

+44
-46
lines changed
Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,33 @@
1-
use clippy_utils::diagnostics::span_lint_and_sugg;
1+
use clippy_utils::diagnostics::span_lint_and_then;
22
use rustc_errors::Applicability;
33
use rustc_lint::LateContext;
44
use rustc_span::{BytePos, Span};
55

66
use super::DOC_COMMENT_DOUBLE_SPACE_LINEBREAK;
77

88
pub fn check(cx: &LateContext<'_>, collected_breaks: &[Span]) {
9-
for r_span in collected_breaks {
10-
span_lint_and_sugg(
11-
cx,
12-
DOC_COMMENT_DOUBLE_SPACE_LINEBREAK,
13-
r_span.with_hi(r_span.lo() + BytePos(2)),
14-
"doc comment uses two spaces for a hard line break",
15-
"replace this double space with a backslash",
16-
"\\".to_owned(),
17-
Applicability::MachineApplicable,
18-
);
9+
if collected_breaks.is_empty() {
10+
return;
1911
}
12+
13+
let breaks: Vec<_> = collected_breaks
14+
.iter()
15+
.map(|span| span.with_hi(span.lo() + BytePos(2)))
16+
.collect();
17+
18+
span_lint_and_then(
19+
cx,
20+
DOC_COMMENT_DOUBLE_SPACE_LINEBREAK,
21+
breaks.clone(),
22+
"doc comment uses two spaces for a hard line break",
23+
|diag| {
24+
let suggs: Vec<_> = breaks.iter().map(|span| (*span, "\\".to_string())).collect();
25+
diag.tool_only_multipart_suggestion(
26+
"replace this double space with a backslash:",
27+
suggs,
28+
Applicability::MachineApplicable,
29+
);
30+
diag.help("replace this double space with a backslash: `\\`");
31+
},
32+
);
2033
}

tests/ui/doc/doc_comment_double_space_linebreak.stderr

Lines changed: 20 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,64 +2,49 @@ error: doc comment uses two spaces for a hard line break
22
--> tests/ui/doc/doc_comment_double_space_linebreak.rs:7:43
33
|
44
LL | //! Should warn on double space linebreaks
5-
| ^^ help: replace this double space with a backslash: `\`
5+
| ^^
66
|
7+
= help: replace this double space with a backslash: `\`
78
= note: `-D clippy::doc-comment-double-space-linebreak` implied by `-D warnings`
89
= help: to override `-D warnings` add `#[allow(clippy::doc_comment_double_space_linebreak)]`
910

1011
error: doc comment uses two spaces for a hard line break
1112
--> tests/ui/doc/doc_comment_double_space_linebreak.rs:35:51
1213
|
1314
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
18-
|
15+
| ^^
1916
LL | /// as a line-break, even when there are multiple
20-
| ^^ help: replace this double space with a backslash: `\`
17+
| ^^
18+
|
19+
= help: replace this double space with a backslash: `\`
2120

2221
error: doc comment uses two spaces for a hard line break
2322
--> tests/ui/doc/doc_comment_double_space_linebreak.rs:44:12
2423
|
2524
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
30-
|
25+
| ^^
3126
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
36-
|
27+
| ^^
3728
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
42-
|
29+
| ^^
4330
LL | /// and so are 🫵
44-
| ^^ help: replace this double space with a backslash: `\`
31+
| ^^
32+
|
33+
= help: replace this double space with a backslash: `\`
4534

4635
error: doc comment uses two spaces for a hard line break
4736
--> tests/ui/doc/doc_comment_double_space_linebreak.rs:86:16
4837
|
4938
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
54-
|
39+
| ^^
40+
LL | /// double spaces\
5541
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
60-
|
42+
| ^^
43+
LL | /// adding backslash\
6144
LL | /// to some of them
62-
| ^^ help: replace this double space with a backslash: `\`
45+
| ^^
46+
|
47+
= help: replace this double space with a backslash: `\`
6348

64-
error: aborting due to 10 previous errors
49+
error: aborting due to 4 previous errors
6550

0 commit comments

Comments
 (0)