only lint public stutter namings

This commit is contained in:
Oliver Schneider 2016-06-10 16:14:36 +02:00
parent 8356d2fb21
commit 7253ce73bb
No known key found for this signature in database
GPG Key ID: 56D6EEA0FC67AC46

View File

@ -135,18 +135,20 @@ 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 !in_macro(cx, item.span) {
if let Some(mod_camel) = self.modules.last() {
// constants don't have surrounding modules
if !mod_camel.is_empty() {
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, ENUM_VARIANT_NAMES, item.span, &format!("Item name ({}) starts with its containing module's name ({})", item_camel, mod_camel));
}
if rmatching == nchars {
span_lint(cx, ENUM_VARIANT_NAMES, item.span, &format!("Item name ({}) ends with its containing module's name ({})", item_camel, mod_camel));
if item.vis == Visibility::Public {
if !in_macro(cx, item.span) {
if let Some(mod_camel) = self.modules.last() {
// constants don't have surrounding modules
if !mod_camel.is_empty() {
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, ENUM_VARIANT_NAMES, item.span, &format!("Item name ({}) starts with its containing module's name ({})", item_camel, mod_camel));
}
if rmatching == nchars {
span_lint(cx, ENUM_VARIANT_NAMES, item.span, &format!("Item name ({}) ends with its containing module's name ({})", item_camel, mod_camel));
}
}
}
}