Skip to content
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
20 changes: 16 additions & 4 deletions apps/oxlint/src/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,15 +176,19 @@ impl Runner for LintRunner {

if 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`
// oxlint config files in those directories and their ancestors
// e.g. `/some/file.js` will check `/some` and `/`
// `/some/other/file.js` will check `/some/other`, `/some`, and `/`
let mut directories = FxHashSet::default();
for path in &paths {
let path = Path::new(path);
if let Some(directory) = path.parent() {
// Start from the file's parent directory and walk up the tree
let mut current = path.parent();
while let Some(dir) = current {
// NOTE: Initial benchmarking showed that it was faster to iterate over the directories twice
// rather than constructing the configs in one iteration. It's worth re-benchmarking that though.
directories.insert(directory);
directories.insert(dir);
current = dir.parent();
}
}
for directory in directories {
Expand Down Expand Up @@ -1009,6 +1013,14 @@ mod test {
Tester::new().with_cwd("fixtures/extends_config".into()).test_and_snapshot(args);
}

#[test]
fn test_nested_config_subdirectory() {
// This tests the specific scenario from issue #10156
// where a file is located in a subdirectory of a directory with a config file
let args = &["package3-deep-config"];
Tester::new().with_cwd("fixtures/nested_config".into()).test_and_snapshot(args);
}

#[test]
fn test_nested_config_explicit_config_precedence() {
// `--config` takes absolute precedence over nested configs, and will be used for
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
source: apps/oxlint/src/tester.rs
---
##########
arguments: package3-deep-config
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.
,-[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 1 error.
Finished in <variable>ms on 1 file using 1 threads.
----------
CLI result: LintFoundErrors
----------
Loading