Skip to content

Commit

Permalink
test(oxlint): test two real rules with same name but from different p…
Browse files Browse the repository at this point in the history
…lugins (#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
  • Loading branch information
shulaoda authored Feb 1, 2025
1 parent b00b8c8 commit 0bf2bcf
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"plugins": [],
"rules": {
"eslint/no-nested-ternary": "off"
"eslint/no-negated-condition": "off"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
"unicorn"
],
"rules": {
"unicorn/no-nested-ternary": "off"
"unicorn/no-negated-condition": "off"
}
}
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
console.log(bar ? baz : qux === quxx ? bing : bam);
if (!condition) {
console.log(123)
} else {
console.log(666)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"plugins": [
"unicorn"
],
"rules": {
"eslint/no-nested-ternary": "off",
"unicorn/no-nested-ternary": "off"
}
}
1 change: 1 addition & 0 deletions apps/oxlint/fixtures/two_rules_with_same_rule_name/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log(bar ? baz : qux === quxx ? bing : bam);
10 changes: 9 additions & 1 deletion apps/oxlint/src/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -826,14 +826,22 @@ mod test {

#[test]
fn test_disable_eslint_and_unicorn_alias_rules() {
// Issue: <https://github.com/oxc-project/oxc/issues/8485>
let args_1 = &["-c", ".oxlintrc-eslint.json", "test.js"];
let args_2 = &["-c", ".oxlintrc-unicorn.json", "test.js"];
Tester::new()
.with_cwd("fixtures/disable_eslint_and_unicorn_alias_rules".into())
.test_and_snapshot_multiple(&[args_1, args_2]);
}

#[test]
fn test_two_rules_with_same_rule_name_from_different_plugins() {
// 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_rule_name".into())
.test_and_snapshot(args);
}

#[test]
fn test_adjust_ignore_patterns() {
let base = PathBuf::from("/project/root");
Expand Down
Original file line number Diff line number Diff line change
@@ -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 <variable>ms on 1 file with 61 rules using 1 threads.
----------
CLI result: LintSucceeded
----------

0 comments on commit 0bf2bcf

Please sign in to comment.