## Lints
-There are 179 lints included in this crate:
+There are 180 lints included in this crate:
name | default | triggers on
-----------------------------------------------------------------------------------------------------------------------|---------|----------------------------------------------------------------------------------------------------------------------------------
[print_stdout](https://github.com/Manishearth/rust-clippy/wiki#print_stdout) | allow | printing on stdout
[print_with_newline](https://github.com/Manishearth/rust-clippy/wiki#print_with_newline) | warn | using `print!()` with a format string that ends in a newline
[ptr_arg](https://github.com/Manishearth/rust-clippy/wiki#ptr_arg) | warn | fn arguments of the type `&Vec<...>` or `&String`, suggesting to use `&[...]` or `&str` instead, respectively
+[pub_enum_variant_names](https://github.com/Manishearth/rust-clippy/wiki#pub_enum_variant_names) | allow | enums where all variants share a prefix/postfix
[range_step_by_zero](https://github.com/Manishearth/rust-clippy/wiki#range_step_by_zero) | warn | using `Range::step_by(0)`, which produces an infinite iterator
[range_zip_with_len](https://github.com/Manishearth/rust-clippy/wiki#range_zip_with_len) | warn | zipping iterator with a range when `enumerate()` would do
[redundant_closure](https://github.com/Manishearth/rust-clippy/wiki#redundant_closure) | warn | redundant closures, i.e. `|a| foo(a)` (which can be written as just `foo`)
"enums where all variants share a prefix/postfix"
}
+/// **What it does:** Detects enumeration variants that are prefixed or suffixed
+/// by the same characters.
+///
+/// **Why is this bad?** Enumeration variant names should specify their variant,
+/// not repeat the enumeration name.
+///
+/// **Known problems:** None.
+///
+/// **Example:**
+/// ```rust
+/// enum Cake {
+/// BlackForestCake,
+/// HummingbirdCake,
+/// }
+/// ```
+declare_lint! {
+ pub PUB_ENUM_VARIANT_NAMES,
+ Allow,
+ "enums where all variants share a prefix/postfix"
+}
+
/// **What it does:** Detects type names that are prefixed or suffixed by the
/// containing module's name.
///
impl LintPass for EnumVariantNames {
fn get_lints(&self) -> LintArray {
- lint_array!(ENUM_VARIANT_NAMES, STUTTER, MODULE_INCEPTION)
+ lint_array!(ENUM_VARIANT_NAMES, PUB_ENUM_VARIANT_NAMES, STUTTER, MODULE_INCEPTION)
}
}
def: &EnumDef,
item_name: &str,
item_name_chars: usize,
- span: Span
+ span: Span,
+ lint: &'static Lint
) {
if (def.variants.len() as u64) < threshold {
return;
for var in &def.variants {
let name = var2str(var);
if partial_match(item_name, &name) == item_name_chars {
- span_lint(cx, ENUM_VARIANT_NAMES, var.span, "Variant name starts with the enum's name");
+ span_lint(cx, lint, var.span, "Variant name starts with the enum's name");
}
if partial_rmatch(item_name, &name) == item_name_chars {
- span_lint(cx, ENUM_VARIANT_NAMES, var.span, "Variant name ends with the enum's name");
+ span_lint(cx, lint, var.span, "Variant name ends with the enum's name");
}
}
let first = var2str(&def.variants[0]);
(true, false) => ("post", post),
};
span_help_and_lint(cx,
- ENUM_VARIANT_NAMES,
+ lint,
span,
&format!("All variants have the same {}fix: `{}`", what, value),
&format!("remove the {}fixes and use full paths to \
}
}
if let ItemKind::Enum(ref def, _) = item.node {
- check_variant(cx, self.threshold, def, &item_name, item_name_chars, item.span);
+ let lint = match item.vis {
+ Visibility::Public => PUB_ENUM_VARIANT_NAMES,
+ _ => ENUM_VARIANT_NAMES,
+ };
+ check_variant(cx, self.threshold, def, &item_name, item_name_chars, item.span, lint);
}
self.modules.push((item_name, item_camel));
}