]> git.lizzy.rs Git - rust.git/blob - clippy_lints/src/utils/internal_lints.rs
Make the lint docstrings more consistent.
[rust.git] / clippy_lints / src / utils / internal_lints.rs
1 use rustc::lint::*;
2 use utils::span_lint;
3 use syntax::parse::token::InternedString;
4 use syntax::ast::*;
5
6 /// **What it does:** Checks for various things we like to keep tidy in clippy.
7 ///
8 /// **Why is this bad?** We like to pretend we're an example of tidy code.
9 ///
10 /// **Known problems:** None.
11 ///
12 /// **Example:** Wrong ordering of the util::paths constants.
13 declare_lint! {
14     pub CLIPPY_LINTS_INTERNAL, Allow,
15     "Various things that will negatively affect your clippy experience"
16 }
17
18
19 #[derive(Copy, Clone)]
20 pub struct Clippy;
21
22 impl LintPass for Clippy {
23     fn get_lints(&self) -> LintArray {
24         lint_array!(CLIPPY_LINTS_INTERNAL)
25     }
26 }
27
28 impl EarlyLintPass for Clippy {
29     fn check_crate(&mut self, cx: &EarlyContext, krate: &Crate) {
30         if let Some(utils) = krate.module.items.iter().find(|item| item.ident.name.as_str() == "utils") {
31             if let ItemKind::Mod(ref utils_mod) = utils.node {
32                 if let Some(paths) = utils_mod.items.iter().find(|item| item.ident.name.as_str() == "paths") {
33                     if let ItemKind::Mod(ref paths_mod) = paths.node {
34                         let mut last_name: Option<InternedString> = None;
35                         for item in &paths_mod.items {
36                             let name = item.ident.name.as_str();
37                             if let Some(ref last_name) = last_name {
38                                 if **last_name > *name {
39                                     span_lint(cx,
40                                               CLIPPY_LINTS_INTERNAL,
41                                               item.span,
42                                               "this constant should be before the previous constant due to lexical ordering",
43                                     );
44                                 }
45                             }
46                             last_name = Some(name);
47                         }
48                     }
49                 }
50             }
51         }
52     }
53 }