Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't emit enum_variant_names if remainder starts with a numeric #4345

Merged
merged 1 commit into from
Aug 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions clippy_lints/src/enum_variants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ fn check_variant(
let name = var2str(var);
if partial_match(item_name, &name) == item_name_chars
&& name.chars().nth(item_name_chars).map_or(false, |c| !c.is_lowercase())
&& name.chars().nth(item_name_chars + 1).map_or(false, |c| !c.is_numeric())
{
span_lint(cx, lint, var.span, "Variant name starts with the enum's name");
}
Expand All @@ -178,6 +179,9 @@ fn check_variant(
let pre_camel = camel_case::until(pre);
pre = &pre[..pre_camel];
while let Some((next, last)) = name[pre.len()..].chars().zip(pre.chars().rev()).next() {
if next.is_numeric() {
return;
}
if next.is_lowercase() {
let last = pre.len() - last.len_utf8();
let last_camel = camel_case::until(&pre[..last]);
Expand Down
15 changes: 14 additions & 1 deletion tests/ui/enum_variants.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#![feature(non_ascii_idents)]
#![warn(clippy::all, clippy::pub_enum_variant_names)]
#![warn(clippy::enum_variant_names, clippy::pub_enum_variant_names)]
#![allow(non_camel_case_types)]

enum FakeCallType {
Expand Down Expand Up @@ -120,4 +120,17 @@ enum N {
Float,
}

// should not lint
enum Peek {
Peek1,
Peek2,
Peek3,
}

// should not lint
pub enum NetworkLayer {
Layer2,
Layer3,
}

fn main() {}