diff --git a/README.md b/README.md index 3b0ca3f4a38..9de4eef72ed 100644 --- a/README.md +++ b/README.md @@ -129,7 +129,7 @@ name [shadow_same](https://github.com/Manishearth/rust-clippy/wiki#shadow_same) | allow | rebinding a name to itself, e.g. `let mut x = &mut x` [shadow_unrelated](https://github.com/Manishearth/rust-clippy/wiki#shadow_unrelated) | allow | The name is re-bound without even using the original value [should_implement_trait](https://github.com/Manishearth/rust-clippy/wiki#should_implement_trait) | warn | defining a method that should be implementing a std trait -[similar_names](https://github.com/Manishearth/rust-clippy/wiki#similar_names) | warn | similarly named items and bindings +[similar_names](https://github.com/Manishearth/rust-clippy/wiki#similar_names) | allow | similarly named items and bindings [single_char_pattern](https://github.com/Manishearth/rust-clippy/wiki#single_char_pattern) | warn | using a single-character str where a char could be used, e.g. `_.split("x")` [single_match](https://github.com/Manishearth/rust-clippy/wiki#single_match) | warn | a match statement with a single nontrivial arm (i.e, where the other arm is `_ => {}`) is used; recommends `if let` instead [single_match_else](https://github.com/Manishearth/rust-clippy/wiki#single_match_else) | allow | a match statement with a two arms where the second arm's pattern is a wildcard; recommends `if let` instead diff --git a/src/lib.rs b/src/lib.rs index e22d85a43e1..435e6998c16 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -266,6 +266,7 @@ pub fn plugin_registrar(reg: &mut Registry) { methods::WRONG_PUB_SELF_CONVENTION, mut_mut::MUT_MUT, mutex_atomic::MUTEX_INTEGER, + non_expressive_names::SIMILAR_NAMES, print::PRINT_STDOUT, print::USE_DEBUG, shadow::SHADOW_REUSE, @@ -368,7 +369,6 @@ pub fn plugin_registrar(reg: &mut Registry) { new_without_default::NEW_WITHOUT_DEFAULT, no_effect::NO_EFFECT, non_expressive_names::MANY_SINGLE_CHAR_NAMES, - non_expressive_names::SIMILAR_NAMES, open_options::NONSENSICAL_OPEN_OPTIONS, overflow_check_conditional::OVERFLOW_CHECK_CONDITIONAL, panic::PANIC_PARAMS, diff --git a/src/non_expressive_names.rs b/src/non_expressive_names.rs index a6f0571c499..0c6fdc37066 100644 --- a/src/non_expressive_names.rs +++ b/src/non_expressive_names.rs @@ -2,7 +2,8 @@ use rustc::lint::*; use syntax::codemap::Span; use syntax::parse::token::InternedString; use syntax::ast::*; -use syntax::visit::{self, FnKind}; +use syntax::attr; +use syntax::visit; use utils::{span_lint_and_then, in_macro, span_lint}; /// **What it does:** This lint warns about names that are very similar and thus confusing @@ -14,7 +15,7 @@ use utils::{span_lint_and_then, in_macro, span_lint}; /// **Example:** `checked_exp` and `checked_expr` declare_lint! { pub SIMILAR_NAMES, - Warn, + Allow, "similarly named items and bindings" } @@ -237,24 +238,28 @@ impl<'v, 'a, 'b> visit::Visitor<'v> for SimilarNamesLocalVisitor<'a, 'b> { }); } fn visit_item(&mut self, _: &'v Item) { - // do nothing + // do not recurse into inner items } } impl EarlyLintPass for NonExpressiveNames { - fn check_fn(&mut self, cx: &EarlyContext, _: FnKind, decl: &FnDecl, blk: &Block, _: Span, _: NodeId) { - let mut visitor = SimilarNamesLocalVisitor { - names: Vec::new(), - cx: cx, - lint: &self, - single_char_names: Vec::new(), - }; - // initialize with function arguments - for arg in &decl.inputs { - visit::walk_pat(&mut SimilarNamesNameVisitor(&mut visitor), &arg.pat); + fn check_item(&mut self, cx: &EarlyContext, item: &Item) { + if let ItemKind::Fn(ref decl, _, _, _, _, ref blk) = item.node { + if !attr::contains_name(&item.attrs, "test") { + let mut visitor = SimilarNamesLocalVisitor { + names: Vec::new(), + cx: cx, + lint: &self, + single_char_names: Vec::new(), + }; + // initialize with function arguments + for arg in &decl.inputs { + visit::walk_pat(&mut SimilarNamesNameVisitor(&mut visitor), &arg.pat); + } + // walk all other bindings + visit::walk_block(&mut visitor, blk); + } } - // walk all other bindings - visit::walk_block(&mut visitor, blk); } } diff --git a/tests/compile-fail/non_expressive_names.rs b/tests/compile-fail/non_expressive_names.rs index b756253e6ad..61fe0067a27 100644 --- a/tests/compile-fail/non_expressive_names.rs +++ b/tests/compile-fail/non_expressive_names.rs @@ -1,6 +1,6 @@ #![feature(plugin)] #![plugin(clippy)] -#![deny(clippy)] +#![deny(clippy,similar_names)] //~^ NOTE: lint level defined here //~| NOTE: lint level defined here //~| NOTE: lint level defined here