doc_comment_double_space_linebreaks: lint per line instead of by block
remove additional lint call fix fix lint defs
This commit is contained in:
@@ -5570,8 +5570,8 @@ Released 2018-09-13
|
||||
[`disallowed_type`]: https://rust-lang.github.io/rust-clippy/master/index.html#disallowed_type
|
||||
[`disallowed_types`]: https://rust-lang.github.io/rust-clippy/master/index.html#disallowed_types
|
||||
[`diverging_sub_expression`]: https://rust-lang.github.io/rust-clippy/master/index.html#diverging_sub_expression
|
||||
[`doc_include_without_cfg`]: https://rust-lang.github.io/rust-clippy/master/index.html#doc_include_without_cfg
|
||||
[`doc_comment_double_space_linebreak`]: https://rust-lang.github.io/rust-clippy/master/index.html#doc_comment_double_space_linebreak
|
||||
[`doc_include_without_cfg`]: https://rust-lang.github.io/rust-clippy/master/index.html#doc_include_without_cfg
|
||||
[`doc_lazy_continuation`]: https://rust-lang.github.io/rust-clippy/master/index.html#doc_lazy_continuation
|
||||
[`doc_link_code`]: https://rust-lang.github.io/rust-clippy/master/index.html#doc_link_code
|
||||
[`doc_link_with_quotes`]: https://rust-lang.github.io/rust-clippy/master/index.html#doc_link_with_quotes
|
||||
|
||||
@@ -137,8 +137,8 @@ pub static LINTS: &[&crate::LintInfo] = &[
|
||||
crate::disallowed_names::DISALLOWED_NAMES_INFO,
|
||||
crate::disallowed_script_idents::DISALLOWED_SCRIPT_IDENTS_INFO,
|
||||
crate::disallowed_types::DISALLOWED_TYPES_INFO,
|
||||
crate::doc::DOC_INCLUDE_WITHOUT_CFG_INFO,
|
||||
crate::doc::DOC_COMMENT_DOUBLE_SPACE_LINEBREAK_INFO,
|
||||
crate::doc::DOC_INCLUDE_WITHOUT_CFG_INFO,
|
||||
crate::doc::DOC_LAZY_CONTINUATION_INFO,
|
||||
crate::doc::DOC_LINK_CODE_INFO,
|
||||
crate::doc::DOC_LINK_WITH_QUOTES_INFO,
|
||||
|
||||
@@ -1,41 +1,20 @@
|
||||
use clippy_utils::diagnostics::span_lint_and_then;
|
||||
use clippy_utils::source::snippet_opt;
|
||||
use clippy_utils::diagnostics::span_lint_and_sugg;
|
||||
use rustc_errors::Applicability;
|
||||
use rustc_lint::LateContext;
|
||||
use rustc_span::Span;
|
||||
use rustc_span::{BytePos, Span};
|
||||
|
||||
use super::DOC_COMMENT_DOUBLE_SPACE_LINEBREAK;
|
||||
|
||||
pub fn check(cx: &LateContext<'_>, collected_breaks: &[Span]) {
|
||||
let replacements: Vec<_> = collect_doc_replacements(cx, collected_breaks);
|
||||
|
||||
if let Some((&(lo_span, _), &(hi_span, _))) = replacements.first().zip(replacements.last()) {
|
||||
span_lint_and_then(
|
||||
for r_span in collected_breaks {
|
||||
span_lint_and_sugg(
|
||||
cx,
|
||||
DOC_COMMENT_DOUBLE_SPACE_LINEBREAK,
|
||||
lo_span.to(hi_span),
|
||||
r_span.with_hi(r_span.lo() + BytePos(2)),
|
||||
"doc comment uses two spaces for a hard line break",
|
||||
|diag| {
|
||||
diag.multipart_suggestion(
|
||||
"replace this double space with a backslash",
|
||||
replacements,
|
||||
"\\".to_owned(),
|
||||
Applicability::MachineApplicable,
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
fn collect_doc_replacements(cx: &LateContext<'_>, spans: &[Span]) -> Vec<(Span, String)> {
|
||||
spans
|
||||
.iter()
|
||||
.map(|span| {
|
||||
// we already made sure the snippet exists when collecting spans
|
||||
let s = snippet_opt(cx, *span).expect("snippet was already validated to exist");
|
||||
let after_newline = s.trim_start_matches(' ');
|
||||
|
||||
let new_comment = format!("\\{after_newline}");
|
||||
(*span, new_comment)
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
@@ -772,8 +772,6 @@ fn check_attrs(cx: &LateContext<'_>, valid_idents: &FxHashSet<String>, attrs: &[
|
||||
return None;
|
||||
}
|
||||
|
||||
suspicious_doc_comments::check(cx, attrs);
|
||||
|
||||
let (fragments, _) = attrs_to_doc_fragments(
|
||||
attrs.iter().filter_map(|attr| {
|
||||
if attr.doc_str_and_comment_kind().is_none() || attr.span().in_external_macro(cx.sess().source_map()) {
|
||||
|
||||
@@ -2,75 +2,64 @@ error: doc comment uses two spaces for a hard line break
|
||||
--> tests/ui/doc/doc_comment_double_space_linebreak.rs:7:43
|
||||
|
|
||||
LL | //! Should warn on double space linebreaks
|
||||
| ___________________________________________^
|
||||
LL | | //! in file/module doc comment
|
||||
| |____^
|
||||
| ^^ help: replace this double space with a backslash: `\`
|
||||
|
|
||||
= note: `-D clippy::doc-comment-double-space-linebreak` implied by `-D warnings`
|
||||
= help: to override `-D warnings` add `#[allow(clippy::doc_comment_double_space_linebreak)]`
|
||||
help: replace this double space with a backslash
|
||||
|
|
||||
LL ~ //! Should warn on double space linebreaks\
|
||||
LL ~ //! in file/module doc comment
|
||||
|
|
||||
|
||||
error: doc comment uses two spaces for a hard line break
|
||||
--> tests/ui/doc/doc_comment_double_space_linebreak.rs:35:51
|
||||
|
|
||||
LL | /// Should warn when doc comment uses double space
|
||||
| ___________________________________________________^
|
||||
LL | | /// as a line-break, even when there are multiple
|
||||
LL | | /// in a row
|
||||
| |____^
|
||||
|
|
||||
help: replace this double space with a backslash
|
||||
|
|
||||
LL ~ /// Should warn when doc comment uses double space\
|
||||
LL ~ /// as a line-break, even when there are multiple\
|
||||
LL ~ /// in a row
|
||||
| ^^ help: replace this double space with a backslash: `\`
|
||||
|
||||
error: doc comment uses two spaces for a hard line break
|
||||
--> tests/ui/doc/doc_comment_double_space_linebreak.rs:36:50
|
||||
|
|
||||
LL | /// as a line-break, even when there are multiple
|
||||
| ^^ help: replace this double space with a backslash: `\`
|
||||
|
||||
error: doc comment uses two spaces for a hard line break
|
||||
--> tests/ui/doc/doc_comment_double_space_linebreak.rs:44:12
|
||||
|
|
||||
LL | /// 🌹 are 🟥
|
||||
| ______________^
|
||||
LL | | /// 🌷 are 🟦
|
||||
LL | | /// 📎 is 😎
|
||||
LL | | /// and so are 🫵
|
||||
LL | | /// (hopefully no formatting weirdness linting this)
|
||||
| |____^
|
||||
| ^^ help: replace this double space with a backslash: `\`
|
||||
|
||||
error: doc comment uses two spaces for a hard line break
|
||||
--> tests/ui/doc/doc_comment_double_space_linebreak.rs:45:12
|
||||
|
|
||||
help: replace this double space with a backslash
|
||||
LL | /// 🌷 are 🟦
|
||||
| ^^ help: replace this double space with a backslash: `\`
|
||||
|
||||
error: doc comment uses two spaces for a hard line break
|
||||
--> tests/ui/doc/doc_comment_double_space_linebreak.rs:46:11
|
||||
|
|
||||
LL ~ /// 🌹 are 🟥\
|
||||
LL ~ /// 🌷 are 🟦\
|
||||
LL ~ /// 📎 is 😎\
|
||||
LL ~ /// and so are 🫵\
|
||||
LL ~ /// (hopefully no formatting weirdness linting this)
|
||||
LL | /// 📎 is 😎
|
||||
| ^^ help: replace this double space with a backslash: `\`
|
||||
|
||||
error: doc comment uses two spaces for a hard line break
|
||||
--> tests/ui/doc/doc_comment_double_space_linebreak.rs:47:17
|
||||
|
|
||||
LL | /// and so are 🫵
|
||||
| ^^ help: replace this double space with a backslash: `\`
|
||||
|
||||
error: doc comment uses two spaces for a hard line break
|
||||
--> tests/ui/doc/doc_comment_double_space_linebreak.rs:86:16
|
||||
|
|
||||
LL | /// here we mix
|
||||
| ________________^
|
||||
LL | | /// double spaces\
|
||||
LL | | /// and also
|
||||
LL | | /// adding backslash\
|
||||
LL | | /// to some of them
|
||||
LL | | /// to see how that looks
|
||||
| |____^
|
||||
|
|
||||
help: replace this double space with a backslash
|
||||
|
|
||||
LL ~ /// here we mix\
|
||||
LL ~ /// double spaces\
|
||||
LL ~ /// and also\
|
||||
LL ~ /// adding backslash\
|
||||
LL ~ /// to some of them\
|
||||
LL ~ /// to see how that looks
|
||||
|
|
||||
| ^^ help: replace this double space with a backslash: `\`
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
error: doc comment uses two spaces for a hard line break
|
||||
--> tests/ui/doc/doc_comment_double_space_linebreak.rs:88:13
|
||||
|
|
||||
LL | /// and also
|
||||
| ^^ help: replace this double space with a backslash: `\`
|
||||
|
||||
error: doc comment uses two spaces for a hard line break
|
||||
--> tests/ui/doc/doc_comment_double_space_linebreak.rs:90:20
|
||||
|
|
||||
LL | /// to some of them
|
||||
| ^^ help: replace this double space with a backslash: `\`
|
||||
|
||||
error: aborting due to 10 previous errors
|
||||
|
||||
|
||||
Reference in New Issue
Block a user