Skip to content

Commit df3f83d

Browse files
committed
refactor(linter): simplify wrap_diagnostics by use Message.with_offset
1 parent 49633fe commit df3f83d

File tree

2 files changed

+10
-27
lines changed

2 files changed

+10
-27
lines changed

crates/oxc_diagnostics/src/service.rs

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use std::{
66
};
77

88
use cow_utils::CowUtils;
9-
use miette::LabeledSpan;
109
use percent_encoding::AsciiSet;
1110
#[cfg(not(windows))]
1211
use std::fs::canonicalize as strict_canonicalize;
@@ -122,7 +121,6 @@ impl DiagnosticService {
122121
cwd: C,
123122
path: P,
124123
source_text: &str,
125-
source_start: u32,
126124
diagnostics: Vec<OxcDiagnostic>,
127125
) -> Vec<Error> {
128126
// TODO: This causes snapshots to fail when running tests through a JetBrains terminal.
@@ -141,29 +139,7 @@ impl DiagnosticService {
141139
let source = Arc::new(NamedSource::new(path_display, source_text.to_owned()));
142140
diagnostics
143141
.into_iter()
144-
.map(|diagnostic| {
145-
if source_start == 0 {
146-
return diagnostic.with_source_code(Arc::clone(&source));
147-
}
148-
149-
match &diagnostic.labels {
150-
None => diagnostic.with_source_code(Arc::clone(&source)),
151-
Some(labels) => {
152-
let new_labels = labels
153-
.iter()
154-
.map(|labeled_span| {
155-
LabeledSpan::new(
156-
labeled_span.label().map(std::string::ToString::to_string),
157-
labeled_span.offset() + source_start as usize,
158-
labeled_span.len(),
159-
)
160-
})
161-
.collect::<Vec<_>>();
162-
163-
diagnostic.with_labels(new_labels).with_source_code(Arc::clone(&source))
164-
}
165-
}
166-
})
142+
.map(|diagnostic| diagnostic.with_source_code(Arc::clone(&source)))
167143
.collect()
168144
}
169145

crates/oxc_linter/src/service/runtime.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -554,12 +554,19 @@ impl Runtime {
554554
}
555555

556556
if !messages.is_empty() {
557-
let errors = messages.into_iter().map(Into::into).collect();
557+
let errors = messages
558+
.into_iter()
559+
.map(|mut message| {
560+
if section.source.start != 0 {
561+
message.with_offset(section.source.start);
562+
}
563+
message.into()
564+
})
565+
.collect();
558566
let diagnostics = DiagnosticService::wrap_diagnostics(
559567
&me.cwd,
560568
path,
561569
dep.source_text,
562-
section.source.start,
563570
errors,
564571
);
565572
tx_error.send((path.to_path_buf(), diagnostics)).unwrap();

0 commit comments

Comments
 (0)