Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(linter): do not use nested configs with --config option #9155

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -947,4 +952,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 99 rules using 1 threads.
----------
CLI result: LintFoundErrors
----------
Loading