about summary refs log tree commit diff
path: root/clippy_lints
diff options
context:
space:
mode:
authorflip1995 <9744647+flip1995@users.noreply.github.com>2018-09-03 15:34:12 +0200
committerflip1995 <hello@philkrones.com>2018-11-02 19:49:57 +0100
commite1cf160e2a2fba4cf7625dab1a52af5adfc534f5 (patch)
treeaead229feb0d6292071a161c08c18fde959d4434 /clippy_lints
parentdc1e4091546c1416fb031ada9ad8a821c039b732 (diff)
downloadrust-e1cf160e2a2fba4cf7625dab1a52af5adfc534f5.tar.gz
rust-e1cf160e2a2fba4cf7625dab1a52af5adfc534f5.zip
Add cfg_attr(rustfmt) lint
Diffstat (limited to 'clippy_lints')
-rw-r--r--clippy_lints/src/attrs.rs33
-rw-r--r--clippy_lints/src/lib.rs3
2 files changed, 34 insertions, 2 deletions
diff --git a/clippy_lints/src/attrs.rs b/clippy_lints/src/attrs.rs
index 89d676f3f4c..4ea13f649d7 100644
--- a/clippy_lints/src/attrs.rs
+++ b/clippy_lints/src/attrs.rs
@@ -12,13 +12,13 @@
 
 use crate::reexport::*;
 use crate::utils::{
-    in_macro, last_line_of_span, match_def_path, opt_def_id, paths, snippet_opt, span_lint,
+    in_macro, last_line_of_span, match_def_path, opt_def_id, paths, snippet_opt, span_lint, span_lint_and_sugg,
     span_lint_and_then, without_block_comments,
 };
 use if_chain::if_chain;
 use crate::rustc::hir::*;
 use crate::rustc::lint::{
-    CheckLintNameResult, LateContext, LateLintPass, LintArray, LintContext, LintPass,
+    CheckLintNameResult, EarlyContext, EarlyLintPass, LateContext, LateLintPass, LintArray, LintContext, LintPass,
 };
 use crate::rustc::ty::{self, TyCtxt};
 use crate::rustc::{declare_tool_lint, lint_array};
@@ -169,6 +169,35 @@ declare_clippy_lint! {
     "unknown_lints for scoped Clippy lints"
 }
 
+/// **What it does:** Checks for `#[cfg_attr(rustfmt, rustfmt_skip)]` and suggests to replace it
+/// with `#[rustfmt::skip]`.
+///
+/// **Why is this bad?** Since tool_attributes (rust-lang/rust#44690) are stable now, they should
+/// be used instead of the old `cfg_attr(rustfmt)` attribute.
+///
+/// **Known problems:** It currently only detects outer attributes. But since it does not really
+/// makes sense to have `#![cfg_attr(rustfmt, rustfmt_skip)]` as an inner attribute, this should be
+/// ok.
+///
+/// **Example:**
+///
+/// Bad:
+/// ```rust
+/// #[cfg_attr(rustfmt, rustfmt_skip)]
+/// fn main() { }
+/// ```
+///
+/// Good:
+/// ```rust
+/// #[rustfmt::skip]
+/// fn main() { }
+/// ```
+declare_clippy_lint! {
+    pub DEPRECATED_CFG_ATTR,
+    complexity,
+    "usage of `cfg_attr(rustfmt)` instead of `tool_attributes`"
+}
+
 #[derive(Copy, Clone)]
 pub struct AttrPass;
 
diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs
index 863c0623487..f3fce54f910 100644
--- a/clippy_lints/src/lib.rs
+++ b/clippy_lints/src/lib.rs
@@ -220,6 +220,7 @@ pub fn register_pre_expansion_lints(session: &rustc::session::Session, store: &m
     store.register_pre_expansion_pass(Some(session), box non_expressive_names::NonExpressiveNames {
         single_char_binding_names_threshold: conf.single_char_binding_names_threshold,
     });
+    store.register_pre_expansion_pass(Some(session), box attrs::CfgAttrPass);
 }
 
 pub fn read_conf(reg: &rustc_plugin::Registry<'_>) -> Conf {
@@ -532,6 +533,7 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) {
         approx_const::APPROX_CONSTANT,
         assign_ops::ASSIGN_OP_PATTERN,
         assign_ops::MISREFACTORED_ASSIGN_OP,
+        attrs::DEPRECATED_CFG_ATTR,
         attrs::DEPRECATED_SEMVER,
         attrs::UNKNOWN_CLIPPY_LINTS,
         attrs::USELESS_ATTRIBUTE,
@@ -839,6 +841,7 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) {
 
     reg.register_lint_group("clippy::complexity", Some("clippy_complexity"), vec![
         assign_ops::MISREFACTORED_ASSIGN_OP,
+        attrs::DEPRECATED_CFG_ATTR,
         booleans::NONMINIMAL_BOOL,
         cyclomatic_complexity::CYCLOMATIC_COMPLEXITY,
         double_comparison::DOUBLE_COMPARISONS,