don't lint similar_names inside #[test] functions

This commit is contained in:
Oliver Schneider 2016-05-02 10:52:55 +02:00
parent 469b3d51b4
commit 10f468e679

View file

@ -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
@ -237,12 +238,14 @@ 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) {
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,
@ -257,6 +260,8 @@ impl EarlyLintPass for NonExpressiveNames {
visit::walk_block(&mut visitor, blk);
}
}
}
}
/// Precondition: `a_name.chars().count() < b_name.chars().count()`.
fn levenstein_not_1(a_name: &str, b_name: &str) -> bool {