Skip to content

Commit 7ea9443

Browse files
committed
Rewrite empty_line_after_doc_comments and empty_line_after_outer_attr
1 parent 51a1cf0 commit 7ea9443

File tree

68 files changed

+1131
-689
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+1131
-689
lines changed

clippy_lints/src/attrs/empty_line_after.rs

Lines changed: 0 additions & 52 deletions
This file was deleted.

clippy_lints/src/attrs/mod.rs

Lines changed: 0 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ mod blanket_clippy_restriction_lints;
66
mod deprecated_cfg_attr;
77
mod deprecated_semver;
88
mod duplicated_attributes;
9-
mod empty_line_after;
109
mod inline_always;
1110
mod mixed_attributes_style;
1211
mod non_minimal_cfg;
@@ -127,94 +126,6 @@ declare_clippy_lint! {
127126
"use of `#[deprecated(since = \"x\")]` where x is not semver"
128127
}
129128

130-
declare_clippy_lint! {
131-
/// ### What it does
132-
/// Checks for empty lines after outer attributes
133-
///
134-
/// ### Why is this bad?
135-
/// Most likely the attribute was meant to be an inner attribute using a '!'.
136-
/// If it was meant to be an outer attribute, then the following item
137-
/// should not be separated by empty lines.
138-
///
139-
/// ### Known problems
140-
/// Can cause false positives.
141-
///
142-
/// From the clippy side it's difficult to detect empty lines between an attributes and the
143-
/// following item because empty lines and comments are not part of the AST. The parsing
144-
/// currently works for basic cases but is not perfect.
145-
///
146-
/// ### Example
147-
/// ```no_run
148-
/// #[allow(dead_code)]
149-
///
150-
/// fn not_quite_good_code() { }
151-
/// ```
152-
///
153-
/// Use instead:
154-
/// ```no_run
155-
/// // Good (as inner attribute)
156-
/// #![allow(dead_code)]
157-
///
158-
/// fn this_is_fine() { }
159-
///
160-
/// // or
161-
///
162-
/// // Good (as outer attribute)
163-
/// #[allow(dead_code)]
164-
/// fn this_is_fine_too() { }
165-
/// ```
166-
#[clippy::version = "pre 1.29.0"]
167-
pub EMPTY_LINE_AFTER_OUTER_ATTR,
168-
nursery,
169-
"empty line after outer attribute"
170-
}
171-
172-
declare_clippy_lint! {
173-
/// ### What it does
174-
/// Checks for empty lines after documentation comments.
175-
///
176-
/// ### Why is this bad?
177-
/// The documentation comment was most likely meant to be an inner attribute or regular comment.
178-
/// If it was intended to be a documentation comment, then the empty line should be removed to
179-
/// be more idiomatic.
180-
///
181-
/// ### Known problems
182-
/// Only detects empty lines immediately following the documentation. If the doc comment is followed
183-
/// by an attribute and then an empty line, this lint will not trigger. Use `empty_line_after_outer_attr`
184-
/// in combination with this lint to detect both cases.
185-
///
186-
/// Does not detect empty lines after doc attributes (e.g. `#[doc = ""]`).
187-
///
188-
/// ### Example
189-
/// ```no_run
190-
/// /// Some doc comment with a blank line after it.
191-
///
192-
/// fn not_quite_good_code() { }
193-
/// ```
194-
///
195-
/// Use instead:
196-
/// ```no_run
197-
/// /// Good (no blank line)
198-
/// fn this_is_fine() { }
199-
/// ```
200-
///
201-
/// ```no_run
202-
/// // Good (convert to a regular comment)
203-
///
204-
/// fn this_is_fine_too() { }
205-
/// ```
206-
///
207-
/// ```no_run
208-
/// //! Good (convert to a comment on an inner attribute)
209-
///
210-
/// fn this_is_fine_as_well() { }
211-
/// ```
212-
#[clippy::version = "1.70.0"]
213-
pub EMPTY_LINE_AFTER_DOC_COMMENTS,
214-
nursery,
215-
"empty line after documentation comments"
216-
}
217-
218129
declare_clippy_lint! {
219130
/// ### What it does
220131
/// Checks for `warn`/`deny`/`forbid` attributes targeting the whole clippy::restriction category.
@@ -594,18 +505,12 @@ pub struct EarlyAttributes {
594505

595506
impl_lint_pass!(EarlyAttributes => [
596507
DEPRECATED_CFG_ATTR,
597-
EMPTY_LINE_AFTER_OUTER_ATTR,
598-
EMPTY_LINE_AFTER_DOC_COMMENTS,
599508
NON_MINIMAL_CFG,
600509
DEPRECATED_CLIPPY_CFG_ATTR,
601510
UNNECESSARY_CLIPPY_CFG,
602511
]);
603512

604513
impl EarlyLintPass for EarlyAttributes {
605-
fn check_item(&mut self, cx: &EarlyContext<'_>, item: &rustc_ast::Item) {
606-
empty_line_after::check(cx, item);
607-
}
608-
609514
fn check_attribute(&mut self, cx: &EarlyContext<'_>, attr: &Attribute) {
610515
deprecated_cfg_attr::check(cx, attr, &self.msrv);
611516
deprecated_cfg_attr::check_clippy(cx, attr);

clippy_lints/src/declared_lints.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,6 @@ pub(crate) static LINTS: &[&crate::LintInfo] = &[
5353
crate::attrs::DEPRECATED_CLIPPY_CFG_ATTR_INFO,
5454
crate::attrs::DEPRECATED_SEMVER_INFO,
5555
crate::attrs::DUPLICATED_ATTRIBUTES_INFO,
56-
crate::attrs::EMPTY_LINE_AFTER_DOC_COMMENTS_INFO,
57-
crate::attrs::EMPTY_LINE_AFTER_OUTER_ATTR_INFO,
5856
crate::attrs::INLINE_ALWAYS_INFO,
5957
crate::attrs::MIXED_ATTRIBUTES_STYLE_INFO,
6058
crate::attrs::NON_MINIMAL_CFG_INFO,
@@ -142,6 +140,8 @@ pub(crate) static LINTS: &[&crate::LintInfo] = &[
142140
crate::doc::DOC_LINK_WITH_QUOTES_INFO,
143141
crate::doc::DOC_MARKDOWN_INFO,
144142
crate::doc::EMPTY_DOCS_INFO,
143+
crate::doc::EMPTY_LINE_AFTER_DOC_COMMENTS_INFO,
144+
crate::doc::EMPTY_LINE_AFTER_OUTER_ATTR_INFO,
145145
crate::doc::MISSING_ERRORS_DOC_INFO,
146146
crate::doc::MISSING_PANICS_DOC_INFO,
147147
crate::doc::MISSING_SAFETY_DOC_INFO,

0 commit comments

Comments
 (0)