Skip to content

Commit

Permalink
fix: warn on empty line outer AttrKind::DocComment
Browse files Browse the repository at this point in the history
  • Loading branch information
jdswensen committed Apr 2, 2023
1 parent 8f0ba1f commit 997f804
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions clippy_lints/src/attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ impl EarlyLintPass for EarlyAttributes {
fn check_empty_line_after_outer_attr(cx: &EarlyContext<'_>, item: &rustc_ast::Item) {
let mut iter = item.attrs.iter().peekable();
while let Some(attr) = iter.next() {
if matches!(attr.kind, AttrKind::Normal(..))
if (matches!(attr.kind, AttrKind::Normal(..)) || matches!(attr.kind, AttrKind::DocComment(..)))
&& attr.style == AttrStyle::Outer
&& is_present_in_source(cx, attr.span)
{
Expand All @@ -639,13 +639,17 @@ fn check_empty_line_after_outer_attr(cx: &EarlyContext<'_>, item: &rustc_ast::It
let lines = without_block_comments(lines);

if lines.iter().filter(|l| l.trim().is_empty()).count() > 2 {
span_lint(
cx,
EMPTY_LINE_AFTER_OUTER_ATTR,
begin_of_attr_to_item,
"found an empty line after an outer attribute. \
Perhaps you forgot to add a `!` to make it an inner attribute?",
);
let lint_mst = match attr.kind {
AttrKind::Normal(..) => {
"found an empty line after an outer attribute. \
Perhaps you forgot to add a `!` to make it an inner attribute?"
},
AttrKind::DocComment(..) => {
"found an empty line after an outer doc comment. \
Perhaps you need to use `//!` to make a comment on the module or remove the empty line?"
},
};
span_lint(cx, EMPTY_LINE_AFTER_OUTER_ATTR, begin_of_attr_to_item, lint_mst);
}
}
}
Expand Down

0 comments on commit 997f804

Please sign in to comment.