mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 12:19:15 +00:00
fix(linter): allow replacing rule when none are enabled yet (#7014)
fixes https://github.com/oxc-project/oxc/issues/7009 allows rules to be replaced properly when the `rules_for_override` array is empty (e.g., if you initially disable all rules, then configure them) by checking the `all_rules` array if the first `find` call fails
This commit is contained in:
parent
4b3e1223fe
commit
147e2e4858
1 changed files with 21 additions and 11 deletions
|
|
@ -112,11 +112,20 @@ impl OxlintRules {
|
|||
if let Some(rule_config) =
|
||||
rule_configs.iter().find(|r| r.severity.is_warn_deny())
|
||||
{
|
||||
let config = rule_config.config.clone().unwrap_or_default();
|
||||
|
||||
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));
|
||||
}
|
||||
// If the given rule is not found in the rule list (for example, if all rules are disabled),
|
||||
// then look it up in the entire rules list and add it.
|
||||
else if let Some(rule) = all_rules.iter().find(|r| r.name() == *name) {
|
||||
rules_to_replace.push(RuleWithSeverity::new(
|
||||
rule.read_json(config),
|
||||
rule_config.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());
|
||||
|
|
@ -437,28 +446,29 @@ mod test {
|
|||
#[test]
|
||||
fn test_override_plugin_prefix_duplicates() {
|
||||
let configs = [
|
||||
// FIXME: this should be valid
|
||||
// json!({ "@typescript-eslint/no-unused-vars": "error" }),
|
||||
json!({ "no-unused-vars": "off", "typescript/no-unused-vars": "error" }),
|
||||
json!({ "no-unused-vars": "off", "@typescript-eslint/no-unused-vars": "error" }),
|
||||
];
|
||||
|
||||
for config in configs {
|
||||
for config in &configs {
|
||||
let mut rules = RuleSet::default();
|
||||
r#override(&mut rules, &config);
|
||||
r#override(&mut rules, config);
|
||||
|
||||
// FIXME: this fails, meaning the behavior with two rules (in different plugins) does
|
||||
// not match the behavior of a single rule in a oxlintrc.
|
||||
// assert_eq!(rules.len(), 1, "{config:?}");
|
||||
// let rule = rules.iter().next().unwrap();
|
||||
// assert_eq!(rule.name(), "no-unused-vars", "{config:?}");
|
||||
// assert_eq!(rule.severity, AllowWarnDeny::Deny, "{config:?}");
|
||||
assert_eq!(rules.len(), 1, "{config:?}");
|
||||
let rule = rules.iter().next().unwrap();
|
||||
assert_eq!(rule.name(), "no-unused-vars", "{config:?}");
|
||||
assert_eq!(rule.severity, AllowWarnDeny::Deny, "{config:?}");
|
||||
}
|
||||
|
||||
// rules = RuleSet::default();
|
||||
for config in &configs {
|
||||
let mut rules = RuleSet::default();
|
||||
rules.insert(RuleWithSeverity {
|
||||
rule: RuleEnum::NoUnusedVars(Default::default()),
|
||||
severity: AllowWarnDeny::Warn,
|
||||
});
|
||||
r#override(&mut rules, &config);
|
||||
r#override(&mut rules, config);
|
||||
|
||||
assert_eq!(rules.len(), 1, "{config:?}");
|
||||
let rule = rules.iter().next().unwrap();
|
||||
|
|
|
|||
Loading…
Reference in a new issue