@@ -180,27 +180,39 @@ func convertToSonarIssues(rootPaths []string, data *reportInfo) (*sonarIssues, e
180
180
func convertToSarifReport (rootPaths []string , data * reportInfo ) (* sarifReport , error ) {
181
181
sr := buildSarifReport ()
182
182
183
- var rules []* sarifRule
184
- var locations []* sarifLocation
183
+ type rule struct {
184
+ index int
185
+ rule * sarifRule
186
+ }
187
+
188
+ rules := make ([]* sarifRule , 0 )
189
+ rulesIndices := make (map [string ]rule )
190
+ lastRuleIndex := - 1
191
+
185
192
results := []* sarifResult {}
186
193
187
- for index , issue := range data .Issues {
188
- rules = append (rules , buildSarifRule (issue ))
194
+ for _ , issue := range data .Issues {
195
+ r , ok := rulesIndices [issue .RuleID ]
196
+ if ! ok {
197
+ lastRuleIndex ++
198
+ r = rule {index : lastRuleIndex , rule : buildSarifRule (issue )}
199
+ rulesIndices [issue .RuleID ] = r
200
+ rules = append (rules , r .rule )
201
+ }
189
202
190
203
location , err := buildSarifLocation (issue , rootPaths )
191
204
if err != nil {
192
205
return nil , err
193
206
}
194
- locations = append (locations , location )
195
207
196
208
result := & sarifResult {
197
- RuleID : fmt . Sprintf ( "%s (CWE-%s)" , issue . RuleID , issue . Cwe . ID ) ,
198
- RuleIndex : index ,
209
+ RuleID : r . rule . ID ,
210
+ RuleIndex : r . index ,
199
211
Level : getSarifLevel (issue .Severity .String ()),
200
212
Message : & sarifMessage {
201
213
Text : issue .What ,
202
214
},
203
- Locations : locations ,
215
+ Locations : [] * sarifLocation { location } ,
204
216
}
205
217
206
218
results = append (results , result )
@@ -209,6 +221,7 @@ func convertToSarifReport(rootPaths []string, data *reportInfo) (*sarifReport, e
209
221
tool := & sarifTool {
210
222
Driver : & sarifDriver {
211
223
Name : "gosec" ,
224
+ Version : "2.1.0" ,
212
225
InformationURI : "https://github.com/securego/gosec/" ,
213
226
Rules : rules ,
214
227
},
0 commit comments