also lint private modules for module_inception, as that is the main issue

This commit is contained in:
Oliver Schneider 2016-09-13 10:19:55 +02:00
parent 03fa974855
commit 12a82b2007
No known key found for this signature in database
GPG Key ID: 56D6EEA0FC67AC46
2 changed files with 17 additions and 19 deletions

View File

@ -194,21 +194,25 @@ impl EarlyLintPass for EnumVariantNames {
let item_name = item.ident.name.as_str();
let item_name_chars = item_name.chars().count();
let item_camel = to_camel_case(&item_name);
if item.vis == Visibility::Public && !in_macro(cx, item.span) {
if !in_macro(cx, item.span) {
if let Some(&(ref mod_name, ref mod_camel)) = self.modules.last() {
// constants don't have surrounding modules
if !mod_camel.is_empty() {
if mod_name == &item_name {
span_lint(cx, MODULE_INCEPTION, item.span, "item has the same name as its containing module");
if let ItemKind::Mod(..) = item.node {
span_lint(cx, MODULE_INCEPTION, item.span, "module has the same name as its containing module");
}
}
let matching = partial_match(mod_camel, &item_camel);
let rmatching = partial_rmatch(mod_camel, &item_camel);
let nchars = mod_camel.chars().count();
if matching == nchars {
span_lint(cx, STUTTER, item.span, &format!("Item name ({}) starts with its containing module's name ({})", item_camel, mod_camel));
}
if rmatching == nchars {
span_lint(cx, STUTTER, item.span, &format!("Item name ({}) ends with its containing module's name ({})", item_camel, mod_camel));
if item.vis == Visibility::Public {
let matching = partial_match(mod_camel, &item_camel);
let rmatching = partial_rmatch(mod_camel, &item_camel);
let nchars = mod_camel.chars().count();
if matching == nchars {
span_lint(cx, STUTTER, item.span, "item name starts with its containing module's name");
}
if rmatching == nchars {
span_lint(cx, STUTTER, item.span, "item name ends with its containing module's name");
}
}
}
}

View File

@ -4,26 +4,20 @@
mod foo {
mod bar {
pub mod bar { //~ ERROR item has the same name as its containing module
mod bar { //~ ERROR module has the same name as its containing module
mod foo {}
}
mod foo {}
}
pub mod foo { //~ ERROR item has the same name as its containing module
mod foo { //~ ERROR module has the same name as its containing module
mod bar {}
}
}
mod cake {
mod cake {
// no error, since module is not public
}
}
// No warning. See <https://github.com/Manishearth/rust-clippy/issues/1220>.
mod bar {
#[allow(module_inception)]
pub mod bar {
mod bar {
}
}