]> git.lizzy.rs Git - rust.git/blob - clippy_lints/src/blacklisted_name.rs
Merge pull request #1373 from Manishearth/rustup
[rust.git] / clippy_lints / src / blacklisted_name.rs
1 use rustc::lint::*;
2 use rustc::hir::*;
3 use utils::span_lint;
4
5 /// **What it does:** Checks for usage of blacklisted names for variables, such
6 /// as `foo`.
7 ///
8 /// **Why is this bad?** These names are usually placeholder names and should be
9 /// avoided.
10 ///
11 /// **Known problems:** None.
12 ///
13 /// **Example:**
14 /// ```rust
15 /// let foo = 3.14;
16 /// ```
17 declare_lint! {
18     pub BLACKLISTED_NAME,
19     Warn,
20     "usage of a blacklisted/placeholder name"
21 }
22
23 #[derive(Clone, Debug)]
24 pub struct BlackListedName {
25     blacklist: Vec<String>,
26 }
27
28 impl BlackListedName {
29     pub fn new(blacklist: Vec<String>) -> BlackListedName {
30         BlackListedName { blacklist: blacklist }
31     }
32 }
33
34 impl LintPass for BlackListedName {
35     fn get_lints(&self) -> LintArray {
36         lint_array!(BLACKLISTED_NAME)
37     }
38 }
39
40 impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BlackListedName {
41     fn check_pat(&mut self, cx: &LateContext<'a, 'tcx>, pat: &'tcx Pat) {
42         if let PatKind::Binding(_, _, ref ident, _) = pat.node {
43             if self.blacklist.iter().any(|s| s == &*ident.node.as_str()) {
44                 span_lint(cx,
45                           BLACKLISTED_NAME,
46                           pat.span,
47                           &format!("use of a blacklisted/placeholder name `{}`", ident.node));
48             }
49         }
50     }
51 }