Skip to content

Commit 225e266

Browse files
committedMar 13, 2025·
feat(linter)!: enable --experimental-nested-config by default and add --disable-nested-config option (#9760)
- closes #9755 - Makes the `--experimental-nested-config` behavior the default. - Includes a bug fix where nested configs didn't work properly with `--fix`. - Adds a `--disable-nested-config` option to just read the config file from the current directory and skip looking for `.oxlintrc.json` files in directories.
1 parent bda4b9a commit 225e266

13 files changed

+246
-40
lines changed
 

‎apps/oxlint/src/command/lint.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ pub struct LintCommand {
4242
#[bpaf(external)]
4343
pub misc_options: MiscOptions,
4444

45-
/// Enables automatic loading of nested configuration files (experimental feature)
45+
/// Disables the automatic loading of nested configuration files.
4646
#[bpaf(switch, hide_usage)]
47-
pub experimental_nested_config: bool,
47+
pub disable_nested_config: bool,
4848

4949
/// Single file, single path or list of paths
5050
#[bpaf(positional("PATH"), many, guard(validate_paths, PATHS_ERROR_MESSAGE))]
@@ -519,10 +519,10 @@ mod lint_options {
519519
}
520520

521521
#[test]
522-
fn experimental_nested_config() {
523-
let options = get_lint_options("--experimental-nested-config");
524-
assert!(options.experimental_nested_config);
522+
fn disable_nested_config() {
523+
let options = get_lint_options("--disable-nested-config");
524+
assert!(options.disable_nested_config);
525525
let options = get_lint_options(".");
526-
assert!(!options.experimental_nested_config);
526+
assert!(!options.disable_nested_config);
527527
}
528528
}

‎apps/oxlint/src/lint.rs

+13-15
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@ impl Runner for LintRunner {
5656
fix_options,
5757
enable_plugins,
5858
misc_options,
59-
experimental_nested_config,
59+
disable_nested_config,
6060
..
6161
} = self.options;
6262

63-
let use_nested_config = experimental_nested_config &&
63+
let use_nested_config = !disable_nested_config &&
6464
// If the `--config` option is explicitly passed, we should not search for nested config files
6565
// as the passed config file takes absolute precedence.
6666
basic_options.config.is_none();
@@ -334,8 +334,9 @@ impl Runner for LintRunner {
334334
}
335335
};
336336

337-
let linter = if experimental_nested_config {
337+
let linter = if use_nested_config {
338338
Linter::new_with_nested_configs(LintOptions::default(), lint_config, nested_configs)
339+
.with_fix(fix_options.fix_kind())
339340
} else {
340341
Linter::new(LintOptions::default(), lint_config).with_fix(fix_options.fix_kind())
341342
};
@@ -984,37 +985,34 @@ mod test {
984985

985986
#[test]
986987
fn test_nested_config() {
987-
let args = &["--experimental-nested-config"];
988+
let args = &[];
988989
Tester::new().with_cwd("fixtures/nested_config".into()).test_and_snapshot(args);
990+
991+
let args = &["--disable-nested-config"];
992+
Tester::new().with_cwd("fixtures/extends_config".into()).test_and_snapshot(args);
989993
}
990994

991995
#[test]
992996
fn test_nested_config_explicit_config_precedence() {
993997
// `--config` takes absolute precedence over nested configs, and will be used for
994998
// linting all files rather than the nested configuration files.
995-
let args = &["--experimental-nested-config", "--config", "oxlint-no-console.json"];
999+
let args = &["--config", "oxlint-no-console.json"];
9961000
Tester::new().with_cwd("fixtures/nested_config".into()).test_and_snapshot(args);
9971001
}
9981002

9991003
#[test]
10001004
fn test_nested_config_filter_precedence() {
10011005
// CLI arguments take precedence over nested configs, but apply over top of the nested
10021006
// config files, rather than replacing them.
1003-
let args = &["--experimental-nested-config", "-A", "no-console"];
1007+
let args = &["-A", "no-console"];
10041008
Tester::new().with_cwd("fixtures/nested_config".into()).test_and_snapshot(args);
10051009
}
10061010

10071011
#[test]
10081012
fn test_nested_config_explicit_config_and_filter_precedence() {
10091013
// Combining `--config` and CLI filters should make the passed config file be
10101014
// used for all files, but still override any rules specified in the config file.
1011-
let args = &[
1012-
"--experimental-nested-config",
1013-
"-A",
1014-
"no-console",
1015-
"--config",
1016-
"oxlint-no-console.json",
1017-
];
1015+
let args = &["-A", "no-console", "--config", "oxlint-no-console.json"];
10181016
Tester::new().with_cwd("fixtures/nested_config".into()).test_and_snapshot(args);
10191017
}
10201018

@@ -1035,11 +1033,11 @@ mod test {
10351033
#[test]
10361034
fn test_extends_overrides() {
10371035
// Check that using a config with overrides works as expected
1038-
let args = &["--experimental-nested-config", "overrides"];
1036+
let args = &["overrides"];
10391037
Tester::new().with_cwd("fixtures/extends_config".into()).test_and_snapshot(args);
10401038

10411039
// Check that using a config which extends a config with overrides works as expected
1042-
let args = &["--experimental-nested-config", "overrides_same_directory"];
1040+
let args = &["overrides_same_directory"];
10431041
Tester::new().with_cwd("fixtures/extends_config".into()).test_and_snapshot(args);
10441042
}
10451043
}

‎apps/oxlint/src/snapshots/fixtures__auto_config_detection_debugger.js@oxlint.snap

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ working directory: fixtures/auto_config_detection
1414
help: Delete this code.
1515
1616
Found 0 warnings and 1 error.
17-
Finished in <variable>ms on 1 file with 99 rules using 1 threads.
17+
Finished in <variable>ms on 1 file using 1 threads.
1818
----------
1919
CLI result: LintFoundErrors
2020
----------
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
---
2+
source: apps/oxlint/src/tester.rs
3+
---
4+
##########
5+
arguments: --disable-nested-config
6+
working directory: fixtures/extends_config
7+
----------
8+
9+
! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-unused-vars.html\eslint(no-unused-vars)]8;;\: Variable 'x' is declared but never used. Unused variables should start with a '_'.
10+
,-[overrides/test.ts:1:7]
11+
1 | const x: any = 3;
12+
: |
13+
: `-- 'x' is declared here
14+
`----
15+
help: Consider removing this declaration.
16+
17+
! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-unused-vars.html\eslint(no-unused-vars)]8;;\: Function 'component' is declared but never used.
18+
,-[overrides/test.tsx:1:10]
19+
1 | function component(): any {
20+
: ^^^^|^^^^
21+
: `-- 'component' is declared here
22+
2 | return <a>click here</a>;
23+
`----
24+
help: Consider removing this declaration.
25+
26+
! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-debugger.html\eslint(no-debugger)]8;;\: `debugger` statement is not allowed
27+
,-[overrides_same_directory/config/test.js:1:1]
28+
1 | debugger;
29+
: ^^^^^^^^^
30+
`----
31+
help: Delete this code.
32+
33+
Found 3 warnings and 0 errors.
34+
Finished in <variable>ms on 4 files with 99 rules using 1 threads.
35+
----------
36+
CLI result: LintSucceeded
37+
----------

‎apps/oxlint/src/snapshots/fixtures__extends_config_overrides@oxlint.snap

+19-13
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,31 @@ arguments: overrides
66
working directory: fixtures/extends_config
77
----------
88

9-
! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-unused-vars.html\eslint(no-unused-vars)]8;;\: Variable 'x' is declared but never used. Unused variables should start with a '_'.
10-
,-[overrides/test.ts:1:7]
9+
x ]8;;https://oxc.rs/docs/guide/usage/linter/rules/typescript/no-explicit-any.html\typescript-eslint(no-explicit-any)]8;;\: Unexpected any. Specify a different type.
10+
,-[overrides/test.ts:1:10]
1111
1 | const x: any = 3;
12-
: |
13-
: `-- 'x' is declared here
12+
: ^^^
1413
`----
15-
help: Consider removing this declaration.
14+
help: Use `unknown` instead, this will force you to explicitly, and safely, assert the type is correct.
1615
17-
! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-unused-vars.html\eslint(no-unused-vars)]8;;\: Function 'component' is declared but never used.
18-
,-[overrides/test.tsx:1:10]
16+
x ]8;;https://oxc.rs/docs/guide/usage/linter/rules/typescript/no-explicit-any.html\typescript-eslint(no-explicit-any)]8;;\: Unexpected any. Specify a different type.
17+
,-[overrides/test.tsx:1:23]
1918
1 | function component(): any {
20-
: ^^^^|^^^^
21-
: `-- 'component' is declared here
19+
: ^^^
2220
2 | return <a>click here</a>;
2321
`----
24-
help: Consider removing this declaration.
22+
help: Use `unknown` instead, this will force you to explicitly, and safely, assert the type is correct.
2523
26-
Found 2 warnings and 0 errors.
27-
Finished in <variable>ms on 2 files with 100 rules using 1 threads.
24+
x ]8;;https://oxc.rs/docs/guide/usage/linter/rules/jsx_a11y/anchor-ambiguous-text.html\eslint-plugin-jsx-a11y(anchor-ambiguous-text)]8;;\: Unexpected ambagious anchor link text.
25+
,-[overrides/test.tsx:2:10]
26+
1 | function component(): any {
27+
2 | return <a>click here</a>;
28+
: ^^^^^^^^^^^^^^^^^
29+
3 | }
30+
`----
31+
32+
Found 0 warnings and 3 errors.
33+
Finished in <variable>ms on 2 files using 1 threads.
2834
----------
29-
CLI result: LintSucceeded
35+
CLI result: LintFoundErrors
3036
----------
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
source: apps/oxlint/src/tester.rs
3+
---
4+
##########
5+
arguments: overrides_same_directory
6+
working directory: fixtures/extends_config
7+
----------
8+
9+
! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-debugger.html\eslint(no-debugger)]8;;\: `debugger` statement is not allowed
10+
,-[overrides_same_directory/config/test.js:1:1]
11+
1 | debugger;
12+
: ^^^^^^^^^
13+
`----
14+
help: Delete this code.
15+
16+
Found 1 warning and 0 errors.
17+
Finished in <variable>ms on 1 file using 1 threads.
18+
----------
19+
CLI result: LintSucceeded
20+
----------
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
---
2+
source: apps/oxlint/src/tester.rs
3+
---
4+
##########
5+
arguments: --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+
----------
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
source: apps/oxlint/src/tester.rs
3+
---
4+
##########
5+
arguments: -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 98 rules using 1 threads.
10+
----------
11+
CLI result: LintSucceeded
12+
----------
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
source: apps/oxlint/src/tester.rs
3+
---
4+
##########
5+
arguments: -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 using 1 threads.
32+
----------
33+
CLI result: LintFoundErrors
34+
----------
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
---
2+
source: apps/oxlint/src/tester.rs
3+
---
4+
##########
5+
arguments:
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-debugger.html\eslint(no-debugger)]8;;\: `debugger` statement is not allowed
17+
,-[debugger.js:1:1]
18+
1 | debugger;
19+
: ^^^^^^^^^
20+
`----
21+
help: Delete this code.
22+
23+
! ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-debugger.html\eslint(no-debugger)]8;;\: `debugger` statement is not allowed
24+
,-[package1-empty-config/debugger.js:1:1]
25+
1 | debugger;
26+
: ^^^^^^^^^
27+
`----
28+
help: Delete this code.
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+
,-[package2-no-config/console.ts:1:1]
32+
1 | console.log("test");
33+
: ^^^^^^^^^^^
34+
`----
35+
help: Delete this console statement.
36+
37+
x ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-debugger.html\eslint(no-debugger)]8;;\: `debugger` statement is not allowed
38+
,-[package2-no-config/debugger.js:1:1]
39+
1 | debugger;
40+
: ^^^^^^^^^
41+
`----
42+
help: Delete this code.
43+
44+
x ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-console.html\eslint(no-console)]8;;\: eslint(no-console): Unexpected console statement.
45+
,-[package3-deep-config/src/components/component.js:2:3]
46+
1 | export function Component() {
47+
2 | console.log("hello");
48+
: ^^^^^^^^^^^
49+
3 | }
50+
`----
51+
help: Delete this console statement.
52+
53+
Found 1 warning and 5 errors.
54+
Finished in <variable>ms on 7 files using 1 threads.
55+
----------
56+
CLI result: LintFoundErrors
57+
----------

