@@ -514,7 +514,9 @@ struct TsGoLintDiagnosticPayload {
514514 pub range : Range ,
515515 pub rule : String ,
516516 pub message : RuleMessage ,
517+ #[ serde( default ) ]
517518 pub fixes : Vec < Fix > ,
519+ #[ serde( default ) ]
518520 pub suggestions : Vec < Suggestion > ,
519521 pub file_path : PathBuf ,
520522}
@@ -1020,4 +1022,75 @@ mod test {
10201022 ] )
10211023 ) ;
10221024 }
1025+
1026+ #[ test]
1027+ fn test_diagnostic_payload_deserialize_without_fixes_or_suggestions ( ) {
1028+ use super :: TsGoLintDiagnosticPayload ;
1029+
1030+ // Test payload with both fixes and suggestions omitted
1031+ let json = r#"{
1032+ "range": {"pos": 0, "end": 10},
1033+ "rule": "no-unused-vars",
1034+ "message": {
1035+ "id": "msg_id",
1036+ "description": "Variable is unused",
1037+ "help": null
1038+ },
1039+ "file_path": "test.ts"
1040+ }"# ;
1041+
1042+ let payload: TsGoLintDiagnosticPayload = serde_json:: from_str ( json) . unwrap ( ) ;
1043+ assert_eq ! ( payload. fixes. len( ) , 0 ) ;
1044+ assert_eq ! ( payload. suggestions. len( ) , 0 ) ;
1045+ assert_eq ! ( payload. rule, "no-unused-vars" ) ;
1046+
1047+ // Test payload with only fixes omitted
1048+ let json_with_suggestions = r#"{
1049+ "range": {"pos": 0, "end": 10},
1050+ "rule": "no-unused-vars",
1051+ "message": {
1052+ "id": "msg_id",
1053+ "description": "Variable is unused",
1054+ "help": null
1055+ },
1056+ "suggestions": [
1057+ {
1058+ "message": {
1059+ "id": "suggestion_id",
1060+ "description": "Remove unused variable",
1061+ "help": null
1062+ },
1063+ "fixes": []
1064+ }
1065+ ],
1066+ "file_path": "test.ts"
1067+ }"# ;
1068+
1069+ let payload: TsGoLintDiagnosticPayload =
1070+ serde_json:: from_str ( json_with_suggestions) . unwrap ( ) ;
1071+ assert_eq ! ( payload. fixes. len( ) , 0 ) ;
1072+ assert_eq ! ( payload. suggestions. len( ) , 1 ) ;
1073+
1074+ // Test payload with only suggestions omitted
1075+ let json_with_fixes = r#"{
1076+ "range": {"pos": 0, "end": 10},
1077+ "rule": "no-unused-vars",
1078+ "message": {
1079+ "id": "msg_id",
1080+ "description": "Variable is unused",
1081+ "help": null
1082+ },
1083+ "fixes": [
1084+ {
1085+ "text": "fixed",
1086+ "range": {"pos": 0, "end": 5}
1087+ }
1088+ ],
1089+ "file_path": "test.ts"
1090+ }"# ;
1091+
1092+ let payload: TsGoLintDiagnosticPayload = serde_json:: from_str ( json_with_fixes) . unwrap ( ) ;
1093+ assert_eq ! ( payload. fixes. len( ) , 1 ) ;
1094+ assert_eq ! ( payload. suggestions. len( ) , 0 ) ;
1095+ }
10231096}
0 commit comments