Skip to content

Commit

Permalink
split item_name_threshold to avoid deprecation
Browse files Browse the repository at this point in the history
  • Loading branch information
jonboh committed Oct 8, 2023
1 parent 1c891ea commit f645bd8
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 14 deletions.
17 changes: 12 additions & 5 deletions clippy_lints/src/item_name_repetitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,17 +142,24 @@ declare_clippy_lint! {

pub struct ItemNameRepetitions {
modules: Vec<(Symbol, String, OwnerId)>,
threshold: u64,
enum_threshold: u64,
struct_threshold: u64,
avoid_breaking_exported_api: bool,
allow_private_module_inception: bool,
}

impl ItemNameRepetitions {
#[must_use]
pub fn new(threshold: u64, avoid_breaking_exported_api: bool, allow_private_module_inception: bool) -> Self {
pub fn new(
enum_threshold: u64,
struct_threshold: u64,
avoid_breaking_exported_api: bool,
allow_private_module_inception: bool,
) -> Self {
Self {
modules: Vec::new(),
threshold,
enum_threshold,
struct_threshold,
avoid_breaking_exported_api,
allow_private_module_inception,
}
Expand Down Expand Up @@ -425,9 +432,9 @@ impl LateLintPass<'_> for ItemNameRepetitions {
&& span_is_local(item.span)
{
match item.kind {
ItemKind::Enum(def, _) => check_variant(cx, self.threshold, &def, item_name, item.span),
ItemKind::Enum(def, _) => check_variant(cx, self.enum_threshold, &def, item_name, item.span),
ItemKind::Struct(VariantData::Struct(fields, _), _) => {
check_fields(cx, self.threshold, item, fields);
check_fields(cx, self.struct_threshold, item, fields);
},
_ => (),
}
Expand Down
6 changes: 4 additions & 2 deletions clippy_lints/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -849,11 +849,13 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
literal_representation_threshold,
))
});
let item_name_threshold = conf.item_name_threshold;
let enum_variant_name_threshold = conf.enum_variant_name_threshold;
let struct_field_name_threshold = conf.struct_field_name_threshold;
let allow_private_module_inception = conf.allow_private_module_inception;
store.register_late_pass(move |_| {
Box::new(item_name_repetitions::ItemNameRepetitions::new(
item_name_threshold,
enum_variant_name_threshold,
struct_field_name_threshold,
avoid_breaking_exported_api,
allow_private_module_inception,
))
Expand Down
10 changes: 7 additions & 3 deletions clippy_lints/src/utils/conf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,10 +356,14 @@ define_Conf! {
///
/// The maximum size of objects (in bytes) that will be linted. Larger objects are ok on the heap
(too_large_for_stack: u64 = 200),
/// Lint: ENUM_VARIANT_NAMES, STRUCT_FIELD_NAMES.
/// Lint: ENUM_VARIANT_NAMES.
///
/// The minimum number of enum variants or struct fields for the lints about variant and field names to trigger
(item_name_threshold: u64 = 3),
/// The minimum number of enum variants for the lints about variant names to trigger
(enum_variant_name_threshold: u64 = 3),
/// Lint: STRUCT_VARIANT_NAMES.
///
/// The minimum number of struct fields for the lints about field names to trigger
(struct_field_name_threshold: u64 = 3),
/// Lint: LARGE_ENUM_VARIANT.
///
/// The maximum size of an enum's variant to avoid box suggestion
Expand Down
2 changes: 1 addition & 1 deletion tests/ui-toml/item_name_repetitions/threshold0/clippy.toml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
item-name-threshold = 0
struct-field-name-threshold = 0
3 changes: 2 additions & 1 deletion tests/ui-toml/item_name_repetitions/threshold5/clippy.toml
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
item-name-threshold = 5
enum-variant-name-threshold = 5
struct-field-name-threshold = 5
6 changes: 4 additions & 2 deletions tests/ui-toml/toml_unknown_key/conf_unknown_key.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ error: error reading Clippy's configuration file: unknown field `foobar`, expect
enable-raw-pointer-heuristic-for-send
enforce-iter-loop-reborrow
enforced-import-renames
enum-variant-name-threshold
enum-variant-size-threshold
excessive-nesting-threshold
future-size-threshold
ignore-interior-mutability
item-name-threshold
large-error-threshold
literal-representation-threshold
matches-for-let-else
Expand All @@ -53,6 +53,7 @@ error: error reading Clippy's configuration file: unknown field `foobar`, expect
single-char-binding-names-threshold
stack-size-threshold
standard-macro-braces
struct-field-name-threshold
suppress-restriction-lint-in-const
third-party
too-large-for-stack
Expand Down Expand Up @@ -104,11 +105,11 @@ error: error reading Clippy's configuration file: unknown field `barfoo`, expect
enable-raw-pointer-heuristic-for-send
enforce-iter-loop-reborrow
enforced-import-renames
enum-variant-name-threshold
enum-variant-size-threshold
excessive-nesting-threshold
future-size-threshold
ignore-interior-mutability
item-name-threshold
large-error-threshold
literal-representation-threshold
matches-for-let-else
Expand All @@ -126,6 +127,7 @@ error: error reading Clippy's configuration file: unknown field `barfoo`, expect
single-char-binding-names-threshold
stack-size-threshold
standard-macro-braces
struct-field-name-threshold
suppress-restriction-lint-in-const
third-party
too-large-for-stack
Expand Down

0 comments on commit f645bd8

Please sign in to comment.