diff --git a/crates/oxc_cli/fixtures/no_undef/eslintrc.json b/crates/oxc_cli/fixtures/no_undef/eslintrc.json new file mode 100644 index 0000000000000..f646b22826a2d --- /dev/null +++ b/crates/oxc_cli/fixtures/no_undef/eslintrc.json @@ -0,0 +1,5 @@ +{ + "rules": { + "no-undef": "warn" + } +} diff --git a/crates/oxc_cli/fixtures/no_undef/test.js b/crates/oxc_cli/fixtures/no_undef/test.js new file mode 100644 index 0000000000000..0f4e35a4a0c5e --- /dev/null +++ b/crates/oxc_cli/fixtures/no_undef/test.js @@ -0,0 +1 @@ +console.log() diff --git a/crates/oxc_cli/src/lint/mod.rs b/crates/oxc_cli/src/lint/mod.rs index fa85fe16e4927..fd5a2acb1a471 100644 --- a/crates/oxc_cli/src/lint/mod.rs +++ b/crates/oxc_cli/src/lint/mod.rs @@ -324,6 +324,15 @@ mod test { assert_eq!(result.number_of_errors, 0); } + #[test] + fn eslintrc_no_undef() { + let args = &["-c", "fixtures/no_undef/eslintrc.json", "fixtures/no_undef/test.js"]; + let result = test(args); + assert_eq!(result.number_of_files, 1); + assert_eq!(result.number_of_warnings, 1); + assert_eq!(result.number_of_errors, 0); + } + #[test] fn no_empty_allow_empty_catch() { let args = &[ diff --git a/crates/oxc_linter/src/config/mod.rs b/crates/oxc_linter/src/config/mod.rs index 306fcce1f543f..e347d183fdac6 100644 --- a/crates/oxc_linter/src/config/mod.rs +++ b/crates/oxc_linter/src/config/mod.rs @@ -68,14 +68,20 @@ impl ESLintConfig { }) } - pub fn override_rules(&self, rules_to_override: &mut FxHashSet) { + pub fn override_rules( + &self, + rules_to_override: &mut FxHashSet, + all_rules: &[RuleEnum], + ) { let mut rules_to_replace = vec![]; let mut rules_to_remove = vec![]; - for rule in rules_to_override.iter() { - let plugin_name = rule.plugin_name(); - let rule_name = rule.name(); - if let Some(rule_to_configure) = - self.rules.iter().find(|r| r.plugin_name == plugin_name && r.rule_name == rule_name) + + for rule_to_configure in &self.rules { + let (plugin_name, rule_name) = + (&rule_to_configure.plugin_name, &rule_to_configure.rule_name); + if let Some(rule) = rules_to_override + .iter() + .find(|r| r.plugin_name() == plugin_name && r.name() == rule_name) { match rule_to_configure.severity { AllowWarnDeny::Warn | AllowWarnDeny::Deny => { @@ -85,8 +91,13 @@ impl ESLintConfig { rules_to_remove.push(rule.clone()); } } + } else if let Some(rule) = + all_rules.iter().find(|r| r.plugin_name() == plugin_name && r.name() == rule_name) + { + rules_to_replace.push(rule.read_json(rule_to_configure.config.clone())); } } + for rule in rules_to_remove { rules_to_override.remove(&rule); } diff --git a/crates/oxc_linter/src/options.rs b/crates/oxc_linter/src/options.rs index 312de4c9bc32f..53465459cba85 100644 --- a/crates/oxc_linter/src/options.rs +++ b/crates/oxc_linter/src/options.rs @@ -199,7 +199,7 @@ impl LintOptions { } if let Some(config) = &config { - config.override_rules(&mut rules); + config.override_rules(&mut rules, &all_rules); } let mut rules = rules.into_iter().collect::>();