Skip to content

Commit f27e2f8

Browse files
committed
fix(linter/unicorn/prefer-object-from-entries): update Default implementation for PreferObjectFromEntriesConfig
1 parent 9625434 commit f27e2f8

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

crates/oxc_linter/src/rules/unicorn/prefer_object_from_entries.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,17 @@ fn prefer_object_from_entries_diagnostic(span: Span) -> OxcDiagnostic {
2424
#[derive(Debug, Default, Clone)]
2525
pub struct PreferObjectFromEntries(Box<PreferObjectFromEntriesConfig>);
2626

27-
#[derive(Debug, Default, Clone, Deserialize)]
27+
#[derive(Debug, Clone, Deserialize)]
2828
pub struct PreferObjectFromEntriesConfig {
2929
functions: Vec<String>,
3030
}
3131

32+
impl Default for PreferObjectFromEntriesConfig {
33+
fn default() -> Self {
34+
Self { functions: vec!["_.fromPairs".to_string(), "lodash.fromPairs".to_string()] }
35+
}
36+
}
37+
3238
impl std::ops::Deref for PreferObjectFromEntries {
3339
type Target = PreferObjectFromEntriesConfig;
3440

@@ -227,17 +233,14 @@ impl Rule for PreferObjectFromEntries {
227233
}
228234

229235
fn from_configuration(value: serde_json::Value) -> Self {
230-
let mut config: PreferObjectFromEntriesConfig = value
236+
let config: PreferObjectFromEntriesConfig = value
231237
.as_array()
232238
.and_then(|arr| arr.first())
233239
.map(|config| {
234240
serde_json::from_value(config.clone()).expect("Failed to deserialize config")
235241
})
236242
.unwrap_or_default();
237243

238-
config.functions.push("_.fromPairs".into());
239-
config.functions.push("lodash.fromPairs".into());
240-
241244
Self(Box::new(config))
242245
}
243246
}

crates/oxc_linter/tests/rule_configuration_test.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,7 @@ fn test_rule_default_matches_from_configuration_null() {
2424
// When fixing a rule, ensure that either:
2525
// 1. The Default implementation returns the same values as from_configuration(null), or
2626
// 2. The from_configuration method is updated to return Default::default() when given null
27-
let exceptions = [
28-
"unicorn/prefer-object-from-entries",
29-
"unicorn/prefer-structured-clone",
30-
];
27+
let exceptions = ["unicorn/prefer-structured-clone"];
3128

3229
// Iterate through all available linter rules
3330
for rule in RULES.iter() {

0 commit comments

Comments
 (0)