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
6 changes: 3 additions & 3 deletions apps/oxlint/src/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,7 @@ impl Runner for LintRunner {
// the same functionality.
let use_cross_module = config_builder.plugins().has_import()
|| nested_configs.values().any(|config| config.plugins().has_import());
let mut options =
LintServiceOptions::new(self.cwd, paths).with_cross_module(use_cross_module);
let mut options = LintServiceOptions::new(self.cwd).with_cross_module(use_cross_module);

let lint_config = config_builder.build();

Expand Down Expand Up @@ -304,7 +303,8 @@ impl Runner for LintRunner {

// Spawn linting in another thread so diagnostics can be printed immediately from diagnostic_service.run.
rayon::spawn(move || {
let mut lint_service = LintService::new(&linter, allocator_pool, options);
let mut lint_service =
LintService::new(&linter, allocator_pool, options).with_paths(paths);

// Use `RawTransferFileSystem` if `oxlint2` feature is enabled.
// This reads the source text into start of allocator, instead of the end.
Expand Down
10 changes: 4 additions & 6 deletions crates/oxc_language_server/src/linter/isolated_lint_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,18 +138,16 @@ impl IsolatedLintHandler {

debug!("lint {}", path.display());

let lint_service_options = LintServiceOptions::new(
self.options.root_path.clone(),
vec![Arc::from(path.as_os_str())],
)
.with_cross_module(self.options.use_cross_module);
let lint_service_options = LintServiceOptions::new(self.options.root_path.clone())
.with_cross_module(self.options.use_cross_module);

let mut lint_service =
LintService::new(&self.linter, AllocatorPool::default(), lint_service_options)
.with_file_system(Box::new(IsolatedLintHandlerFileSystem::new(
path.to_path_buf(),
source_text,
)));
)))
.with_paths(vec![Arc::from(path.as_os_str())]);
let result = lint_service.run_source(allocator);

Some(result)
Expand Down
14 changes: 8 additions & 6 deletions crates/oxc_linter/src/service/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ pub mod offset_to_position;
pub struct LintServiceOptions {
/// Current working directory
cwd: Box<Path>,

/// All paths to lint
paths: Vec<Arc<OsStr>>,

/// TypeScript `tsconfig.json` path for reading path alias and project references
tsconfig: Option<PathBuf>,

Expand All @@ -30,11 +26,11 @@ pub struct LintServiceOptions {

impl LintServiceOptions {
#[must_use]
pub fn new<T>(cwd: T, paths: Vec<Arc<OsStr>>) -> Self
pub fn new<T>(cwd: T) -> Self
where
T: Into<Box<Path>>,
{
Self { cwd: cwd.into(), paths, tsconfig: None, cross_module: false }
Self { cwd: cwd.into(), tsconfig: None, cross_module: false }
}

#[inline]
Expand Down Expand Up @@ -88,6 +84,12 @@ impl<'l> LintService<'l> {
self
}

#[must_use]
pub fn with_paths(mut self, paths: Vec<Arc<OsStr>>) -> Self {
self.runtime = self.runtime.with_paths(paths);
self
}

/// # Panics
pub fn run(&mut self, tx_error: &DiagnosticSender) {
self.runtime.run(tx_error);
Expand Down
7 changes: 6 additions & 1 deletion crates/oxc_linter/src/service/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ impl<'l> Runtime<'l> {
Self {
allocator_pool,
cwd: options.cwd,
paths: options.paths.iter().cloned().collect(),
paths: IndexSet::with_capacity_and_hasher(0, FxBuildHasher),
linter,
resolver,
file_system: Box::new(OsFileSystem),
Expand All @@ -203,6 +203,11 @@ impl<'l> Runtime<'l> {
self
}

pub fn with_paths(mut self, paths: Vec<Arc<OsStr>>) -> Self {
self.paths = paths.into_iter().collect();
self
}

fn get_resolver(tsconfig_path: Option<PathBuf>) -> Resolver {
use oxc_resolver::{ResolveOptions, TsconfigOptions, TsconfigReferences};
let tsconfig = tsconfig_path.and_then(|path| {
Expand Down
13 changes: 7 additions & 6 deletions crates/oxc_linter/src/tester.rs
Original file line number Diff line number Diff line change
Expand Up @@ -537,12 +537,13 @@ impl Tester {

let cwd = self.current_working_directory.clone();
let paths = vec![Arc::<OsStr>::from(path_to_lint.as_os_str())];
let options =
LintServiceOptions::new(cwd, paths).with_cross_module(self.plugins.has_import());
let mut lint_service =
LintService::new(&linter, AllocatorPool::default(), options).with_file_system(
Box::new(TesterFileSystem::new(path_to_lint, source_text.to_string())),
);
let options = LintServiceOptions::new(cwd).with_cross_module(self.plugins.has_import());
let mut lint_service = LintService::new(&linter, AllocatorPool::default(), options)
.with_file_system(Box::new(TesterFileSystem::new(
path_to_lint,
source_text.to_string(),
)))
.with_paths(paths);

let (sender, _receiver) = mpsc::channel();
let result = lint_service.run_test_source(&allocator, false, &sender);
Expand Down
Loading