diff --git a/crates/oxc_linter/src/config/config_builder.rs b/crates/oxc_linter/src/config/config_builder.rs index ece65cba25884..bfdde8bf3a46c 100644 --- a/crates/oxc_linter/src/config/config_builder.rs +++ b/crates/oxc_linter/src/config/config_builder.rs @@ -137,7 +137,7 @@ impl ConfigStoreBuilder { let (extends, extends_paths) = resolve_oxlintrc_config(extends_oxlintrc)?; - oxlintrc = oxlintrc.merge(&extends); + oxlintrc = oxlintrc.merge(extends); extended_paths.extend(extends_paths); } diff --git a/crates/oxc_linter/src/config/oxlintrc.rs b/crates/oxc_linter/src/config/oxlintrc.rs index ba6f631a220b9..695a53f28e6f8 100644 --- a/crates/oxc_linter/src/config/oxlintrc.rs +++ b/crates/oxc_linter/src/config/oxlintrc.rs @@ -215,11 +215,18 @@ impl Oxlintrc { serde_json::to_string_pretty(&schema).unwrap() } - /// Merges two [Oxlintrc] files together - /// [Self] takes priority over `other` + /// Merges two [Oxlintrc] files together. + /// + /// [Self] takes priority over `other` - if both configs define the same property, + /// the value from [Self] wins. + /// + /// For example, if `self` has `{ "rules": { "no-console": "error" } }` and `other` has + /// `{ "rules": { "no-console": "warn", "no-debugger": "error" } }`, the result will be + /// `{ "rules": { "no-console": "error", "no-debugger": "error" } }` (self's `"no-console"` + /// setting wins). #[must_use] - pub fn merge(&self, other: &Oxlintrc) -> Oxlintrc { - let mut categories = other.categories.clone(); + pub fn merge(&self, other: Oxlintrc) -> Oxlintrc { + let mut categories = other.categories; categories.extend(self.categories.iter()); let rules = self @@ -242,7 +249,7 @@ impl Oxlintrc { let env = self.env.clone(); let globals = self.globals.clone(); - let mut overrides = other.overrides.clone(); + let mut overrides = other.overrides; overrides.extend(self.overrides.clone()); let plugins = match (self.plugins, other.plugins) {