mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-24 15:54:15 +00:00
add an internal lint that catches misordered paths
This commit is contained in:
parent
fc54a91916
commit
02c46f057f
@ -169,6 +169,7 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry) {
|
||||
// end deprecated lints, do not remove this comment, it’s used in `update_lints`
|
||||
|
||||
reg.register_late_lint_pass(box serde::Serde);
|
||||
reg.register_early_lint_pass(box utils::internal_lints::Clippy);
|
||||
reg.register_late_lint_pass(box types::TypePass);
|
||||
reg.register_late_lint_pass(box booleans::NonminimalBool);
|
||||
reg.register_late_lint_pass(box misc::TopLevelRefPass);
|
||||
|
53
clippy_lints/src/utils/internal_lints.rs
Normal file
53
clippy_lints/src/utils/internal_lints.rs
Normal file
@ -0,0 +1,53 @@
|
||||
use rustc::lint::*;
|
||||
use utils::span_lint;
|
||||
use syntax::parse::token::InternedString;
|
||||
use syntax::ast::*;
|
||||
|
||||
/// **What it does:** This lint checks for various things we like to keep tidy in clippy
|
||||
///
|
||||
/// **Why is this bad?** ???
|
||||
///
|
||||
/// **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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -25,6 +25,7 @@ pub mod conf;
|
||||
mod hir;
|
||||
pub mod paths;
|
||||
pub mod sugg;
|
||||
pub mod internal_lints;
|
||||
pub use self::hir::{SpanlessEq, SpanlessHash};
|
||||
|
||||
pub type MethodArgs = HirVec<P<Expr>>;
|
||||
|
@ -17,7 +17,7 @@ fn dogfood() {
|
||||
let mut s = String::new();
|
||||
s.push_str(" -L target/debug/");
|
||||
s.push_str(" -L target/debug/deps");
|
||||
s.push_str(" -Zextra-plugins=clippy -Ltarget_recur/debug -Dclippy_pedantic -Dclippy");
|
||||
s.push_str(" -Zextra-plugins=clippy -Ltarget_recur/debug -Dclippy_pedantic -Dclippy -Dclippy_lints_internal");
|
||||
config.target_rustcflags = Some(s);
|
||||
if let Ok(name) = var("TESTNAME") {
|
||||
config.filter = Some(name.to_owned())
|
||||
@ -29,6 +29,7 @@ fn dogfood() {
|
||||
}
|
||||
|
||||
config.mode = cfg_mode;
|
||||
config.verbose = true;
|
||||
|
||||
let files = ["src/main.rs", "src/lib.rs", "clippy_lints/src/lib.rs"];
|
||||
|
||||
|
@ -150,11 +150,10 @@ def main(print_only=False, check=False):
|
||||
return
|
||||
|
||||
# collect all lints from source files
|
||||
for root, _, files in os.walk('clippy_lints/src'):
|
||||
for fn in files:
|
||||
for fn in os.listdir('clippy_lints/src'):
|
||||
if fn.endswith('.rs'):
|
||||
collect(lints, deprecated_lints, restriction_lints,
|
||||
os.path.join(root, fn))
|
||||
os.path.join('clippy_lints', 'src', fn))
|
||||
|
||||
# determine version
|
||||
with open('Cargo.toml') as fp:
|
||||
|
Loading…
Reference in New Issue
Block a user