Skip to content

Commit

Permalink
chore(linter): add filter parsing test cases
Browse files Browse the repository at this point in the history
I also deleted some commented-out-code I forgot to remove in a previous
PR
  • Loading branch information
DonIsaac committed Sep 26, 2024
1 parent efabfc8 commit a23c9a4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 78 deletions.
74 changes: 0 additions & 74 deletions crates/oxc_linter/src/config/oxlintrc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,78 +89,4 @@ impl Oxlintrc {

Ok(config)
}

// #[allow(clippy::option_if_let_else)]
// pub fn override_rules(
// &self,
// rules_for_override: &mut FxHashSet<RuleWithSeverity>,
// all_rules: &[RuleEnum],
// ) {
// use itertools::Itertools;
// let mut rules_to_replace: Vec<RuleWithSeverity> = vec![];
// let mut rules_to_remove: Vec<RuleWithSeverity> = 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);
// }
// }
}
10 changes: 6 additions & 4 deletions crates/oxc_linter/src/options/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit a23c9a4

Please sign in to comment.