Skip to content

Commit b0d3128

Browse files
committed
refactor(linter): decouple module resolution from import plugin
1 parent 85ac3f7 commit b0d3128

File tree

3 files changed

+17
-7
lines changed

3 files changed

+17
-7
lines changed

apps/oxlint/src/lint/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ impl Runner for LintRunner {
9898
let number_of_files = paths.len();
9999

100100
let cwd = std::env::current_dir().unwrap();
101-
let mut options = LintServiceOptions::new(cwd, paths);
101+
let mut options =
102+
LintServiceOptions::new(cwd, paths).with_cross_module(enable_plugins.import_plugin);
102103
let lint_options = OxlintOptions::default()
103104
.with_filter(filter)
104105
.with_config_path(basic_options.config)

crates/oxc_linter/src/service.rs

+14-5
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ pub struct LintServiceOptions {
3232

3333
/// TypeScript `tsconfig.json` path for reading path alias and project references
3434
tsconfig: Option<PathBuf>,
35+
36+
cross_module: bool,
3537
}
3638

3739
impl LintServiceOptions {
@@ -40,7 +42,7 @@ impl LintServiceOptions {
4042
where
4143
T: Into<Box<Path>>,
4244
{
43-
Self { cwd: cwd.into(), paths, tsconfig: None }
45+
Self { cwd: cwd.into(), paths, tsconfig: None, cross_module: false }
4446
}
4547

4648
#[inline]
@@ -58,6 +60,13 @@ impl LintServiceOptions {
5860
self
5961
}
6062

63+
#[inline]
64+
#[must_use]
65+
pub fn with_cross_module(mut self, cross_module: bool) -> Self {
66+
self.cross_module = cross_module;
67+
self
68+
}
69+
6170
#[inline]
6271
pub fn cwd(&self) -> &Path {
6372
&self.cwd
@@ -165,7 +174,7 @@ pub struct Runtime {
165174

166175
impl Runtime {
167176
fn new(linter: Linter, options: LintServiceOptions) -> Self {
168-
let resolver = linter.options().plugins.has_import().then(|| {
177+
let resolver = options.cross_module.then(|| {
169178
Self::get_resolver(options.tsconfig.or_else(|| Some(options.cwd.join("tsconfig.json"))))
170179
});
171180
Self {
@@ -310,7 +319,7 @@ impl Runtime {
310319
.build_module_record(path, program);
311320
let module_record = semantic_builder.module_record();
312321

313-
if self.linter.options().plugins.has_import() {
322+
if self.resolver.is_some() {
314323
self.module_map.insert(
315324
path.to_path_buf().into_boxed_path(),
316325
ModuleState::Resolved(Arc::clone(&module_record)),
@@ -392,7 +401,7 @@ impl Runtime {
392401
}
393402

394403
fn init_cache_state(&self, path: &Path) -> bool {
395-
if !self.linter.options().plugins.has_import() {
404+
if self.resolver.is_none() {
396405
return false;
397406
}
398407

@@ -447,7 +456,7 @@ impl Runtime {
447456
}
448457

449458
fn ignore_path(&self, path: &Path) {
450-
if self.linter.options().plugins.has_import() {
459+
if self.resolver.is_some() {
451460
self.module_map.insert(path.to_path_buf().into_boxed_path(), ModuleState::Ignored);
452461
self.update_cache_state(path);
453462
}

crates/oxc_linter/src/tester.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ impl Tester {
380380

381381
let cwd = self.current_working_directory.clone();
382382
let paths = vec![path_to_lint.into_boxed_path()];
383-
let options = LintServiceOptions::new(cwd, paths);
383+
let options = LintServiceOptions::new(cwd, paths).with_cross_module(self.plugins.import);
384384
let lint_service = LintService::from_linter(linter, options);
385385
let diagnostic_service = DiagnosticService::default();
386386
let tx_error = diagnostic_service.sender();

0 commit comments

Comments
 (0)