Skip to content

Commit 28d9e68

Browse files
committed
test(linter): ensure CLI filters take precedence over nested configs
1 parent d981385 commit 28d9e68

4 files changed

Lines changed: 122 additions & 1 deletion

apps/oxlint/src/lint.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -956,10 +956,32 @@ mod test {
956956
}
957957

958958
#[test]
959-
fn test_nested_config_precedence() {
959+
fn test_nested_config_explicit_config_precedence() {
960960
// `--config` takes absolute precedence over nested configs, and will be used for
961961
// linting all files rather than the nested configuration files.
962962
let args = &["--experimental-nested-config", "--config", "oxlint-no-console.json"];
963963
Tester::new().with_cwd("fixtures/nested_config".into()).test_and_snapshot(args);
964964
}
965+
966+
#[test]
967+
fn test_nested_config_filter_precedence() {
968+
// CLI arguments take precedence over nested configs, but apply over top of the nested
969+
// config files, rather than replacing them.
970+
let args = &["--experimental-nested-config", "-A", "no-console"];
971+
Tester::new().with_cwd("fixtures/nested_config".into()).test_and_snapshot(args);
972+
}
973+
974+
#[test]
975+
fn test_nested_config_explicit_config_and_filter_precedence() {
976+
// Combining `--config` and CLI filters should make the passed config file be
977+
// used for all files, but still override any rules specified in the config file.
978+
let args = &[
979+
"--experimental-nested-config",
980+
"-A",
981+
"no-console",
982+
"--config",
983+
"oxlint-no-console.json",
984+
];
985+
Tester::new().with_cwd("fixtures/nested_config".into()).test_and_snapshot(args);
986+
}
965987
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
---
2+
source: apps/oxlint/src/tester.rs
3+
---
4+
##########
5+
arguments: --experimental-nested-config --config oxlint-no-console.json
6+
working directory: fixtures/nested_config
7+
----------
8+
9+
x ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-console.html\eslint(no-console)]8;;\: eslint(no-console): Unexpected console statement.
10+
,-[console.ts:1:1]
11+
1 | console.log("test");
12+
: ^^^^^^^^^^^
13+
`----
14+
help: Delete this console statement.
15+
16+
x ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-console.html\eslint(no-console)]8;;\: eslint(no-console): Unexpected console statement.
17+
,-[package1-empty-config/console.ts:1:1]
18+
1 | console.log("test");
19+
: ^^^^^^^^^^^
20+
`----
21+
help: Delete this console statement.
22+
23+
x ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-console.html\eslint(no-console)]8;;\: eslint(no-console): Unexpected console statement.
24+
,-[package2-no-config/console.ts:1:1]
25+
1 | console.log("test");
26+
: ^^^^^^^^^^^
27+
`----
28+
help: Delete this console statement.
29+
30+
x ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-console.html\eslint(no-console)]8;;\: eslint(no-console): Unexpected console statement.
31+
,-[package3-deep-config/src/components/component.js:2:3]
32+
1 | export function Component() {
33+
2 | console.log("hello");
34+
: ^^^^^^^^^^^
35+
3 | }
36+
`----
37+
help: Delete this console statement.
38+
39+
Found 0 warnings and 4 errors.
40+
Finished in <variable>ms on 7 files with 97 rules using 1 threads.
41+
----------
42+
CLI result: LintFoundErrors
43+
----------
44+
45+
##########
46+
arguments: --experimental-nested-config --config oxlint-no-console.json -A no-console fixtures/nested_config
47+
working directory: fixtures/nested_config
48+
----------
49+
Found 0 warnings and 0 errors.
50+
Finished in <variable>ms on 0 files with 97 rules using 1 threads.
51+
----------
52+
CLI result: LintSucceeded
53+
----------
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
source: apps/oxlint/src/tester.rs
3+
---
4+
##########
5+
arguments: --experimental-nested-config -A no-console --config oxlint-no-console.json
6+
working directory: fixtures/nested_config
7+
----------
8+
Found 0 warnings and 0 errors.
9+
Finished in <variable>ms on 7 files with 96 rules using 1 threads.
10+
----------
11+
CLI result: LintSucceeded
12+
----------
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
source: apps/oxlint/src/tester.rs
3+
---
4+
##########
5+
arguments: --experimental-nested-config -A no-console
6+
working directory: fixtures/nested_config
7+
----------
8+
9+
x ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-debugger.html\eslint(no-debugger)]8;;\: `debugger` statement is not allowed
10+
,-[debugger.js:1:1]
11+
1 | debugger;
12+
: ^^^^^^^^^
13+
`----
14+
help: Delete this code.
15+
16+
! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-debugger.html\eslint(no-debugger)]8;;\: `debugger` statement is not allowed
17+
,-[package1-empty-config/debugger.js:1:1]
18+
1 | debugger;
19+
: ^^^^^^^^^
20+
`----
21+
help: Delete this code.
22+
23+
x ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-debugger.html\eslint(no-debugger)]8;;\: `debugger` statement is not allowed
24+
,-[package2-no-config/debugger.js:1:1]
25+
1 | debugger;
26+
: ^^^^^^^^^
27+
`----
28+
help: Delete this code.
29+
30+
Found 1 warning and 2 errors.
31+
Finished in <variable>ms on 7 files with 97 rules using 1 threads.
32+
----------
33+
CLI result: LintFoundErrors
34+
----------

0 commit comments

Comments
 (0)