]> git.lizzy.rs Git - rust.git/blob - clippy_lints/src/blacklisted_name.rs
Merge pull request #950 from oli-obk/split3
[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:** This lints about usage of blacklisted names.
6 ///
7 /// **Why is this bad?** These names are usually placeholder names and should be avoided.
8 ///
9 /// **Known problems:** None.
10 ///
11 /// **Example:** `let foo = 3.14;`
12 declare_lint! {
13     pub BLACKLISTED_NAME,
14     Warn,
15     "usage of a blacklisted/placeholder name"
16 }
17
18 #[derive(Clone, Debug)]
19 pub struct BlackListedName {
20     blacklist: Vec<String>,
21 }
22
23 impl BlackListedName {
24     pub fn new(blacklist: Vec<String>) -> BlackListedName {
25         BlackListedName { blacklist: blacklist }
26     }
27 }
28
29 impl LintPass for BlackListedName {
30     fn get_lints(&self) -> LintArray {
31         lint_array!(BLACKLISTED_NAME)
32     }
33 }
34
35 impl LateLintPass for BlackListedName {
36     fn check_pat(&mut self, cx: &LateContext, pat: &Pat) {
37         if let PatKind::Ident(_, ref ident, _) = pat.node {
38             if self.blacklist.iter().any(|s| s == &*ident.node.as_str()) {
39                 span_lint(cx,
40                           BLACKLISTED_NAME,
41                           pat.span,
42                           &format!("use of a blacklisted/placeholder name `{}`", ident.node));
43             }
44         }
45     }
46 }