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:
parent
f94f64f5e8
commit
2fd51b8d34
5 changed files with 51 additions and 85 deletions
|
|
@ -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,
|
||||
Applicability::MachineApplicable,
|
||||
);
|
||||
},
|
||||
"replace this double space with a backslash",
|
||||
"\\".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()) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue