From d66e9addd685c8fc2264e68590d745e869311242 Mon Sep 17 00:00:00 2001 From: VictorHugoPilled Date: Tue, 10 Sep 2024 21:38:59 +0000 Subject: [PATCH] fix: Fixed incorrect comment form suggestion chore: Ran cargo dev fmt chore: Fixed spacing fix: Fixed spacing for comment suggestion fix: Added new module level test to too_long_first_doc_paragraph chore: Ran cargo uibless --- .../src/doc/too_long_first_doc_paragraph.rs | 9 +++++- tests/ui/too_long_first_doc_paragraph.rs | 10 +++++++ tests/ui/too_long_first_doc_paragraph.stderr | 28 +++++++++++++++---- 3 files changed, 40 insertions(+), 7 deletions(-) diff --git a/clippy_lints/src/doc/too_long_first_doc_paragraph.rs b/clippy_lints/src/doc/too_long_first_doc_paragraph.rs index 7bb3bb12f..0165d24c7 100644 --- a/clippy_lints/src/doc/too_long_first_doc_paragraph.rs +++ b/clippy_lints/src/doc/too_long_first_doc_paragraph.rs @@ -79,10 +79,17 @@ pub(super) fn check( && let new_span = first_span.with_hi(second_span.lo()).with_lo(first_span.hi()) && let Some(snippet) = snippet_opt(cx, new_span) { + let Some(first) = snippet_opt(cx, first_span) else { + return; + }; + let Some(comment_form) = first.get(..3) else { + return; + }; + diag.span_suggestion( new_span, "add an empty line", - format!("{snippet}///\n"), + format!("{snippet}{comment_form}{snippet}"), Applicability::MachineApplicable, ); } diff --git a/tests/ui/too_long_first_doc_paragraph.rs b/tests/ui/too_long_first_doc_paragraph.rs index 1042249c5..7d0a37cde 100644 --- a/tests/ui/too_long_first_doc_paragraph.rs +++ b/tests/ui/too_long_first_doc_paragraph.rs @@ -2,6 +2,16 @@ #![warn(clippy::too_long_first_doc_paragraph)] +pub mod foo { + + // in foo.rs + //! A very short summary. + //! A much longer explanation that goes into a lot more detail about + //! how the thing works, possibly with doclinks and so one, + //! and probably spanning a many rows. Blablabla, it needs to be over + //! 200 characters so I needed to write something longeeeeeeer. +} + /// Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc turpis nunc, lacinia /// a dolor in, pellentesque aliquet enim. Cras nec maximus sem. Mauris arcu libero, /// gravida non lacinia at, rhoncus eu lacus. diff --git a/tests/ui/too_long_first_doc_paragraph.stderr b/tests/ui/too_long_first_doc_paragraph.stderr index 7f48e5cf8..39926647f 100644 --- a/tests/ui/too_long_first_doc_paragraph.stderr +++ b/tests/ui/too_long_first_doc_paragraph.stderr @@ -1,16 +1,32 @@ error: first doc comment paragraph is too long - --> tests/ui/too_long_first_doc_paragraph.rs:5:1 + --> tests/ui/too_long_first_doc_paragraph.rs:8:5 + | +LL | / //! A very short summary. +LL | | //! A much longer explanation that goes into a lot more detail about +LL | | //! how the thing works, possibly with doclinks and so one, +LL | | //! and probably spanning a many rows. Blablabla, it needs to be over +LL | | //! 200 characters so I needed to write something longeeeeeeer. + | |____^ + | + = note: `-D clippy::too-long-first-doc-paragraph` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::too_long_first_doc_paragraph)]` +help: add an empty line + | +LL ~ //! A very short summary. +LL + //! +LL ~ //! A much longer explanation that goes into a lot more detail about + | + +error: first doc comment paragraph is too long + --> tests/ui/too_long_first_doc_paragraph.rs:15:1 | LL | / /// Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc turpis nunc, lacinia LL | | /// a dolor in, pellentesque aliquet enim. Cras nec maximus sem. Mauris arcu libero, LL | | /// gravida non lacinia at, rhoncus eu lacus. | |_ - | - = note: `-D clippy::too-long-first-doc-paragraph` implied by `-D warnings` - = help: to override `-D warnings` add `#[allow(clippy::too_long_first_doc_paragraph)]` error: first doc comment paragraph is too long - --> tests/ui/too_long_first_doc_paragraph.rs:26:1 + --> tests/ui/too_long_first_doc_paragraph.rs:36:1 | LL | / /// Lorem LL | | /// ipsum dolor sit amet, consectetur adipiscing elit. Nunc turpis nunc, lacinia @@ -18,5 +34,5 @@ LL | | /// a dolor in, pellentesque aliquet enim. Cras nec maximus sem. Mauris a LL | | /// gravida non lacinia at, rhoncus eu lacus. | |_ -error: aborting due to 2 previous errors +error: aborting due to 3 previous errors