From 1a6923a89185db29f8a290f09e3fa09ca1ced4fc Mon Sep 17 00:00:00 2001 From: DonIsaac <22823424+DonIsaac@users.noreply.github.com> Date: Thu, 26 Sep 2024 17:15:19 +0000 Subject: [PATCH] test(linter): add filter parsing test cases (#6080) I also deleted some commented-out-code I forgot to remove in a previous PR --- crates/oxc_linter/src/config/oxlintrc.rs | 74 ------------------------ crates/oxc_linter/src/options/filter.rs | 10 ++-- 2 files changed, 6 insertions(+), 78 deletions(-) diff --git a/crates/oxc_linter/src/config/oxlintrc.rs b/crates/oxc_linter/src/config/oxlintrc.rs index 86f58df27..100fb7ca6 100644 --- a/crates/oxc_linter/src/config/oxlintrc.rs +++ b/crates/oxc_linter/src/config/oxlintrc.rs @@ -89,78 +89,4 @@ impl Oxlintrc { Ok(config) } - - // #[allow(clippy::option_if_let_else)] - // pub fn override_rules( - // &self, - // rules_for_override: &mut FxHashSet, - // all_rules: &[RuleEnum], - // ) { - // use itertools::Itertools; - // let mut rules_to_replace: Vec = vec![]; - // let mut rules_to_remove: Vec = vec![]; - - // // Rules can have the same name but different plugin names - // let lookup = self.rules.iter().into_group_map_by(|r| r.rule_name.as_str()); - - // for (name, rule_configs) in &lookup { - // match rule_configs.len() { - // 0 => unreachable!(), - // 1 => { - // let rule_config = &rule_configs[0]; - // let (rule_name, plugin_name) = transform_rule_and_plugin_name( - // &rule_config.rule_name, - // &rule_config.plugin_name, - // ); - // let severity = rule_config.severity; - // match severity { - // AllowWarnDeny::Warn | AllowWarnDeny::Deny => { - // if let Some(rule) = all_rules - // .iter() - // .find(|r| r.name() == rule_name && r.plugin_name() == plugin_name) - // { - // let config = rule_config.config.clone().unwrap_or_default(); - // let rule = rule.read_json(config); - // rules_to_replace.push(RuleWithSeverity::new(rule, severity)); - // } - // } - // AllowWarnDeny::Allow => { - // if let Some(rule) = rules_for_override - // .iter() - // .find(|r| r.name() == rule_name && r.plugin_name() == plugin_name) - // { - // let rule = rule.clone(); - // rules_to_remove.push(rule); - // } - // } - // } - // } - // _ => { - // // For overlapping rule names, use the "error" one - // // "no-loss-of-precision": "off", - // // "@typescript-eslint/no-loss-of-precision": "error" - // if let Some(rule_config) = - // rule_configs.iter().find(|r| r.severity.is_warn_deny()) - // { - // if let Some(rule) = rules_for_override.iter().find(|r| r.name() == *name) { - // let config = rule_config.config.clone().unwrap_or_default(); - // rules_to_replace - // .push(RuleWithSeverity::new(rule.read_json(config), rule.severity)); - // } - // } else if rule_configs.iter().all(|r| r.severity.is_allow()) { - // if let Some(rule) = rules_for_override.iter().find(|r| r.name() == *name) { - // rules_to_remove.push(rule.clone()); - // } - // } - // } - // } - // } - - // for rule in rules_to_remove { - // rules_for_override.remove(&rule); - // } - // for rule in rules_to_replace { - // rules_for_override.replace(rule); - // } - // } } diff --git a/crates/oxc_linter/src/options/filter.rs b/crates/oxc_linter/src/options/filter.rs index 8ba6b80fd..b09f4df0a 100644 --- a/crates/oxc_linter/src/options/filter.rs +++ b/crates/oxc_linter/src/options/filter.rs @@ -245,17 +245,19 @@ mod test { #[test] fn test_parse() { + #[rustfmt::skip] let test_cases: Vec<(&'static str, LintFilterKind)> = vec![ + ("no-const-assign", LintFilterKind::Generic("no-const-assign".into())), + ("eslint/no-const-assign", LintFilterKind::Rule(LintPlugins::ESLINT, "no-const-assign".into())), ("import/namespace", LintFilterKind::Rule(LintPlugins::IMPORT, "namespace".into())), - ( - "react-hooks/exhaustive-deps", - LintFilterKind::Rule(LintPlugins::REACT, "exhaustive-deps".into()), - ), + ("react-hooks/exhaustive-deps", LintFilterKind::Rule(LintPlugins::REACT, "exhaustive-deps".into())), // categories + ("correctness", LintFilterKind::Category(RuleCategory::Correctness)), ("nursery", LintFilterKind::Category("nursery".try_into().unwrap())), ("perf", LintFilterKind::Category("perf".try_into().unwrap())), // misc ("not-a-valid-filter", LintFilterKind::Generic("not-a-valid-filter".into())), + ("all", LintFilterKind::Generic("all".into())), ]; for (input, expected) in test_cases {