Skip to content

Commit 2e02805

Browse files
committed
Rewrite empty_line_after_doc_comments and empty_line_after_outer_attr
1 parent b02cb24 commit 2e02805

File tree

74 files changed

+1563
-872
lines changed

Some content is hidden

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

74 files changed

+1563
-872
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;
@@ -128,94 +127,6 @@ declare_clippy_lint! {
128127
"use of `#[deprecated(since = \"x\")]` where x is not semver"
129128
}
130129

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

604515
impl_lint_pass!(EarlyAttributes => [
605516
DEPRECATED_CFG_ATTR,
606-
EMPTY_LINE_AFTER_OUTER_ATTR,
607-
EMPTY_LINE_AFTER_DOC_COMMENTS,
608517
NON_MINIMAL_CFG,
609518
DEPRECATED_CLIPPY_CFG_ATTR,
610519
UNNECESSARY_CLIPPY_CFG,
611520
]);
612521

613522
impl EarlyLintPass for EarlyAttributes {
614-
fn check_item(&mut self, cx: &EarlyContext<'_>, item: &rustc_ast::Item) {
615-
empty_line_after::check(cx, item);
616-
}
617-
618523
fn check_attribute(&mut self, cx: &EarlyContext<'_>, attr: &Attribute) {
619524
deprecated_cfg_attr::check(cx, attr, &self.msrv);
620525
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)