Skip to content

Commit

Permalink
fix(linter): do not use nested configs with --config option
Browse files Browse the repository at this point in the history
  • Loading branch information
camchenry committed Feb 17, 2025
1 parent cdbcf2b commit 979b3ab
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 1 deletion.
6 changes: 6 additions & 0 deletions apps/oxlint/fixtures/nested_config/oxlint-no-console.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"rules": {
"no-console": "error",
"no-debugger": "off"
}
}
15 changes: 14 additions & 1 deletion apps/oxlint/src/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,12 @@ impl Runner for LintRunner {
let mut nested_oxlintrc = FxHashMap::<&Path, Oxlintrc>::default();
let mut nested_configs = FxHashMap::<PathBuf, ConfigStore>::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`
Expand Down Expand Up @@ -941,4 +946,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);
}
}
Original file line number Diff line number Diff line change
@@ -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 <variable>ms on 7 files with 97 rules using 1 threads.
----------
CLI result: LintFoundErrors
----------

0 comments on commit 979b3ab

Please sign in to comment.