@@ -509,7 +509,9 @@ struct TsGoLintDiagnosticPayload {
509509 pub range : Range ,
510510 pub rule : String ,
511511 pub message : RuleMessage ,
512+ #[ serde( default ) ]
512513 pub fixes : Vec < Fix > ,
514+ #[ serde( default ) ]
513515 pub suggestions : Vec < Suggestion > ,
514516 pub file_path : PathBuf ,
515517}
@@ -1030,4 +1032,75 @@ mod test {
10301032 ] )
10311033 ) ;
10321034 }
1035+
1036+ #[ test]
1037+ fn test_diagnostic_payload_deserialize_without_fixes_or_suggestions ( ) {
1038+ use super :: TsGoLintDiagnosticPayload ;
1039+
1040+ // Test payload with both fixes and suggestions omitted
1041+ let json = r#"{
1042+ "range": {"pos": 0, "end": 10},
1043+ "rule": "no-unused-vars",
1044+ "message": {
1045+ "id": "msg_id",
1046+ "description": "Variable is unused",
1047+ "help": null
1048+ },
1049+ "file_path": "test.ts"
1050+ }"# ;
1051+
1052+ let payload: TsGoLintDiagnosticPayload = serde_json:: from_str ( json) . unwrap ( ) ;
1053+ assert_eq ! ( payload. fixes. len( ) , 0 ) ;
1054+ assert_eq ! ( payload. suggestions. len( ) , 0 ) ;
1055+ assert_eq ! ( payload. rule, "no-unused-vars" ) ;
1056+
1057+ // Test payload with only fixes omitted
1058+ let json_with_suggestions = r#"{
1059+ "range": {"pos": 0, "end": 10},
1060+ "rule": "no-unused-vars",
1061+ "message": {
1062+ "id": "msg_id",
1063+ "description": "Variable is unused",
1064+ "help": null
1065+ },
1066+ "suggestions": [
1067+ {
1068+ "message": {
1069+ "id": "suggestion_id",
1070+ "description": "Remove unused variable",
1071+ "help": null
1072+ },
1073+ "fixes": []
1074+ }
1075+ ],
1076+ "file_path": "test.ts"
1077+ }"# ;
1078+
1079+ let payload: TsGoLintDiagnosticPayload =
1080+ serde_json:: from_str ( json_with_suggestions) . unwrap ( ) ;
1081+ assert_eq ! ( payload. fixes. len( ) , 0 ) ;
1082+ assert_eq ! ( payload. suggestions. len( ) , 1 ) ;
1083+
1084+ // Test payload with only suggestions omitted
1085+ let json_with_fixes = r#"{
1086+ "range": {"pos": 0, "end": 10},
1087+ "rule": "no-unused-vars",
1088+ "message": {
1089+ "id": "msg_id",
1090+ "description": "Variable is unused",
1091+ "help": null
1092+ },
1093+ "fixes": [
1094+ {
1095+ "text": "fixed",
1096+ "range": {"pos": 0, "end": 5}
1097+ }
1098+ ],
1099+ "file_path": "test.ts"
1100+ }"# ;
1101+
1102+ let payload: TsGoLintDiagnosticPayload = serde_json:: from_str ( json_with_fixes) . unwrap ( ) ;
1103+ assert_eq ! ( payload. fixes. len( ) , 1 ) ;
1104+ assert_eq ! ( payload. suggestions. len( ) , 0 ) ;
1105+ }
10331106}
0 commit comments