lint modules that have the same name as their parent module
This commit is contained in:
parent
e12f14f676
commit
7ee4a9a659
5 changed files with 69 additions and 1 deletions
|
|
@ -96,6 +96,7 @@ pub mod methods;
|
|||
pub mod minmax;
|
||||
pub mod misc;
|
||||
pub mod misc_early;
|
||||
pub mod module_inception;
|
||||
pub mod mut_mut;
|
||||
pub mod mut_reference;
|
||||
pub mod mutex_atomic;
|
||||
|
|
@ -173,6 +174,7 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry) {
|
|||
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_early_lint_pass(box module_inception::Pass);
|
||||
reg.register_late_lint_pass(box misc::TopLevelRefPass);
|
||||
reg.register_late_lint_pass(box misc::CmpNan);
|
||||
reg.register_late_lint_pass(box eq_op::EqOp);
|
||||
|
|
@ -384,6 +386,7 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry) {
|
|||
misc_early::MIXED_CASE_HEX_LITERALS,
|
||||
misc_early::REDUNDANT_CLOSURE_CALL,
|
||||
misc_early::UNNEEDED_FIELD_PATTERN,
|
||||
module_inception::MODULE_INCEPTION,
|
||||
mut_reference::UNNECESSARY_MUT_PASSED,
|
||||
mutex_atomic::MUTEX_ATOMIC,
|
||||
needless_bool::BOOL_COMPARISON,
|
||||
|
|
|
|||
47
clippy_lints/src/module_inception.rs
Normal file
47
clippy_lints/src/module_inception.rs
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
use rustc::lint::*;
|
||||
use syntax::ast::*;
|
||||
use utils::span_lint;
|
||||
|
||||
/// **What it does:** Checks for modules that have the same name as their parent module
|
||||
///
|
||||
/// **Why is this bad?** A typical beginner mistake is to have `mod foo;` and again `mod foo { .. }` in `foo.rs`
|
||||
///
|
||||
/// **Known problems:** None.
|
||||
///
|
||||
/// **Example:**
|
||||
/// ```rust
|
||||
/// // lib.rs
|
||||
/// mod foo;
|
||||
/// // foo.rs
|
||||
/// mod foo {
|
||||
/// ...
|
||||
/// }
|
||||
/// ```
|
||||
declare_lint! {
|
||||
pub MODULE_INCEPTION,
|
||||
Warn,
|
||||
"modules that have the same name as their parent module"
|
||||
}
|
||||
|
||||
pub struct Pass;
|
||||
|
||||
impl LintPass for Pass {
|
||||
fn get_lints(&self) -> LintArray {
|
||||
lint_array![MODULE_INCEPTION]
|
||||
}
|
||||
}
|
||||
|
||||
impl EarlyLintPass for Pass {
|
||||
fn check_item(&mut self, cx: &EarlyContext, item: &Item) {
|
||||
if let ItemKind::Mod(ref module) = item.node {
|
||||
for sub_item in &module.items {
|
||||
if let ItemKind::Mod(_) = sub_item.node {
|
||||
if item.ident == sub_item.ident {
|
||||
span_lint(cx, MODULE_INCEPTION, sub_item.span,
|
||||
"module has the same name as its containing module");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue