Skip to content
Closed
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
2 changes: 2 additions & 0 deletions crates/oxc_linter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

use std::{path::Path, rc::Rc, sync::Arc};

use oxc_allocator::Allocator;
use oxc_diagnostics::OxcDiagnostic;
use oxc_semantic::{AstNode, Semantic};
use oxc_span::Span;
Expand Down Expand Up @@ -117,6 +118,7 @@ impl Linter {
path: &Path,
semantic: Rc<Semantic<'a>>,
module_record: Arc<ModuleRecord>,
_allocator: &Allocator,
) -> Vec<Message<'a>> {
let ResolvedLinterState { rules, config, external_rules } = self.config.resolve(path);

Expand Down
9 changes: 6 additions & 3 deletions crates/oxc_linter/src/service/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ impl Runtime {
pub(super) fn run(&mut self, tx_error: &DiagnosticSender) {
rayon::scope(|scope| {
self.resolve_modules(scope, true, tx_error, |me, mut module_to_lint| {
module_to_lint.content.with_dependent_mut(|_allocator_guard, dep| {
module_to_lint.content.with_dependent_mut(|allocator_guard, dep| {
// If there are fixes, we will accumulate all of them and write to the file at the end.
// This means we do not write multiple times to the same file if there are multiple sources
// in the same file (for example, multiple scripts in an `.astro` file).
Expand All @@ -524,6 +524,7 @@ impl Runtime {
path,
Rc::new(section.semantic.unwrap()),
Arc::clone(&module_record),
allocator_guard,
),
Err(errors) => errors
.into_iter()
Expand Down Expand Up @@ -613,7 +614,7 @@ impl Runtime {
rayon::scope(|scope| {
self.resolve_modules(scope, true, &sender, |me, mut module| {
module.content.with_dependent_mut(
|_allocator_guard, ModuleContentDependent { source_text, section_contents }| {
|allocator_guard, ModuleContentDependent { source_text, section_contents }| {
assert_eq!(module.section_module_records.len(), section_contents.len());

let rope = &Rope::from_str(source_text);
Expand All @@ -634,6 +635,7 @@ impl Runtime {
Path::new(&module.path),
Rc::new(section.semantic.unwrap()),
Arc::clone(&module_record),
allocator_guard,
);

messages.lock().unwrap().extend(section_message.iter().map(
Expand Down Expand Up @@ -750,7 +752,7 @@ impl Runtime {
rayon::scope(|scope| {
self.resolve_modules(scope, check_syntax_errors, tx_error, |me, mut module| {
module.content.with_dependent_mut(
|_allocator_guard, ModuleContentDependent { source_text: _, section_contents }| {
|allocator_guard, ModuleContentDependent { source_text: _, section_contents }| {
assert_eq!(module.section_module_records.len(), section_contents.len());
for (record_result, section) in module
.section_module_records
Expand All @@ -763,6 +765,7 @@ impl Runtime {
Path::new(&module.path),
Rc::new(section.semantic.unwrap()),
Arc::clone(&module_record),
allocator_guard,
),
Err(errors) => errors
.into_iter()
Expand Down
12 changes: 10 additions & 2 deletions napi/playground/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,14 @@ impl Oxc {
}

let linter_module_record = Arc::new(ModuleRecord::new(&path, &module_record, &semantic));
self.run_linter(&run_options, &linter_options, &path, &program, &linter_module_record);
self.run_linter(
&run_options,
&linter_options,
&path,
&program,
&linter_module_record,
&allocator,
);

self.run_formatter(&run_options, &source_text, source_type);

Expand Down Expand Up @@ -282,6 +289,7 @@ impl Oxc {
path: &Path,
program: &Program,
module_record: &Arc<ModuleRecord>,
allocator: &Allocator,
) {
// Only lint if there are no syntax errors
if run_options.lint.unwrap_or_default() && self.diagnostics.is_empty() {
Expand All @@ -307,7 +315,7 @@ impl Oxc {
ConfigStore::new(lint_config, FxHashMap::default(), ExternalPluginStore::default()),
None,
)
.run(path, Rc::clone(&semantic), Arc::clone(module_record));
.run(path, Rc::clone(&semantic), Arc::clone(module_record), allocator);
self.diagnostics.extend(linter_ret.into_iter().map(|e| e.error));
}
}
Expand Down
4 changes: 3 additions & 1 deletion tasks/benchmark/benches/linter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ fn bench_linter(criterion: &mut Criterion) {
)
.with_fix(FixKind::All);
group.bench_function(id, |b| {
b.iter(|| linter.run(path, Rc::clone(&semantic), Arc::clone(&module_record)));
b.iter(|| {
linter.run(path, Rc::clone(&semantic), Arc::clone(&module_record), &allocator)
});
});
}
group.finish();
Expand Down
Loading