clippy_lints 0.0.84

A bunch of helpful lints to avoid common pitfalls in Rust
use rustc::lint::*;
use utils::span_lint;
use syntax::parse::token::InternedString;
use syntax::ast::*;

/// **What it does:** Checks for various things we like to keep tidy in clippy.
///
/// **Why is this bad?** We like to pretend we're an example of tidy code.
///
/// **Known problems:** None.
///
/// **Example:** Wrong ordering of the util::paths constants.
declare_lint! {
    pub CLIPPY_LINTS_INTERNAL,
    Allow,
    "various things that will negatively affect your clippy experience"
}


#[derive(Copy, Clone)]
pub struct Clippy;

impl LintPass for Clippy {
    fn get_lints(&self) -> LintArray {
        lint_array!(CLIPPY_LINTS_INTERNAL)
    }
}

impl EarlyLintPass for Clippy {
    fn check_crate(&mut self, cx: &EarlyContext, krate: &Crate) {
        if let Some(utils) = krate.module.items.iter().find(|item| item.ident.name.as_str() == "utils") {
            if let ItemKind::Mod(ref utils_mod) = utils.node {
                if let Some(paths) = utils_mod.items.iter().find(|item| item.ident.name.as_str() == "paths") {
                    if let ItemKind::Mod(ref paths_mod) = paths.node {
                        let mut last_name: Option<InternedString> = None;
                        for item in &paths_mod.items {
                            let name = item.ident.name.as_str();
                            if let Some(ref last_name) = last_name {
                                if **last_name > *name {
                                    span_lint(cx,
                                              CLIPPY_LINTS_INTERNAL,
                                              item.span,
                                              "this constant should be before the previous constant due to lexical ordering",
                                    );
                                }
                            }
                            last_name = Some(name);
                        }
                    }
                }
            }
        }
    }
}