diff --git a/crates/oxc_linter/src/rules/unicorn/prefer_object_from_entries.rs b/crates/oxc_linter/src/rules/unicorn/prefer_object_from_entries.rs index d64f990e6069f..2ad567828a779 100644 --- a/crates/oxc_linter/src/rules/unicorn/prefer_object_from_entries.rs +++ b/crates/oxc_linter/src/rules/unicorn/prefer_object_from_entries.rs @@ -24,11 +24,17 @@ fn prefer_object_from_entries_diagnostic(span: Span) -> OxcDiagnostic { #[derive(Debug, Default, Clone)] pub struct PreferObjectFromEntries(Box); -#[derive(Debug, Default, Clone, Deserialize)] +#[derive(Debug, Clone, Deserialize)] pub struct PreferObjectFromEntriesConfig { functions: Vec, } +impl Default for PreferObjectFromEntriesConfig { + fn default() -> Self { + Self { functions: vec!["_.fromPairs".to_string(), "lodash.fromPairs".to_string()] } + } +} + impl std::ops::Deref for PreferObjectFromEntries { type Target = PreferObjectFromEntriesConfig; @@ -227,7 +233,7 @@ impl Rule for PreferObjectFromEntries { } fn from_configuration(value: serde_json::Value) -> Self { - let mut config: PreferObjectFromEntriesConfig = value + let config: PreferObjectFromEntriesConfig = value .as_array() .and_then(|arr| arr.first()) .map(|config| { @@ -235,9 +241,6 @@ impl Rule for PreferObjectFromEntries { }) .unwrap_or_default(); - config.functions.push("_.fromPairs".into()); - config.functions.push("lodash.fromPairs".into()); - Self(Box::new(config)) } } diff --git a/crates/oxc_linter/tests/rule_configuration_test.rs b/crates/oxc_linter/tests/rule_configuration_test.rs index 9b3a90284d8aa..90547a57169ed 100644 --- a/crates/oxc_linter/tests/rule_configuration_test.rs +++ b/crates/oxc_linter/tests/rule_configuration_test.rs @@ -24,7 +24,7 @@ fn test_rule_default_matches_from_configuration_null() { // When fixing a rule, ensure that either: // 1. The Default implementation returns the same values as from_configuration(null), or // 2. The from_configuration method is updated to return Default::default() when given null - let exceptions = ["unicorn/prefer-object-from-entries", "unicorn/prefer-structured-clone"]; + let exceptions = ["unicorn/prefer-structured-clone"]; // Iterate through all available linter rules for rule in RULES.iter() {