]> git.lizzy.rs Git - rust.git/blob - clippy_lints/src/blacklisted_name.rs
Merge pull request #1093 from oli-obk/serde_specific_lint
[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:**
12 /// ```rust
13 /// let foo = 3.14;
14 /// ```
15 declare_lint! {
16     pub BLACKLISTED_NAME,
17     Warn,
18     "usage of a blacklisted/placeholder name"
19 }
20
21 #[derive(Clone, Debug)]
22 pub struct BlackListedName {
23     blacklist: Vec<String>,
24 }
25
26 impl BlackListedName {
27     pub fn new(blacklist: Vec<String>) -> BlackListedName {
28         BlackListedName { blacklist: blacklist }
29     }
30 }
31
32 impl LintPass for BlackListedName {
33     fn get_lints(&self) -> LintArray {
34         lint_array!(BLACKLISTED_NAME)
35     }
36 }
37
38 impl LateLintPass for BlackListedName {
39     fn check_pat(&mut self, cx: &LateContext, pat: &Pat) {
40         if let PatKind::Binding(_, ref ident, _) = pat.node {
41             if self.blacklist.iter().any(|s| s == &*ident.node.as_str()) {
42                 span_lint(cx,
43                           BLACKLISTED_NAME,
44                           pat.span,
45                           &format!("use of a blacklisted/placeholder name `{}`", ident.node));
46             }
47         }
48     }
49 }