Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 165bd69

Browse files
committedFeb 22, 2025·
fix(linter): do not use nested configs with --config option
1 parent 9bc3017 commit 165bd69

File tree

3 files changed

+63
-1
lines changed

3 files changed

+63
-1
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"rules": {
3+
"no-console": "error",
4+
"no-debugger": "off"
5+
}
6+
}

‎apps/oxlint/src/lint.rs

+14-1
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,12 @@ impl Runner for LintRunner {
175175
let mut nested_oxlintrc = FxHashMap::<&Path, Oxlintrc>::default();
176176
let mut nested_configs = FxHashMap::<PathBuf, ConfigStore>::default();
177177

178-
if experimental_nested_config {
178+
let use_nested_config =
179+
// If the `--config` option is explicitly passed, we should not search for nested config files
180+
// as the passed config file takes absolute precedence.
181+
basic_options.config.is_none();
182+
183+
if experimental_nested_config && use_nested_config {
179184
// get all of the unique directories among the paths to use for search for
180185
// oxlint config files in those directories
181186
// e.g. `/some/file.js` and `/some/other/file.js` would both result in `/some`
@@ -947,4 +952,12 @@ mod test {
947952
let args = &["--experimental-nested-config"];
948953
Tester::new().with_cwd("fixtures/nested_config".into()).test_and_snapshot(args);
949954
}
955+
956+
#[test]
957+
fn test_nested_config_precedence() {
958+
// `--config` takes absolute precedence over nested configs, and will be used for
959+
// linting all files rather than the nested configuration files.
960+
let args = &["--experimental-nested-config", "--config", "oxlint-no-console.json"];
961+
Tester::new().with_cwd("fixtures/nested_config".into()).test_and_snapshot(args);
962+
}
950963
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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 99 rules using 1 threads.
41+
----------
42+
CLI result: LintFoundErrors
43+
----------

0 commit comments

Comments
 (0)
Please sign in to comment.