From e628e4d513ac9d85e7dd98740ec107b4d103bb27 Mon Sep 17 00:00:00 2001 From: Oliver 'ker' Schneider Date: Thu, 16 Jun 2016 18:37:56 +0200 Subject: [PATCH] allow by default --- CHANGELOG.md | 1 + README.md | 3 ++- clippy_lints/src/enum_variants.rs | 18 +++++++++++++++--- clippy_lints/src/lib.rs | 1 + 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 790bbc04691..3c2f9e1a622 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -240,6 +240,7 @@ All notable changes to this project will be documented in this file. [`string_add_assign`]: https://github.com/Manishearth/rust-clippy/wiki#string_add_assign [`string_lit_as_bytes`]: https://github.com/Manishearth/rust-clippy/wiki#string_lit_as_bytes [`string_to_string`]: https://github.com/Manishearth/rust-clippy/wiki#string_to_string +[`stutter`]: https://github.com/Manishearth/rust-clippy/wiki#stutter [`suspicious_assignment_formatting`]: https://github.com/Manishearth/rust-clippy/wiki#suspicious_assignment_formatting [`suspicious_else_formatting`]: https://github.com/Manishearth/rust-clippy/wiki#suspicious_else_formatting [`temporary_assignment`]: https://github.com/Manishearth/rust-clippy/wiki#temporary_assignment diff --git a/README.md b/README.md index 85e9ed70bf8..a8e8cbb3a5a 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ Table of contents: ## Lints -There are 153 lints included in this crate: +There are 154 lints included in this crate: name | default | meaning ---------------------------------------------------------------------------------------------------------------------|---------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ @@ -144,6 +144,7 @@ name [string_add](https://github.com/Manishearth/rust-clippy/wiki#string_add) | allow | using `x + ..` where x is a `String`; suggests using `push_str()` instead [string_add_assign](https://github.com/Manishearth/rust-clippy/wiki#string_add_assign) | allow | using `x = x + ..` where x is a `String`; suggests using `push_str()` instead [string_lit_as_bytes](https://github.com/Manishearth/rust-clippy/wiki#string_lit_as_bytes) | warn | calling `as_bytes` on a string literal; suggests using a byte string literal instead +[stutter](https://github.com/Manishearth/rust-clippy/wiki#stutter) | allow | finds type names prefixed/postfixed with their containing module's name [suspicious_assignment_formatting](https://github.com/Manishearth/rust-clippy/wiki#suspicious_assignment_formatting) | warn | suspicious formatting of `*=`, `-=` or `!=` [suspicious_else_formatting](https://github.com/Manishearth/rust-clippy/wiki#suspicious_else_formatting) | warn | suspicious formatting of `else if` [temporary_assignment](https://github.com/Manishearth/rust-clippy/wiki#temporary_assignment) | warn | assignments to temporaries diff --git a/clippy_lints/src/enum_variants.rs b/clippy_lints/src/enum_variants.rs index 8905870f1d8..4bf65ec4297 100644 --- a/clippy_lints/src/enum_variants.rs +++ b/clippy_lints/src/enum_variants.rs @@ -19,6 +19,18 @@ "finds enums where all variants share a prefix/postfix" } +/// **What it does:** Warns on type names that are prefixed or suffixed by the containing module's name +/// +/// **Why is this bad?** It requires the user to type the module name twice +/// +/// **Known problems:** None +/// +/// **Example:** mod cake { struct BlackForestCake; } +declare_lint! { + pub STUTTER, Allow, + "finds type names prefixed/postfixed with their containing module's name" +} + #[derive(Default)] pub struct EnumVariantNames { modules: Vec, @@ -26,7 +38,7 @@ pub struct EnumVariantNames { impl LintPass for EnumVariantNames { fn get_lints(&self) -> LintArray { - lint_array!(ENUM_VARIANT_NAMES) + lint_array!(ENUM_VARIANT_NAMES, STUTTER) } } @@ -143,10 +155,10 @@ fn check_item(&mut self, cx: &EarlyContext, item: &Item) { 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)); + span_lint(cx, STUTTER, 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)); + span_lint(cx, STUTTER, item.span, &format!("Item name ({}) ends with its containing module's name ({})", item_camel, mod_camel)); } } } diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index 32dd274ba6d..b68596f2535 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -263,6 +263,7 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry) { array_indexing::INDEXING_SLICING, booleans::NONMINIMAL_BOOL, enum_glob_use::ENUM_GLOB_USE, + enum_variants::STUTTER, if_not_else::IF_NOT_ELSE, items_after_statements::ITEMS_AFTER_STATEMENTS, matches::SINGLE_MATCH_ELSE, -- 2.44.0