From 23660c936119c0128f3118a44a85aabf9acde8a5 Mon Sep 17 00:00:00 2001 From: camchenry <1514176+camchenry@users.noreply.github.com> Date: Wed, 29 Oct 2025 15:11:42 +0000 Subject: [PATCH] feat(linter): `tsgolint`: handle omitted fixes and suggestions (#15047) In preparation for https://github.com/oxc-project/tsgolint/pull/317. Enables oxlint to support missing fixes/suggestions in the payload from tsgolint. --- crates/oxc_linter/src/tsgolint.rs | 73 +++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/crates/oxc_linter/src/tsgolint.rs b/crates/oxc_linter/src/tsgolint.rs index fe75a522ff1c3..d78cb1e49948b 100644 --- a/crates/oxc_linter/src/tsgolint.rs +++ b/crates/oxc_linter/src/tsgolint.rs @@ -509,7 +509,9 @@ struct TsGoLintDiagnosticPayload { pub range: Range, pub rule: String, pub message: RuleMessage, + #[serde(default)] pub fixes: Vec, + #[serde(default)] pub suggestions: Vec, pub file_path: PathBuf, } @@ -1030,4 +1032,75 @@ mod test { ]) ); } + + #[test] + fn test_diagnostic_payload_deserialize_without_fixes_or_suggestions() { + use super::TsGoLintDiagnosticPayload; + + // Test payload with both fixes and suggestions omitted + let json = r#"{ + "range": {"pos": 0, "end": 10}, + "rule": "no-unused-vars", + "message": { + "id": "msg_id", + "description": "Variable is unused", + "help": null + }, + "file_path": "test.ts" + }"#; + + let payload: TsGoLintDiagnosticPayload = serde_json::from_str(json).unwrap(); + assert_eq!(payload.fixes.len(), 0); + assert_eq!(payload.suggestions.len(), 0); + assert_eq!(payload.rule, "no-unused-vars"); + + // Test payload with only fixes omitted + let json_with_suggestions = r#"{ + "range": {"pos": 0, "end": 10}, + "rule": "no-unused-vars", + "message": { + "id": "msg_id", + "description": "Variable is unused", + "help": null + }, + "suggestions": [ + { + "message": { + "id": "suggestion_id", + "description": "Remove unused variable", + "help": null + }, + "fixes": [] + } + ], + "file_path": "test.ts" + }"#; + + let payload: TsGoLintDiagnosticPayload = + serde_json::from_str(json_with_suggestions).unwrap(); + assert_eq!(payload.fixes.len(), 0); + assert_eq!(payload.suggestions.len(), 1); + + // Test payload with only suggestions omitted + let json_with_fixes = r#"{ + "range": {"pos": 0, "end": 10}, + "rule": "no-unused-vars", + "message": { + "id": "msg_id", + "description": "Variable is unused", + "help": null + }, + "fixes": [ + { + "text": "fixed", + "range": {"pos": 0, "end": 5} + } + ], + "file_path": "test.ts" + }"#; + + let payload: TsGoLintDiagnosticPayload = serde_json::from_str(json_with_fixes).unwrap(); + assert_eq!(payload.fixes.len(), 1); + assert_eq!(payload.suggestions.len(), 0); + } }