diff --git a/apps/oxlint/fixtures/nested_config/oxlint-no-console.json b/apps/oxlint/fixtures/nested_config/oxlint-no-console.json new file mode 100644 index 00000000000000..f35466e3f8004b --- /dev/null +++ b/apps/oxlint/fixtures/nested_config/oxlint-no-console.json @@ -0,0 +1,6 @@ +{ + "rules": { + "no-console": "error", + "no-debugger": "off" + } +} diff --git a/apps/oxlint/src/lint.rs b/apps/oxlint/src/lint.rs index b01e4c421ebaae..cd266c985a98e9 100644 --- a/apps/oxlint/src/lint.rs +++ b/apps/oxlint/src/lint.rs @@ -175,7 +175,12 @@ impl Runner for LintRunner { let mut nested_oxlintrc = FxHashMap::<&Path, Oxlintrc>::default(); let mut nested_configs = FxHashMap::::default(); - if experimental_nested_config { + let use_nested_config = + // If the `--config` option is explicitly passed, we should not search for nested config files + // as the passed config file takes absolute precedence. + basic_options.config.is_none(); + + if experimental_nested_config && use_nested_config { // get all of the unique directories among the paths to use for search for // oxlint config files in those directories // e.g. `/some/file.js` and `/some/other/file.js` would both result in `/some` @@ -949,4 +954,12 @@ mod test { let args = &["--experimental-nested-config"]; Tester::new().with_cwd("fixtures/nested_config".into()).test_and_snapshot(args); } + + #[test] + fn test_nested_config_precedence() { + // `--config` takes absolute precedence over nested configs, and will be used for + // linting all files rather than the nested configuration files. + let args = &["--experimental-nested-config", "--config", "oxlint-no-console.json"]; + Tester::new().with_cwd("fixtures/nested_config".into()).test_and_snapshot(args); + } } diff --git a/apps/oxlint/src/snapshots/fixtures__nested_config_--experimental-nested-config --config oxlint-no-console.json@oxlint.snap b/apps/oxlint/src/snapshots/fixtures__nested_config_--experimental-nested-config --config oxlint-no-console.json@oxlint.snap new file mode 100644 index 00000000000000..7caad0df17da71 --- /dev/null +++ b/apps/oxlint/src/snapshots/fixtures__nested_config_--experimental-nested-config --config oxlint-no-console.json@oxlint.snap @@ -0,0 +1,43 @@ +--- +source: apps/oxlint/src/tester.rs +--- +########## +arguments: --experimental-nested-config --config oxlint-no-console.json +working directory: fixtures/nested_config +---------- + + x ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-console.html\eslint(no-console)]8;;\: eslint(no-console): Unexpected console statement. + ,-[console.ts:1:1] + 1 | console.log("test"); + : ^^^^^^^^^^^ + `---- + help: Delete this console statement. + + x ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-console.html\eslint(no-console)]8;;\: eslint(no-console): Unexpected console statement. + ,-[package1-empty-config/console.ts:1:1] + 1 | console.log("test"); + : ^^^^^^^^^^^ + `---- + help: Delete this console statement. + + x ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-console.html\eslint(no-console)]8;;\: eslint(no-console): Unexpected console statement. + ,-[package2-no-config/console.ts:1:1] + 1 | console.log("test"); + : ^^^^^^^^^^^ + `---- + help: Delete this console statement. + + x ]8;;https://oxc.rs/docs/guide/usage/linter/rules/eslint/no-console.html\eslint(no-console)]8;;\: eslint(no-console): Unexpected console statement. + ,-[package3-deep-config/src/components/component.js:2:3] + 1 | export function Component() { + 2 | console.log("hello"); + : ^^^^^^^^^^^ + 3 | } + `---- + help: Delete this console statement. + +Found 0 warnings and 4 errors. +Finished in ms on 7 files with 97 rules using 1 threads. +---------- +CLI result: LintFoundErrors +----------