feat(linter): warn unmatched rule names (#6782)

Fixes https://github.com/oxc-project/oxc/issues/6763
This commit is contained in:
Tapan Prakash 2024-10-23 21:35:01 +05:30 committed by GitHub
parent fdd69e4b3f
commit 2aa763c803
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -59,11 +59,12 @@ impl IntoIterator for OxlintRules {
}
impl OxlintRules {
#[allow(clippy::option_if_let_else)]
#[allow(clippy::option_if_let_else, clippy::print_stdout)]
pub(crate) fn override_rules(&self, rules_for_override: &mut RuleSet, all_rules: &[RuleEnum]) {
use itertools::Itertools;
let mut rules_to_replace: Vec<RuleWithSeverity> = vec![];
let mut rules_to_remove: Vec<RuleWithSeverity> = vec![];
let mut rules_not_matched: Vec<&str> = vec![];
// Rules can have the same name but different plugin names
let lookup = self.iter().into_group_map_by(|r| r.rule_name.as_str());
@ -87,6 +88,8 @@ impl OxlintRules {
let config = rule_config.config.clone().unwrap_or_default();
let rule = rule.read_json(config);
rules_to_replace.push(RuleWithSeverity::new(rule, severity));
} else {
rules_not_matched.push(rule_name);
}
}
AllowWarnDeny::Allow => {
@ -96,6 +99,8 @@ impl OxlintRules {
{
let rule = rule.clone();
rules_to_remove.push(rule);
} else {
rules_not_matched.push(rule_name);
}
}
}
@ -127,6 +132,13 @@ impl OxlintRules {
for rule in rules_to_replace {
rules_for_override.replace(rule);
}
if !rules_not_matched.is_empty() {
println!("The following rules do not match the currently supported rules:");
for rule in rules_not_matched {
println!("{rule}");
}
}
}
}