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:
Jacherr
2025-02-13 16:45:43 +00:00
committed by xFrednet
parent f94f64f5e8
commit 2fd51b8d34
5 changed files with 51 additions and 85 deletions

View File

@@ -5570,8 +5570,8 @@ Released 2018-09-13
[`disallowed_type`]: https://rust-lang.github.io/rust-clippy/master/index.html#disallowed_type [`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 [`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 [`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_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_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_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 [`doc_link_with_quotes`]: https://rust-lang.github.io/rust-clippy/master/index.html#doc_link_with_quotes

View File

@@ -137,8 +137,8 @@ pub static LINTS: &[&crate::LintInfo] = &[
crate::disallowed_names::DISALLOWED_NAMES_INFO, crate::disallowed_names::DISALLOWED_NAMES_INFO,
crate::disallowed_script_idents::DISALLOWED_SCRIPT_IDENTS_INFO, crate::disallowed_script_idents::DISALLOWED_SCRIPT_IDENTS_INFO,
crate::disallowed_types::DISALLOWED_TYPES_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_COMMENT_DOUBLE_SPACE_LINEBREAK_INFO,
crate::doc::DOC_INCLUDE_WITHOUT_CFG_INFO,
crate::doc::DOC_LAZY_CONTINUATION_INFO, crate::doc::DOC_LAZY_CONTINUATION_INFO,
crate::doc::DOC_LINK_CODE_INFO, crate::doc::DOC_LINK_CODE_INFO,
crate::doc::DOC_LINK_WITH_QUOTES_INFO, crate::doc::DOC_LINK_WITH_QUOTES_INFO,

View File

@@ -1,41 +1,20 @@
use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::diagnostics::span_lint_and_sugg;
use clippy_utils::source::snippet_opt;
use rustc_errors::Applicability; use rustc_errors::Applicability;
use rustc_lint::LateContext; use rustc_lint::LateContext;
use rustc_span::Span; use rustc_span::{BytePos, Span};
use super::DOC_COMMENT_DOUBLE_SPACE_LINEBREAK; use super::DOC_COMMENT_DOUBLE_SPACE_LINEBREAK;
pub fn check(cx: &LateContext<'_>, collected_breaks: &[Span]) { pub fn check(cx: &LateContext<'_>, collected_breaks: &[Span]) {
let replacements: Vec<_> = collect_doc_replacements(cx, collected_breaks); for r_span in collected_breaks {
span_lint_and_sugg(
if let Some((&(lo_span, _), &(hi_span, _))) = replacements.first().zip(replacements.last()) {
span_lint_and_then(
cx, cx,
DOC_COMMENT_DOUBLE_SPACE_LINEBREAK, 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", "doc comment uses two spaces for a hard line break",
|diag| { "replace this double space with a backslash",
diag.multipart_suggestion( "\\".to_owned(),
"replace this double space with a backslash", Applicability::MachineApplicable,
replacements,
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()
}

View File

@@ -772,8 +772,6 @@ fn check_attrs(cx: &LateContext<'_>, valid_idents: &FxHashSet<String>, attrs: &[
return None; return None;
} }
suspicious_doc_comments::check(cx, attrs);
let (fragments, _) = attrs_to_doc_fragments( let (fragments, _) = attrs_to_doc_fragments(
attrs.iter().filter_map(|attr| { attrs.iter().filter_map(|attr| {
if attr.doc_str_and_comment_kind().is_none() || attr.span().in_external_macro(cx.sess().source_map()) { if attr.doc_str_and_comment_kind().is_none() || attr.span().in_external_macro(cx.sess().source_map()) {

View File

@@ -1,76 +1,65 @@
error: doc comment uses two spaces for a hard line break error: doc comment uses two spaces for a hard line break
--> tests/ui/doc/doc_comment_double_space_linebreak.rs:7:43 --> tests/ui/doc/doc_comment_double_space_linebreak.rs:7:43
| |
LL | //! Should warn on double space linebreaks LL | //! Should warn on double space linebreaks
| ___________________________________________^ | ^^ help: replace this double space with a backslash: `\`
LL | | //! in file/module doc comment
| |____^
| |
= note: `-D clippy::doc-comment-double-space-linebreak` implied by `-D warnings` = 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: 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 error: doc comment uses two spaces for a hard line break
--> tests/ui/doc/doc_comment_double_space_linebreak.rs:35:51 --> tests/ui/doc/doc_comment_double_space_linebreak.rs:35:51
| |
LL | /// Should warn when doc comment uses double space LL | /// Should warn when doc comment uses double space
| ___________________________________________________^ | ^^ help: replace this double space with a backslash: `\`
LL | | /// as a line-break, even when there are multiple
LL | | /// in a row error: doc comment uses two spaces for a hard line break
| |____^ --> tests/ui/doc/doc_comment_double_space_linebreak.rs:36:50
|
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
| |
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 error: doc comment uses two spaces for a hard line break
--> tests/ui/doc/doc_comment_double_space_linebreak.rs:44:12 --> tests/ui/doc/doc_comment_double_space_linebreak.rs:44:12
| |
LL | /// 🌹 are 🟥 LL | /// 🌹 are 🟥
| ______________^ | ^^ help: replace this double space with a backslash: `\`
LL | | /// 🌷 are 🟦
LL | | /// 📎 is 😎 error: doc comment uses two spaces for a hard line break
LL | | /// and so are 🫵 --> tests/ui/doc/doc_comment_double_space_linebreak.rs:45:12
LL | | /// (hopefully no formatting weirdness linting this)
| |____^
| |
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 | /// 📎 is 😎
LL ~ /// 🌷 are 🟦\ | ^^ help: replace this double space with a backslash: `\`
LL ~ /// 📎 is 😎\
LL ~ /// and so are 🫵\ error: doc comment uses two spaces for a hard line break
LL ~ /// (hopefully no formatting weirdness linting this) --> 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 error: doc comment uses two spaces for a hard line break
--> tests/ui/doc/doc_comment_double_space_linebreak.rs:86:16 --> tests/ui/doc/doc_comment_double_space_linebreak.rs:86:16
| |
LL | /// here we mix LL | /// here we mix
| ________________^ | ^^ help: replace this double space with a backslash: `\`
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
|
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