mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 12:21:58 +00:00
fix(linter): can't disable no-nested-ternary rule anymore (#8600)
closes #8485 Since we currently support two rules with the same `rule_name` but different `plugin_names`, some of the original logic is no longer applicable. As a result, I have made some adjustments.
This commit is contained in:
parent
e929f26826
commit
8ce21d1d48
5 changed files with 72 additions and 32 deletions
10
apps/oxlint/fixtures/two_rules_with_same_name/.oxlintrc.json
Normal file
10
apps/oxlint/fixtures/two_rules_with_same_name/.oxlintrc.json
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
{
|
||||||
|
"plugins": [
|
||||||
|
"oxc",
|
||||||
|
"unicorn"
|
||||||
|
],
|
||||||
|
"rules": {
|
||||||
|
"eslint/no-nested-ternary": "off",
|
||||||
|
"unicorn/no-nested-ternary": "off"
|
||||||
|
}
|
||||||
|
}
|
||||||
1
apps/oxlint/fixtures/two_rules_with_same_name/test.js
Normal file
1
apps/oxlint/fixtures/two_rules_with_same_name/test.js
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
console.log(bar ? baz : qux === quxx ? bing : bam);
|
||||||
|
|
@ -824,6 +824,13 @@ mod test {
|
||||||
.test_and_snapshot_multiple(&[args_1, args_2]);
|
.test_and_snapshot_multiple(&[args_1, args_2]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_two_rules_with_same_name_from_different_plugin_names() {
|
||||||
|
// Issue: <https://github.com/oxc-project/oxc/issues/8485>
|
||||||
|
let args = &["-c", ".oxlintrc.json", "test.js"];
|
||||||
|
Tester::new().with_cwd("fixtures/two_rules_with_same_name".into()).test_and_snapshot(args);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_adjust_ignore_patterns() {
|
fn test_adjust_ignore_patterns() {
|
||||||
let base = PathBuf::from("/project/root");
|
let base = PathBuf::from("/project/root");
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,12 @@
|
||||||
|
---
|
||||||
|
source: apps/oxlint/src/tester.rs
|
||||||
|
---
|
||||||
|
##########
|
||||||
|
arguments: -c .oxlintrc.json test.js
|
||||||
|
working directory: fixtures/two_rules_with_same_name
|
||||||
|
----------
|
||||||
|
Found 0 warnings and 0 errors.
|
||||||
|
Finished in <variable>ms on 1 file with 74 rules using 1 threads.
|
||||||
|
----------
|
||||||
|
CLI result: LintSucceeded
|
||||||
|
----------
|
||||||
|
|
@ -110,28 +110,43 @@ impl OxlintRules {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
// For overlapping rule names, use the "error" one
|
let rules = rules_for_override
|
||||||
// "no-loss-of-precision": "off",
|
.iter()
|
||||||
// "@typescript-eslint/no-loss-of-precision": "error"
|
.filter_map(|r| {
|
||||||
if let Some(rule_config) =
|
if r.name() == *name {
|
||||||
rule_configs.iter().find(|r| r.severity.is_warn_deny())
|
Some((r.plugin_name(), r))
|
||||||
{
|
} else {
|
||||||
let config = rule_config.config.clone().unwrap_or_default();
|
None
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.collect::<FxHashMap<_, _>>();
|
||||||
|
|
||||||
if let Some(rule) = rules_for_override.iter().find(|r| r.name() == *name) {
|
for rule_config in rule_configs {
|
||||||
rules_to_replace
|
let (rule_name, plugin_name) = transform_rule_and_plugin_name(
|
||||||
.push(RuleWithSeverity::new(rule.read_json(config), rule.severity));
|
&rule_config.rule_name,
|
||||||
}
|
&rule_config.plugin_name,
|
||||||
// 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) {
|
if rule_config.severity.is_warn_deny() {
|
||||||
rules_to_replace.push(RuleWithSeverity::new(
|
let config = rule_config.config.clone().unwrap_or_default();
|
||||||
rule.read_json(config),
|
if let Some(rule) = rules.get(&plugin_name) {
|
||||||
rule_config.severity,
|
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) {
|
}
|
||||||
|
// 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() == rule_name && r.plugin_name() == plugin_name)
|
||||||
|
{
|
||||||
|
rules_to_replace.push(RuleWithSeverity::new(
|
||||||
|
rule.read_json(config),
|
||||||
|
rule_config.severity,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
} else if let Some(&rule) = rules.get(&plugin_name) {
|
||||||
rules_to_remove.push(rule.clone());
|
rules_to_remove.push(rule.clone());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -152,17 +167,12 @@ fn transform_rule_and_plugin_name<'a>(
|
||||||
rule_name: &'a str,
|
rule_name: &'a str,
|
||||||
plugin_name: &'a str,
|
plugin_name: &'a str,
|
||||||
) -> (&'a str, &'a str) {
|
) -> (&'a str, &'a str) {
|
||||||
if plugin_name == "vitest" && is_jest_rule_adapted_to_vitest(rule_name) {
|
let plugin_name = match plugin_name {
|
||||||
return (rule_name, "jest");
|
"vitest" if is_jest_rule_adapted_to_vitest(rule_name) => "jest",
|
||||||
}
|
"unicorn" if rule_name == "no-negated-condition" => "eslint",
|
||||||
|
"typescript" if is_eslint_rule_adapted_to_typescript(rule_name) => "eslint",
|
||||||
if plugin_name == "typescript" && is_eslint_rule_adapted_to_typescript(rule_name) {
|
_ => plugin_name,
|
||||||
return (rule_name, "eslint");
|
};
|
||||||
}
|
|
||||||
|
|
||||||
if plugin_name == "unicorn" && rule_name == "no-negated-condition" {
|
|
||||||
return ("no-negated-condition", "eslint");
|
|
||||||
}
|
|
||||||
|
|
||||||
(rule_name, plugin_name)
|
(rule_name, plugin_name)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue