|
12 | 12 |
|
13 | 13 | use crate::reexport::*;
|
14 | 14 | use crate::utils::{
|
15 |
| - in_macro, last_line_of_span, match_def_path, opt_def_id, paths, snippet_opt, span_lint, |
| 15 | + in_macro, last_line_of_span, match_def_path, opt_def_id, paths, snippet_opt, span_lint, span_lint_and_sugg, |
16 | 16 | span_lint_and_then, without_block_comments,
|
17 | 17 | };
|
18 | 18 | use if_chain::if_chain;
|
19 | 19 | use crate::rustc::hir::*;
|
20 | 20 | use crate::rustc::lint::{
|
21 |
| - CheckLintNameResult, LateContext, LateLintPass, LintArray, LintContext, LintPass, |
| 21 | + CheckLintNameResult, EarlyContext, EarlyLintPass, LateContext, LateLintPass, LintArray, LintContext, LintPass, |
22 | 22 | };
|
23 | 23 | use crate::rustc::ty::{self, TyCtxt};
|
24 | 24 | use crate::rustc::{declare_tool_lint, lint_array};
|
@@ -169,6 +169,35 @@ declare_clippy_lint! {
|
169 | 169 | "unknown_lints for scoped Clippy lints"
|
170 | 170 | }
|
171 | 171 |
|
| 172 | +/// **What it does:** Checks for `#[cfg_attr(rustfmt, rustfmt_skip)]` and suggests to replace it |
| 173 | +/// with `#[rustfmt::skip]`. |
| 174 | +/// |
| 175 | +/// **Why is this bad?** Since tool_attributes (rust-lang/rust#44690) are stable now, they should |
| 176 | +/// be used instead of the old `cfg_attr(rustfmt)` attribute. |
| 177 | +/// |
| 178 | +/// **Known problems:** It currently only detects outer attributes. But since it does not really |
| 179 | +/// makes sense to have `#![cfg_attr(rustfmt, rustfmt_skip)]` as an inner attribute, this should be |
| 180 | +/// ok. |
| 181 | +/// |
| 182 | +/// **Example:** |
| 183 | +/// |
| 184 | +/// Bad: |
| 185 | +/// ```rust |
| 186 | +/// #[cfg_attr(rustfmt, rustfmt_skip)] |
| 187 | +/// fn main() { } |
| 188 | +/// ``` |
| 189 | +/// |
| 190 | +/// Good: |
| 191 | +/// ```rust |
| 192 | +/// #[rustfmt::skip] |
| 193 | +/// fn main() { } |
| 194 | +/// ``` |
| 195 | +declare_clippy_lint! { |
| 196 | + pub DEPRECATED_CFG_ATTR, |
| 197 | + complexity, |
| 198 | + "usage of `cfg_attr(rustfmt)` instead of `tool_attributes`" |
| 199 | +} |
| 200 | + |
172 | 201 | #[derive(Copy, Clone)]
|
173 | 202 | pub struct AttrPass;
|
174 | 203 |
|
|
0 commit comments