‎apps/oxlint/src/snapshots/fixtures__output_formatter_diagnostic_--format=default test.js@oxlint.snap

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ working directory: fixtures/output_formatter_diagnostic
3333
help: Delete this code.
3434
3535
Found 2 warnings and 1 error.
36-
Finished in <variable>ms on 1 file with 99 rules using 1 threads.
36+
Finished in <variable>ms on 1 file using 1 threads.
3737
----------
3838
CLI result: LintFoundErrors
3939
----------

‎tasks/website/src/linter/snapshots/cli.snap

+2-2
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,8 @@ Arguments:
133133
## Available options:
134134
- **` --rules`** &mdash;
135135
list all the rules that are currently registered
136-
- **` --experimental-nested-config`** &mdash;
137-
Enables automatic loading of nested configuration files (experimental feature)
136+
- **` --disable-nested-config`** &mdash;
137+
Disables the automatic loading of nested configuration files.
138138
- **`-h`**, **`--help`** &mdash;
139139
Prints help information
140140
- **`-V`**, **`--version`** &mdash;

‎tasks/website/src/linter/snapshots/cli_terminal.snap

+1-2
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ Available positional items:
8181

8282
Available options:
8383
--rules list all the rules that are currently registered
84-
--experimental-nested-config Enables automatic loading of nested configuration files
85-
(experimental feature)
84+
--disable-nested-config Disables the automatic loading of nested configuration files.
8685
-h, --help Prints help information
8786
-V, --version Prints version information

0 commit comments

Comments
 (0)
Please sign in to comment.