From 0bf2bcf35944326e8f95460842cbca04d94dbbe4 Mon Sep 17 00:00:00 2001 From: dalaoshu Date: Sat, 1 Feb 2025 21:29:23 +0800 Subject: [PATCH] test(oxlint): test two real rules with same name but from different plugins (#8821) Related to #8814 This test case is designed to verify that two different rules, having the same name but coming from different plugins, are treated as distinct rules rather than simple aliases. In `unicorn`, there is only one rule, `no-negated-condition`, which is aliased to `eslint`. https://github.com/oxc-project/oxc/blob/655b2126889a3307929a1a20047b317c1eefb140/crates/oxc_linter/src/config/rules.rs#L166-L178 --- .../.oxlintrc-eslint.json | 2 +- .../.oxlintrc-unicorn.json | 2 +- .../disable_eslint_and_unicorn_alias_rules/test.js | 6 +++++- .../two_rules_with_same_rule_name/.oxlintrc.json | 9 +++++++++ .../fixtures/two_rules_with_same_rule_name/test.js | 1 + apps/oxlint/src/lint.rs | 10 +++++++++- ...e_rule_name_-c .oxlintrc.json test.js@oxlint.snap | 12 ++++++++++++ 7 files changed, 38 insertions(+), 4 deletions(-) create mode 100644 apps/oxlint/fixtures/two_rules_with_same_rule_name/.oxlintrc.json create mode 100644 apps/oxlint/fixtures/two_rules_with_same_rule_name/test.js create mode 100644 apps/oxlint/src/snapshots/fixtures__two_rules_with_same_rule_name_-c .oxlintrc.json test.js@oxlint.snap diff --git a/apps/oxlint/fixtures/disable_eslint_and_unicorn_alias_rules/.oxlintrc-eslint.json b/apps/oxlint/fixtures/disable_eslint_and_unicorn_alias_rules/.oxlintrc-eslint.json index 9f5e705e3..c60c7a4b4 100644 --- a/apps/oxlint/fixtures/disable_eslint_and_unicorn_alias_rules/.oxlintrc-eslint.json +++ b/apps/oxlint/fixtures/disable_eslint_and_unicorn_alias_rules/.oxlintrc-eslint.json @@ -1,6 +1,6 @@ { "plugins": [], "rules": { - "eslint/no-nested-ternary": "off" + "eslint/no-negated-condition": "off" } } diff --git a/apps/oxlint/fixtures/disable_eslint_and_unicorn_alias_rules/.oxlintrc-unicorn.json b/apps/oxlint/fixtures/disable_eslint_and_unicorn_alias_rules/.oxlintrc-unicorn.json index 6d34ea2c5..3347526bd 100644 --- a/apps/oxlint/fixtures/disable_eslint_and_unicorn_alias_rules/.oxlintrc-unicorn.json +++ b/apps/oxlint/fixtures/disable_eslint_and_unicorn_alias_rules/.oxlintrc-unicorn.json @@ -3,6 +3,6 @@ "unicorn" ], "rules": { - "unicorn/no-nested-ternary": "off" + "unicorn/no-negated-condition": "off" } } diff --git a/apps/oxlint/fixtures/disable_eslint_and_unicorn_alias_rules/test.js b/apps/oxlint/fixtures/disable_eslint_and_unicorn_alias_rules/test.js index 498f6f9b2..bfcc644f1 100644 --- a/apps/oxlint/fixtures/disable_eslint_and_unicorn_alias_rules/test.js +++ b/apps/oxlint/fixtures/disable_eslint_and_unicorn_alias_rules/test.js @@ -1 +1,5 @@ -console.log(bar ? baz : qux === quxx ? bing : bam); +if (!condition) { + console.log(123) +} else { + console.log(666) +} diff --git a/apps/oxlint/fixtures/two_rules_with_same_rule_name/.oxlintrc.json b/apps/oxlint/fixtures/two_rules_with_same_rule_name/.oxlintrc.json new file mode 100644 index 000000000..ee3c88d50 --- /dev/null +++ b/apps/oxlint/fixtures/two_rules_with_same_rule_name/.oxlintrc.json @@ -0,0 +1,9 @@ +{ + "plugins": [ + "unicorn" + ], + "rules": { + "eslint/no-nested-ternary": "off", + "unicorn/no-nested-ternary": "off" + } +} diff --git a/apps/oxlint/fixtures/two_rules_with_same_rule_name/test.js b/apps/oxlint/fixtures/two_rules_with_same_rule_name/test.js new file mode 100644 index 000000000..498f6f9b2 --- /dev/null +++ b/apps/oxlint/fixtures/two_rules_with_same_rule_name/test.js @@ -0,0 +1 @@ +console.log(bar ? baz : qux === quxx ? bing : bam); diff --git a/apps/oxlint/src/lint.rs b/apps/oxlint/src/lint.rs index 446eb6cea..3c1f2f1eb 100644 --- a/apps/oxlint/src/lint.rs +++ b/apps/oxlint/src/lint.rs @@ -826,7 +826,6 @@ mod test { #[test] fn test_disable_eslint_and_unicorn_alias_rules() { - // Issue: let args_1 = &["-c", ".oxlintrc-eslint.json", "test.js"]; let args_2 = &["-c", ".oxlintrc-unicorn.json", "test.js"]; Tester::new() @@ -834,6 +833,15 @@ mod test { .test_and_snapshot_multiple(&[args_1, args_2]); } + #[test] + fn test_two_rules_with_same_rule_name_from_different_plugins() { + // Issue: + let args = &["-c", ".oxlintrc.json", "test.js"]; + Tester::new() + .with_cwd("fixtures/two_rules_with_same_rule_name".into()) + .test_and_snapshot(args); + } + #[test] fn test_adjust_ignore_patterns() { let base = PathBuf::from("/project/root"); diff --git a/apps/oxlint/src/snapshots/fixtures__two_rules_with_same_rule_name_-c .oxlintrc.json test.js@oxlint.snap b/apps/oxlint/src/snapshots/fixtures__two_rules_with_same_rule_name_-c .oxlintrc.json test.js@oxlint.snap new file mode 100644 index 000000000..a388090bc --- /dev/null +++ b/apps/oxlint/src/snapshots/fixtures__two_rules_with_same_rule_name_-c .oxlintrc.json test.js@oxlint.snap @@ -0,0 +1,12 @@ +--- +source: apps/oxlint/src/tester.rs +--- +########## +arguments: -c .oxlintrc.json test.js +working directory: fixtures/two_rules_with_same_rule_name +---------- +Found 0 warnings and 0 errors. +Finished in ms on 1 file with 61 rules using 1 threads. +---------- +CLI result: LintSucceeded +----------