also lint private modules for module_inception, as that is the main issue
This commit is contained in:
@@ -194,21 +194,25 @@ impl EarlyLintPass for EnumVariantNames {
|
|||||||
let item_name = item.ident.name.as_str();
|
let item_name = item.ident.name.as_str();
|
||||||
let item_name_chars = item_name.chars().count();
|
let item_name_chars = item_name.chars().count();
|
||||||
let item_camel = to_camel_case(&item_name);
|
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() {
|
if let Some(&(ref mod_name, ref mod_camel)) = self.modules.last() {
|
||||||
// constants don't have surrounding modules
|
// constants don't have surrounding modules
|
||||||
if !mod_camel.is_empty() {
|
if !mod_camel.is_empty() {
|
||||||
if mod_name == &item_name {
|
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");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if item.vis == Visibility::Public {
|
||||||
let matching = partial_match(mod_camel, &item_camel);
|
let matching = partial_match(mod_camel, &item_camel);
|
||||||
let rmatching = partial_rmatch(mod_camel, &item_camel);
|
let rmatching = partial_rmatch(mod_camel, &item_camel);
|
||||||
let nchars = mod_camel.chars().count();
|
let nchars = mod_camel.chars().count();
|
||||||
if matching == nchars {
|
if matching == nchars {
|
||||||
span_lint(cx, STUTTER, item.span, &format!("Item name ({}) starts with its containing module's name ({})", item_camel, mod_camel));
|
span_lint(cx, STUTTER, item.span, "item name starts with its containing module's name");
|
||||||
}
|
}
|
||||||
if rmatching == nchars {
|
if rmatching == nchars {
|
||||||
span_lint(cx, STUTTER, item.span, &format!("Item name ({}) ends with its containing module's name ({})", item_camel, mod_camel));
|
span_lint(cx, STUTTER, item.span, "item name ends with its containing module's name");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,26 +4,20 @@
|
|||||||
|
|
||||||
mod foo {
|
mod foo {
|
||||||
mod bar {
|
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 {}
|
||||||
}
|
}
|
||||||
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 bar {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mod cake {
|
|
||||||
mod cake {
|
|
||||||
// no error, since module is not public
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// No warning. See <https://github.com/Manishearth/rust-clippy/issues/1220>.
|
// No warning. See <https://github.com/Manishearth/rust-clippy/issues/1220>.
|
||||||
mod bar {
|
mod bar {
|
||||||
#[allow(module_inception)]
|
#[allow(module_inception)]
|
||||||
pub mod bar {
|
mod bar {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user