Skip to content

Commit 723b4c6

Browse files
authored
fix(linter): cross_module of LintService not being enabled despite enabled import plugin (#10597)
Running `oxlint --import-plugin` with no `oxlintrc.json` didn't enable `cross_module` of `LintService`, because `use_nested_config` was `true` and `nested_configs` empty in that case. This leads to rules like `import/no-cycle` not working.
1 parent e7eb919 commit 723b4c6

File tree

4 files changed

+58
-8
lines changed

4 files changed

+58
-8
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { B } from "./b";
2+
3+
export class A {
4+
value: B;
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { A } from "./a";
2+
3+
export class B {
4+
value: A;
5+
}

apps/oxlint/src/lint.rs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ impl Runner for LintRunner {
5959
..
6060
} = self.options;
6161

62-
let use_nested_config = !disable_nested_config &&
62+
let search_for_nested_configs = !disable_nested_config &&
6363
// If the `--config` option is explicitly passed, we should not search for nested config files
6464
// as the passed config file takes absolute precedence.
6565
basic_options.config.is_none();
@@ -171,7 +171,7 @@ impl Runner for LintRunner {
171171

172172
let handler = GraphicalReportHandler::new();
173173

174-
if use_nested_config {
174+
if search_for_nested_configs {
175175
// get all of the unique directories among the paths to use for search for
176176
// oxlint config files in those directories and their ancestors
177177
// e.g. `/some/file.js` will check `/some` and `/`
@@ -290,10 +290,10 @@ impl Runner for LintRunner {
290290

291291
// TODO(refactor): pull this into a shared function, so that the language server can use
292292
// the same functionality.
293-
let use_cross_module = if use_nested_config {
294-
nested_configs.values().any(|config| config.plugins().has_import())
295-
} else {
293+
let use_cross_module = if nested_configs.is_empty() {
296294
config_builder.plugins().has_import()
295+
} else {
296+
nested_configs.values().any(|config| config.plugins().has_import())
297297
};
298298
let mut options =
299299
LintServiceOptions::new(self.cwd, paths).with_cross_module(use_cross_module);
@@ -319,12 +319,12 @@ impl Runner for LintRunner {
319319
_ => None,
320320
};
321321

322-
let linter = if use_nested_config {
323-
Linter::new_with_nested_configs(LintOptions::default(), lint_config, nested_configs)
322+
let linter = if nested_configs.is_empty() {
323+
Linter::new(LintOptions::default(), lint_config)
324324
.with_fix(fix_options.fix_kind())
325325
.with_report_unused_directives(report_unused_directives)
326326
} else {
327-
Linter::new(LintOptions::default(), lint_config)
327+
Linter::new_with_nested_configs(LintOptions::default(), lint_config, nested_configs)
328328
.with_fix(fix_options.fix_kind())
329329
.with_report_unused_directives(report_unused_directives)
330330
};
@@ -1133,4 +1133,11 @@ mod test {
11331133
.with_cwd("fixtures/cross_module_extended_config".into())
11341134
.test_and_snapshot(args);
11351135
}
1136+
1137+
#[test]
1138+
fn test_import_plugin_being_enabled_correctly() {
1139+
// https://github.com/oxc-project/oxc/pull/10597
1140+
let args = &["--import-plugin", "-D", "import/no-cycle"];
1141+
Tester::new().with_cwd("fixtures/import-cycle".into()).test_and_snapshot(args);
1142+
}
11361143
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
---
2+
source: apps/oxlint/src/tester.rs
3+
---
4+
##########
5+
arguments: --import-plugin -D import/no-cycle
6+
working directory: fixtures/import-cycle
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+
,-[a.ts:1:19]
11+
1 | import { B } from "./b";
12+
: ^^^^^
13+
2 |
14+
`----
15+
help: These paths form a cycle:
16+
-> ./b - fixtures/import-cycle/b.ts
17+
-> ./a - fixtures/import-cycle/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+
,-[b.ts:1:19]
21+
1 | import { A } from "./a";
22+
: ^^^^^
23+
2 |
24+
`----
25+
help: These paths form a cycle:
26+
-> ./a - fixtures/import-cycle/a.ts
27+
-> ./b - fixtures/import-cycle/b.ts
28+
29+
Found 0 warnings and 2 errors.
30+
Finished in <variable>ms on 2 files with 102 rules using 1 threads.
31+
----------
32+
CLI result: LintFoundErrors
33+
----------

0 commit comments

Comments
 (0)