mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 12:19:15 +00:00
refactor(linter): decouple module resolution from import plugin (#5829)
closes #5815
This commit is contained in:
parent
85ac3f749a
commit
026ee6a7e8
3 changed files with 17 additions and 7 deletions
|
|
@ -98,7 +98,8 @@ impl Runner for LintRunner {
|
|||
let number_of_files = paths.len();
|
||||
|
||||
let cwd = std::env::current_dir().unwrap();
|
||||
let mut options = LintServiceOptions::new(cwd, paths);
|
||||
let mut options =
|
||||
LintServiceOptions::new(cwd, paths).with_cross_module(enable_plugins.import_plugin);
|
||||
let lint_options = OxlintOptions::default()
|
||||
.with_filter(filter)
|
||||
.with_config_path(basic_options.config)
|
||||
|
|
|
|||
|
|
@ -32,6 +32,8 @@ pub struct LintServiceOptions {
|
|||
|
||||
/// TypeScript `tsconfig.json` path for reading path alias and project references
|
||||
tsconfig: Option<PathBuf>,
|
||||
|
||||
cross_module: bool,
|
||||
}
|
||||
|
||||
impl LintServiceOptions {
|
||||
|
|
@ -40,7 +42,7 @@ impl LintServiceOptions {
|
|||
where
|
||||
T: Into<Box<Path>>,
|
||||
{
|
||||
Self { cwd: cwd.into(), paths, tsconfig: None }
|
||||
Self { cwd: cwd.into(), paths, tsconfig: None, cross_module: false }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
|
@ -58,6 +60,13 @@ impl LintServiceOptions {
|
|||
self
|
||||
}
|
||||
|
||||
#[inline]
|
||||
#[must_use]
|
||||
pub fn with_cross_module(mut self, cross_module: bool) -> Self {
|
||||
self.cross_module = cross_module;
|
||||
self
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn cwd(&self) -> &Path {
|
||||
&self.cwd
|
||||
|
|
@ -165,7 +174,7 @@ pub struct Runtime {
|
|||
|
||||
impl Runtime {
|
||||
fn new(linter: Linter, options: LintServiceOptions) -> Self {
|
||||
let resolver = linter.options().plugins.has_import().then(|| {
|
||||
let resolver = options.cross_module.then(|| {
|
||||
Self::get_resolver(options.tsconfig.or_else(|| Some(options.cwd.join("tsconfig.json"))))
|
||||
});
|
||||
Self {
|
||||
|
|
@ -310,7 +319,7 @@ impl Runtime {
|
|||
.build_module_record(path, program);
|
||||
let module_record = semantic_builder.module_record();
|
||||
|
||||
if self.linter.options().plugins.has_import() {
|
||||
if self.resolver.is_some() {
|
||||
self.module_map.insert(
|
||||
path.to_path_buf().into_boxed_path(),
|
||||
ModuleState::Resolved(Arc::clone(&module_record)),
|
||||
|
|
@ -392,7 +401,7 @@ impl Runtime {
|
|||
}
|
||||
|
||||
fn init_cache_state(&self, path: &Path) -> bool {
|
||||
if !self.linter.options().plugins.has_import() {
|
||||
if self.resolver.is_none() {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -447,7 +456,7 @@ impl Runtime {
|
|||
}
|
||||
|
||||
fn ignore_path(&self, path: &Path) {
|
||||
if self.linter.options().plugins.has_import() {
|
||||
if self.resolver.is_some() {
|
||||
self.module_map.insert(path.to_path_buf().into_boxed_path(), ModuleState::Ignored);
|
||||
self.update_cache_state(path);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -380,7 +380,7 @@ impl Tester {
|
|||
|
||||
let cwd = self.current_working_directory.clone();
|
||||
let paths = vec![path_to_lint.into_boxed_path()];
|
||||
let options = LintServiceOptions::new(cwd, paths);
|
||||
let options = LintServiceOptions::new(cwd, paths).with_cross_module(self.plugins.import);
|
||||
let lint_service = LintService::from_linter(linter, options);
|
||||
let diagnostic_service = DiagnosticService::default();
|
||||
let tx_error = diagnostic_service.sender();
|
||||
|
|
|
|||
Loading…
Reference in a new issue