diff --git a/crates/oxc_cli/src/lint/mod.rs b/crates/oxc_cli/src/lint/mod.rs index 0970859bf..e00b95b2f 100644 --- a/crates/oxc_cli/src/lint/mod.rs +++ b/crates/oxc_cli/src/lint/mod.rs @@ -308,7 +308,13 @@ mod test { #[test] fn eslintrc_no_undef() { - let args = &["-c", "fixtures/no_undef/eslintrc.json", "fixtures/no_undef/test.js"]; + let args = &[ + "-D", + "no-undef", + "-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); @@ -317,8 +323,13 @@ mod test { #[test] fn eslintrc_no_env() { - let args = - &["-c", "fixtures/eslintrc_env/eslintrc_no_env.json", "fixtures/eslintrc_env/test.js"]; + let args = &[ + "-D", + "no-undef", + "-c", + "fixtures/eslintrc_env/eslintrc_no_env.json", + "fixtures/eslintrc_env/test.js", + ]; let result = test(args); assert_eq!(result.number_of_files, 1); assert_eq!(result.number_of_warnings, 1); diff --git a/crates/oxc_linter/src/options.rs b/crates/oxc_linter/src/options.rs index 0ed1732a3..731eb0663 100644 --- a/crates/oxc_linter/src/options.rs +++ b/crates/oxc_linter/src/options.rs @@ -192,7 +192,7 @@ impl LintOptions { rules.extend(all_rules.iter().cloned()); } else { rules.extend( - all_rules + RULES .iter() .filter(|rule| rule.name() == name_or_category) .cloned(), @@ -228,23 +228,25 @@ impl LintOptions { Ok((rules, config.unwrap_or_default())) } - // get final filtered rules by reading `self.xxx_plugin` + /// Get final filtered rules by reading `self.xxx_plugin` fn get_filtered_rules(&self) -> Vec { - let mut rules = RULES.clone(); - - let mut may_exclude_plugin_rules = |yes: bool, name: &str| { - if !yes { - rules.retain(|rule| rule.plugin_name() != name); - } - }; - - may_exclude_plugin_rules(self.import_plugin, IMPORT_PLUGIN_NAME); - may_exclude_plugin_rules(self.jsdoc_plugin, JSDOC_PLUGIN_NAME); - may_exclude_plugin_rules(self.jest_plugin, JEST_PLUGIN_NAME); - may_exclude_plugin_rules(self.jsx_a11y_plugin, JSX_A11Y_PLUGIN_NAME); - may_exclude_plugin_rules(self.nextjs_plugin, NEXTJS_PLUGIN_NAME); - may_exclude_plugin_rules(self.react_perf_plugin, REACT_PERF_PLUGIN_NAME); - - rules + RULES + .iter() + .filter(|rule| { + if rule.category() == RuleCategory::Nursery { + return false; + } + match rule.plugin_name() { + IMPORT_PLUGIN_NAME if !self.import_plugin => false, + JSDOC_PLUGIN_NAME if !self.jsdoc_plugin => false, + JEST_PLUGIN_NAME if !self.jest_plugin => false, + JSX_A11Y_PLUGIN_NAME if !self.jsx_a11y_plugin => false, + NEXTJS_PLUGIN_NAME if !self.nextjs_plugin => false, + REACT_PERF_PLUGIN_NAME if !self.react_perf_plugin => false, + _ => true, + } + }) + .cloned() + .collect::>() } }