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
2 changes: 1 addition & 1 deletion crates/oxc_linter/src/fixer/fix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ impl<'a> CompositeFix<'a> {
/// 3. contains negative ranges (span.start > span.end)
///
/// <https://github.com/eslint/eslint/blob/v9.9.1/lib/linter/report-translator.js#L147-L179>
fn merge_fixes(fixes: Vec<Fix<'a>>, source_text: &str) -> Fix<'a> {
pub fn merge_fixes(fixes: Vec<Fix<'a>>, source_text: &str) -> Fix<'a> {
let mut fixes = fixes;
if fixes.is_empty() {
// Do nothing
Expand Down
26 changes: 25 additions & 1 deletion crates/oxc_linter/src/tsgolint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ use serde::{Deserialize, Serialize};
use oxc_diagnostics::{DiagnosticSender, DiagnosticService, OxcDiagnostic, Severity};
use oxc_span::{SourceType, Span};

use crate::fixer::{CompositeFix, Message, PossibleFixes};

use super::{AllowWarnDeny, ConfigStore, ResolvedLinterState, read_to_string};

/// State required to initialize the `tsgolint` linter.
Expand Down Expand Up @@ -294,7 +296,7 @@ struct TsGoLintDiagnosticPayload {
pub file_path: PathBuf,
}

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

impl Message<'_> {
/// Converts a `TsGoLintDiagnostic` into a `Message` with possible fixes.
#[expect(dead_code)]
fn from_tsgo_lint_diagnostic(val: TsGoLintDiagnostic, source_text: &str) -> Self {
let possible_fix = if val.fixes.is_empty() {
PossibleFixes::None
} else {
let fixes = val
.fixes
.iter()
.map(|fix| crate::fixer::Fix {
content: fix.text.clone().into(),
span: Span::new(fix.range.pos, fix.range.end),
message: None,
})
.collect();
PossibleFixes::Single(CompositeFix::merge_fixes(fixes, source_text))
};

Self::new(val.into(), possible_fix)
}
}
// TODO: Should this be removed and replaced with a `Span`?
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct Range {
Expand Down
Loading