mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-27 15:11:30 +00:00
Add cfg_attr(rustfmt) lint
This commit is contained in:
parent
dc1e409154
commit
e1cf160e2a
2 changed files with 34 additions and 2 deletions
|
@ -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;
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue