Skip to content

Commit

Permalink
add additional testcases; check doc comment not from expansion
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacherr committed Jun 27, 2024
1 parent bbfee91 commit 916aae1
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 6 deletions.
1 change: 1 addition & 0 deletions clippy_lints/src/doc/doc_comment_double_space_linebreak.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ fn collect_doc_replacements(attrs: &[Attribute]) -> Vec<(Span, String)> {
.iter()
.filter_map(|attr| {
if let AttrKind::DocComment(com_kind, sym) = attr.kind
&& !attr.span.from_expansion()
&& com_kind == CommentKind::Line
&& let comment = sym.as_str()
&& comment.ends_with(" ")
Expand Down
4 changes: 2 additions & 2 deletions clippy_lints/src/doc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ declare_clippy_lint! {
/// fn add(l: i32, r: i32) -> i32 {
/// l + r
/// }
/// ``````
/// ```
///
/// Use instead:
/// ```no_run
Expand All @@ -450,7 +450,7 @@ declare_clippy_lint! {
/// ```
#[clippy::version = "1.80.0"]
pub DOC_COMMENT_DOUBLE_SPACE_LINEBREAK,
restriction,
pedantic,
"double-space used for doc comment linebreak instead of `\\`"
}

Expand Down
20 changes: 19 additions & 1 deletion tests/ui/doc/doc_comment_double_space_linebreak.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ fn single_line_split() {}

// note: cargo fmt can remove double spaces from normal and block comments
// Should not warn on normal comments
// with double spaces at the end of a line
// with double spaces at the end of a line

#[doc = "This is a doc attribute, which should not be linted"]
fn normal_comment() {
/*
Should not warn on block comments
Expand All @@ -40,4 +41,21 @@ fn double_space_doc_comment() {}
/// as a line-break
fn back_slash_doc_comment() {}

/// 🌹 are 🟥\
/// 🌷 are 🟦\
/// 📎 is 😎\
/// and so are 🫵\
/// (hopefully no formatting weirdness linting this)
fn multi_byte_chars_tada() {}

macro_rules! macro_that_makes_function {
() => {
/// Shouldn't lint on this!
/// (hopefully)
fn my_macro_created_function() {}
}
}

macro_that_makes_function!();

fn main() {}
20 changes: 19 additions & 1 deletion tests/ui/doc/doc_comment_double_space_linebreak.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ fn single_line_split() {}

// note: cargo fmt can remove double spaces from normal and block comments
// Should not warn on normal comments
// with double spaces at the end of a line
// with double spaces at the end of a line

#[doc = "This is a doc attribute, which should not be linted"]
fn normal_comment() {
/*
Should not warn on block comments
Expand All @@ -40,4 +41,21 @@ fn double_space_doc_comment() {}
/// as a line-break
fn back_slash_doc_comment() {}

/// 🌹 are 🟥
/// 🌷 are 🟦
/// 📎 is 😎
/// and so are 🫵
/// (hopefully no formatting weirdness linting this)
fn multi_byte_chars_tada() {}

macro_rules! macro_that_makes_function {
() => {
/// Shouldn't lint on this!
/// (hopefully)
fn my_macro_created_function() {}
}
}

macro_that_makes_function!();

fn main() {}
21 changes: 19 additions & 2 deletions tests/ui/doc/doc_comment_double_space_linebreak.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ LL | //! Should warn on double space linebreaks
= help: to override `-D warnings` add `#[allow(clippy::doc_comment_double_space_linebreak)]`

error: doc comments should use a back-slash (\) instead of a double space to indicate a linebreak
--> tests/ui/doc/doc_comment_double_space_linebreak.rs:34:1
--> tests/ui/doc/doc_comment_double_space_linebreak.rs:35:1
|
LL | / /// Should warn when doc comment uses double space
LL | | /// as a line-break, even when there are multiple
Expand All @@ -20,5 +20,22 @@ LL + /// Should warn when doc comment uses double space\
LL + /// as a line-break, even when there are multiple\
|

error: aborting due to 2 previous errors
error: doc comments should use a back-slash (\) instead of a double space to indicate a linebreak
--> tests/ui/doc/doc_comment_double_space_linebreak.rs:44:1
|
LL | / /// 🌹 are 🟥
LL | | /// 🌷 are 🟦
LL | | /// 📎 is 😎
LL | | /// and so are 🫵
| |___________________^
|
help: replace this double space with a back-slash
|
LL ~ /// 🌹 are 🟥\
LL ~ /// 🌷 are 🟦\
LL ~ /// 📎 is 😎\
LL ~ /// and so are 🫵\
|

error: aborting due to 3 previous errors

0 comments on commit 916aae1

Please sign in to comment.