From c22455cb9efe52d42d38922bcc309d43c50cab70 Mon Sep 17 00:00:00 2001 From: Lukas Stevens Date: Sun, 26 Nov 2017 18:36:12 +0100 Subject: [PATCH] Check for word beginning in stutter lint --- clippy_lints/src/enum_variants.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/clippy_lints/src/enum_variants.rs b/clippy_lints/src/enum_variants.rs index ea7a378de222..b3dd275f6684 100644 --- a/clippy_lints/src/enum_variants.rs +++ b/clippy_lints/src/enum_variants.rs @@ -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");