Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,17 @@ fn prefer_object_from_entries_diagnostic(span: Span) -> OxcDiagnostic {
#[derive(Debug, Default, Clone)]
pub struct PreferObjectFromEntries(Box<PreferObjectFromEntriesConfig>);

#[derive(Debug, Default, Clone, Deserialize)]
#[derive(Debug, Clone, Deserialize)]
pub struct PreferObjectFromEntriesConfig {
functions: Vec<String>,
}

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;

Expand Down Expand Up @@ -227,17 +233,14 @@ 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| {
serde_json::from_value(config.clone()).expect("Failed to deserialize config")
})
.unwrap_or_default();

config.functions.push("_.fromPairs".into());
config.functions.push("lodash.fromPairs".into());

Self(Box::new(config))
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_linter/tests/rule_configuration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Loading