mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-23 21:23:56 +00:00
Merge pull request #2246 from lukasstevens/master
Check for word beginning in stutter lint
This commit is contained in:
commit
34da5d93ef
3 changed files with 20 additions and 1 deletions
|
@ -264,8 +264,17 @@ impl EarlyLintPass for EnumVariantNames {
|
|||
let matching = partial_match(mod_camel, &item_camel);
|
||||
let rmatching = partial_rmatch(mod_camel, &item_camel);
|
||||
let nchars = mod_camel.chars().count();
|
||||
|
||||
let is_word_beginning = |c: char| {
|
||||
c == '_' || c.is_uppercase() || c.is_numeric()
|
||||
};
|
||||
|
||||
if matching == nchars {
|
||||
span_lint(cx, STUTTER, item.span, "item name starts with its containing module's name");
|
||||
match item_camel.chars().nth(nchars) {
|
||||
Some(c) if is_word_beginning(c) =>
|
||||
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");
|
||||
|
|
|
@ -9,6 +9,10 @@ mod foo {
|
|||
pub fn bar_foo() {}
|
||||
pub struct FooCake {}
|
||||
pub enum CakeFoo {}
|
||||
pub struct Foo7Bar;
|
||||
|
||||
// Should not warn
|
||||
pub struct Foobar;
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
|
@ -24,3 +24,9 @@ error: item name ends with its containing module's name
|
|||
11 | pub enum CakeFoo {}
|
||||
| ^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: item name starts with its containing module's name
|
||||
--> $DIR/stutter.rs:12:5
|
||||
|
|
||||
12 | pub struct Foo7Bar;
|
||||
| ^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
|
|
Loading…
Reference in a new issue