Skip to content

Commit

Permalink
fix: init empty result slice for SARIF printer (#4758)
Browse files Browse the repository at this point in the history
Co-authored-by: Fernandez Ludovic <[email protected]>
  • Loading branch information
Zxilly and ldez committed May 27, 2024
1 parent 6456cbd commit 8173166
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions pkg/printers/sarif.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ func NewSarif(w io.Writer) *Sarif {
func (p Sarif) Print(issues []result.Issue) error {
run := sarifRun{}
run.Tool.Driver.Name = "golangci-lint"
run.Results = make([]sarifResult, 0)

for i := range issues {
issue := issues[i]
Expand Down
14 changes: 14 additions & 0 deletions pkg/printers/sarif_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,17 @@ func TestSarif_Print(t *testing.T) {

assert.Equal(t, expected, buf.String())
}

func TestSarif_Print_empty(t *testing.T) {
buf := new(bytes.Buffer)

printer := NewSarif(buf)

err := printer.Print(nil)
require.NoError(t, err)

expected := `{"version":"2.1.0","$schema":"https://schemastore.azurewebsites.net/schemas/json/sarif-2.1.0-rtm.6.json","runs":[{"tool":{"driver":{"name":"golangci-lint"}},"results":[]}]}
`

assert.Equal(t, expected, buf.String())
}

0 comments on commit 8173166

Please sign in to comment.