Skip to content

Commit 2c80858

Browse files
committedMar 28, 2025·
fix(linter): enable multi-file analysis for nested configs (#10089)
- fixes #10054 previously, multi-file analysis was only enabled when the root `.oxlintrc.json` contained the import plugin. now, we enable if any `.oxlintrc.json` has the import plugin.
1 parent 410b8d6 commit 2c80858

File tree

5 files changed

+60
-2
lines changed

5 files changed

+60
-2
lines changed
 

Diff for: ‎apps/oxlint/fixtures/issue_10054/.oxlintrc.json

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"plugins": ["import"],
3+
"rules": {
4+
"import/no-cycle": "error"
5+
}
6+
}

Diff for: ‎apps/oxlint/fixtures/issue_10054/a.ts

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { b } from "./b";
2+
3+
console.log(b);

Diff for: ‎apps/oxlint/fixtures/issue_10054/b.ts

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import "./a";
2+
3+
export const b = "b";

Diff for: ‎apps/oxlint/src/lint.rs

+15-2
Original file line numberDiff line numberDiff line change
@@ -316,8 +316,15 @@ impl Runner for LintRunner {
316316
}
317317
}
318318

319-
let mut options = LintServiceOptions::new(self.cwd, paths)
320-
.with_cross_module(config_builder.plugins().has_import());
319+
// TODO(refactor): pull this into a shared function, so that the language server can use
320+
// the same functionality.
321+
let use_cross_module = if use_nested_config {
322+
nested_configs.values().any(|config| config.plugins().has_import())
323+
} else {
324+
config_builder.plugins().has_import()
325+
};
326+
let mut options =
327+
LintServiceOptions::new(self.cwd, paths).with_cross_module(use_cross_module);
321328

322329
let lint_config = match config_builder.build() {
323330
Ok(config) => config,
@@ -1057,4 +1064,10 @@ mod test {
10571064
let args = &["overrides_same_directory"];
10581065
Tester::new().with_cwd("fixtures/extends_config".into()).test_and_snapshot(args);
10591066
}
1067+
1068+
#[test]
1069+
fn test_nested_config_multi_file_analysis_imports() {
1070+
let args = &["issue_10054"];
1071+
Tester::new().with_cwd("fixtures".into()).test_and_snapshot(args);
1072+
}
10601073
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
---
2+
source: apps/oxlint/src/tester.rs
3+
---
4+
##########
5+
arguments: issue_10054
6+
working directory: fixtures
7+
----------
8+
9+
x ]8;;https://oxc.rs/docs/guide/usage/linter/rules/import/no-cycle.html\eslint-plugin-import(no-cycle)]8;;\: Dependency cycle detected
10+
,-[issue_10054/a.ts:1:19]
11+
1 | import { b } from "./b";
12+
: ^^^^^
13+
2 |
14+
`----
15+
help: These paths form a cycle:
16+
-> ./b - fixtures/issue_10054/b.ts
17+
-> ./a - fixtures/issue_10054/a.ts
18+
19+
x ]8;;https://oxc.rs/docs/guide/usage/linter/rules/import/no-cycle.html\eslint-plugin-import(no-cycle)]8;;\: Dependency cycle detected
20+
,-[issue_10054/b.ts:1:8]
21+
1 | import "./a";
22+
: ^^^^^
23+
2 |
24+
`----
25+
help: These paths form a cycle:
26+
-> ./a - fixtures/issue_10054/a.ts
27+
-> ./b - fixtures/issue_10054/b.ts
28+
29+
Found 0 warnings and 2 errors.
30+
Finished in <variable>ms on 2 files using 1 threads.
31+
----------
32+
CLI result: LintFoundErrors
33+
----------

0 commit comments

Comments
 (0)
Please sign in to comment.