Skip to content

Commit 0f8e4b1

Browse files
committed
refactor(linter): add impl for TsGoLintDiagnostic into Message
1 parent ecc9c60 commit 0f8e4b1

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

crates/oxc_linter/src/fixer/fix.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ impl<'a> CompositeFix<'a> {
550550
/// 3. contains negative ranges (span.start > span.end)
551551
///
552552
/// <https://github.com/eslint/eslint/blob/v9.9.1/lib/linter/report-translator.js#L147-L179>
553-
fn merge_fixes(fixes: Vec<Fix<'a>>, source_text: &str) -> Fix<'a> {
553+
pub fn merge_fixes(fixes: Vec<Fix<'a>>, source_text: &str) -> Fix<'a> {
554554
let mut fixes = fixes;
555555
if fixes.is_empty() {
556556
// Do nothing

crates/oxc_linter/src/tsgolint.rs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ use serde::{Deserialize, Serialize};
1111
use oxc_diagnostics::{DiagnosticSender, DiagnosticService, OxcDiagnostic, Severity};
1212
use oxc_span::{SourceType, Span};
1313

14+
use crate::fixer::{CompositeFix, Message, PossibleFixes};
15+
1416
use super::{AllowWarnDeny, ConfigStore, ResolvedLinterState, read_to_string};
1517

1618
/// State required to initialize the `tsgolint` linter.
@@ -294,7 +296,7 @@ struct TsGoLintDiagnosticPayload {
294296
pub file_path: PathBuf,
295297
}
296298

297-
/// Represents a message from `tsgolint`, ready to be converted into [`OxcDiagnostic`].
299+
/// Represents a message from `tsgolint`, ready to be converted into [`OxcDiagnostic`] or [`Message`].
298300
#[derive(Debug, Clone)]
299301
pub struct TsGoLintDiagnostic {
300302
pub r#type: MessageType,
@@ -318,6 +320,28 @@ impl From<TsGoLintDiagnostic> for OxcDiagnostic {
318320
}
319321
}
320322

323+
impl Message<'_> {
324+
/// Converts a `TsGoLintDiagnostic` into a `Message` with possible fixes.
325+
#[expect(dead_code)]
326+
fn from_tsgo_lint_diagnostic(val: TsGoLintDiagnostic, source_text: &str) -> Self {
327+
let possible_fix = if val.fixes.is_empty() {
328+
PossibleFixes::None
329+
} else {
330+
let fixes = val
331+
.fixes
332+
.iter()
333+
.map(|fix| crate::fixer::Fix {
334+
content: fix.text.clone().into(),
335+
span: Span::new(fix.range.pos, fix.range.end),
336+
message: None,
337+
})
338+
.collect();
339+
PossibleFixes::Single(CompositeFix::merge_fixes(fixes, source_text))
340+
};
341+
342+
Self::new(val.into(), possible_fix)
343+
}
344+
}
321345
// TODO: Should this be removed and replaced with a `Span`?
322346
#[derive(Clone, Debug, Serialize, Deserialize)]
323347
pub struct Range {

0 commit comments

Comments
 (0)