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
12 changes: 5 additions & 7 deletions apps/oxlint/src/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,18 +293,16 @@ impl Runner for LintRunner {
}
}

let mut lint_service = LintService::new(linter, options);
let mut diagnostic_service =
Self::get_diagnostic_service(&output_formatter, &warning_options, &misc_options);
let tx_error = diagnostic_service.sender().clone();

let number_of_rules = lint_service.linter().number_of_rules();
let number_of_rules = linter.number_of_rules();

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

let diagnostic_result = diagnostic_service.run(stdout);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,9 @@ impl IsolatedLintHandler {
vec![Arc::from(path.as_os_str())],
)
.with_cross_module(self.options.use_cross_module);
// ToDo: do not clone the linter

let mut lint_service =
LintService::new(self.linter.clone(), lint_service_options).with_file_system(Box::new(
LintService::new(&self.linter, lint_service_options).with_file_system(Box::new(
IsolatedLintHandlerFileSystem::new(path.to_path_buf(), source_text),
));
let result = lint_service.run_source(allocator);
Expand Down
12 changes: 4 additions & 8 deletions crates/oxc_linter/src/service/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ impl LintServiceOptions {
}
}

pub struct LintService {
runtime: Runtime,
pub struct LintService<'l> {
runtime: Runtime<'l>,
}

impl LintService {
pub fn new(linter: Linter, options: LintServiceOptions) -> Self {
impl<'l> LintService<'l> {
pub fn new(linter: &'l Linter, options: LintServiceOptions) -> Self {
let runtime = Runtime::new(linter, options);
Self { runtime }
}
Expand All @@ -84,10 +84,6 @@ impl LintService {
self
}

pub fn linter(&self) -> &Linter {
&self.runtime.linter
}

/// # Panics
pub fn run(&mut self, tx_error: &DiagnosticSender) {
self.runtime.run(tx_error);
Expand Down
8 changes: 4 additions & 4 deletions crates/oxc_linter/src/service/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ use crate::fixer::{FixWithPosition, MessageWithPosition};
#[cfg(feature = "language_server")]
use crate::service::offset_to_position::{SpanPositionMessage, offset_to_position};

pub struct Runtime {
pub struct Runtime<'l> {
cwd: Box<Path>,
/// All paths to lint
paths: IndexSet<Arc<OsStr>, FxBuildHasher>,
pub(super) linter: Linter,
pub(super) linter: &'l Linter,
resolver: Option<Resolver>,

pub(super) file_system: Box<dyn RuntimeFileSystem + Sync + Send>,
Expand Down Expand Up @@ -163,8 +163,8 @@ impl RuntimeFileSystem for OsFileSystem {
}
}

impl Runtime {
pub(super) fn new(linter: Linter, options: LintServiceOptions) -> Self {
impl<'l> Runtime<'l> {
pub(super) fn new(linter: &'l Linter, options: LintServiceOptions) -> Self {
let resolver = options.cross_module.then(|| {
Self::get_resolver(options.tsconfig.or_else(|| Some(options.cwd.join("tsconfig.json"))))
});
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_linter/src/tester.rs
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ impl Tester {
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, options).with_file_system(Box::new(
let mut lint_service = LintService::new(&linter, options).with_file_system(Box::new(
TesterFileSystem::new(path_to_lint, source_text.to_string()),
));

Expand Down
Loading