Skip to content

Commit

Permalink
Do not emit TOO_LONG_FIRST_DOC_PARAGRAPH lint if item is generated …
Browse files Browse the repository at this point in the history
…from proc-macro and simplify code to emit lint
  • Loading branch information
GuillaumeGomez committed Aug 18, 2024
1 parent 3c6e5ef commit a203342
Showing 1 changed file with 18 additions and 21 deletions.
39 changes: 18 additions & 21 deletions clippy_lints/src/doc/too_long_first_doc_paragraph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ use rustc_errors::Applicability;
use rustc_hir::{Item, ItemKind};
use rustc_lint::LateContext;

use clippy_utils::diagnostics::{span_lint, span_lint_and_then};
use clippy_utils::diagnostics::span_lint_and_then;
use clippy_utils::is_from_proc_macro;
use clippy_utils::source::snippet_opt;

use super::TOO_LONG_FIRST_DOC_PARAGRAPH;
Expand Down Expand Up @@ -63,32 +64,28 @@ pub(super) fn check(
let &[first_span, .., last_span] = spans.as_slice() else {
return;
};
if is_from_proc_macro(cx, item) {
return;
}

if should_suggest_empty_doc
&& let Some(second_span) = spans.get(1)
&& let new_span = first_span.with_hi(second_span.lo()).with_lo(first_span.hi())
&& let Some(snippet) = snippet_opt(cx, new_span)
{
span_lint_and_then(
cx,
TOO_LONG_FIRST_DOC_PARAGRAPH,
first_span.with_hi(last_span.lo()),
"first doc comment paragraph is too long",
|diag| {
span_lint_and_then(
cx,
TOO_LONG_FIRST_DOC_PARAGRAPH,
first_span.with_hi(last_span.lo()),
"first doc comment paragraph is too long",
|diag| {
if should_suggest_empty_doc
&& let Some(second_span) = spans.get(1)
&& let new_span = first_span.with_hi(second_span.lo()).with_lo(first_span.hi())
&& let Some(snippet) = snippet_opt(cx, new_span)
{
diag.span_suggestion(
new_span,
"add an empty line",
format!("{snippet}///\n"),
Applicability::MachineApplicable,
);
},
);
return;
}
span_lint(
cx,
TOO_LONG_FIRST_DOC_PARAGRAPH,
first_span.with_hi(last_span.lo()),
"first doc comment paragraph is too long",
}
},
);
}

0 comments on commit a203342

Please sign in to comment.