@@ -4,8 +4,8 @@ use std::{
44 path:: Path ,
55} ;
66
7+ use ruff_source_file:: LineColumn ;
78use serde:: { Serialize , Serializer , ser:: SerializeSeq } ;
8- use serde_json:: json;
99
1010use crate :: diagnostic:: Diagnostic ;
1111
@@ -98,21 +98,21 @@ impl Serialize for SerializedMessages<'_> {
9898 let description = diagnostic. body ( ) ;
9999 let check_name = diagnostic. secondary_code_or_id ( ) ;
100100
101- let value = json ! ( {
102- "check_name" : check_name,
101+ let value = Message {
102+ check_name,
103103 // GitLab doesn't display the separate `check_name` field in a Code Quality report,
104104 // so prepend it to the description too.
105- " description" : format!( "{check_name}: {description}" ) ,
106- " severity" : "major" ,
107- " fingerprint" : format!( "{:x}" , message_fingerprint) ,
108- " location" : {
109- "path" : path,
110- " positions" : {
111- " begin" : start_location,
112- " end" : end_location,
105+ description : format ! ( "{check_name}: {description}" ) ,
106+ severity : "major" ,
107+ fingerprint : format ! ( "{:x}" , message_fingerprint) ,
108+ location : Location {
109+ path,
110+ positions : Position {
111+ begin : start_location,
112+ end : end_location,
113113 } ,
114114 } ,
115- } ) ;
115+ } ;
116116
117117 s. serialize_element ( & value) ?;
118118 }
@@ -122,6 +122,27 @@ impl Serialize for SerializedMessages<'_> {
122122 }
123123}
124124
125+ #[ derive( Serialize ) ]
126+ struct Message < ' a > {
127+ check_name : & ' a str ,
128+ description : String ,
129+ severity : & ' static str ,
130+ fingerprint : String ,
131+ location : Location ,
132+ }
133+
134+ #[ derive( Serialize ) ]
135+ struct Location {
136+ path : String ,
137+ positions : Position ,
138+ }
139+
140+ #[ derive( Serialize ) ]
141+ struct Position {
142+ begin : LineColumn ,
143+ end : LineColumn ,
144+ }
145+
125146/// Generate a unique fingerprint to identify a violation.
126147fn fingerprint ( message : & Diagnostic , project_path : & str , salt : u64 ) -> u64 {
127148 let mut hasher = DefaultHasher :: new ( ) ;
0 commit comments