Skip to content

Commit 9aaba69

Browse files
authored
fix(linter): nested configuration directory resolution (#10157)
Fixes #10156 I'm not very familiar with the inner workings of this project - this was a fix based on what I could understand after exploring the codebase for the first time. @camchenry It would be great to get your eyes on this since you are familiar with the nested config implementation.
1 parent e0057c3 commit 9aaba69

File tree

2 files changed

+38
-4
lines changed

2 files changed

+38
-4
lines changed

apps/oxlint/src/lint.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,15 +176,19 @@ impl Runner for LintRunner {
176176

177177
if use_nested_config {
178178
// get all of the unique directories among the paths to use for search for
179-
// oxlint config files in those directories
180-
// e.g. `/some/file.js` and `/some/other/file.js` would both result in `/some`
179+
// oxlint config files in those directories and their ancestors
180+
// e.g. `/some/file.js` will check `/some` and `/`
181+
// `/some/other/file.js` will check `/some/other`, `/some`, and `/`
181182
let mut directories = FxHashSet::default();
182183
for path in &paths {
183184
let path = Path::new(path);
184-
if let Some(directory) = path.parent() {
185+
// Start from the file's parent directory and walk up the tree
186+
let mut current = path.parent();
187+
while let Some(dir) = current {
185188
// NOTE: Initial benchmarking showed that it was faster to iterate over the directories twice
186189
// rather than constructing the configs in one iteration. It's worth re-benchmarking that though.
187-
directories.insert(directory);
190+
directories.insert(dir);
191+
current = dir.parent();
188192
}
189193
}
190194
for directory in directories {
@@ -1009,6 +1013,14 @@ mod test {
10091013
Tester::new().with_cwd("fixtures/extends_config".into()).test_and_snapshot(args);
10101014
}
10111015

1016+
#[test]
1017+
fn test_nested_config_subdirectory() {
1018+
// This tests the specific scenario from issue #10156
1019+
// where a file is located in a subdirectory of a directory with a config file
1020+
let args = &["package3-deep-config"];
1021+
Tester::new().with_cwd("fixtures/nested_config".into()).test_and_snapshot(args);
1022+
}
1023+
10121024
#[test]
10131025
fn test_nested_config_explicit_config_precedence() {
10141026
// `--config` takes absolute precedence over nested configs, and will be used for
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
source: apps/oxlint/src/tester.rs
3+
---
4+
##########
5+
arguments: package3-deep-config
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+
,-[package3-deep-config/src/components/component.js:2:3]
11+
1 | export function Component() {
12+
2 | console.log("hello");
13+
: ^^^^^^^^^^^
14+
3 | }
15+
`----
16+
help: Delete this console statement.
17+
18+
Found 0 warnings and 1 error.
19+
Finished in <variable>ms on 1 file using 1 threads.
20+
----------
21+
CLI result: LintFoundErrors
22+
----------

0 commit comments

Comments
 (0)