Skip to content

Commit 8173166

Browse files
Zxillyldez
andauthored
fix: init empty result slice for SARIF printer (#4758)
Co-authored-by: Fernandez Ludovic <[email protected]>
1 parent 6456cbd commit 8173166

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

pkg/printers/sarif.go

+1
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ func NewSarif(w io.Writer) *Sarif {
7070
func (p Sarif) Print(issues []result.Issue) error {
7171
run := sarifRun{}
7272
run.Tool.Driver.Name = "golangci-lint"
73+
run.Results = make([]sarifResult, 0)
7374

7475
for i := range issues {
7576
issue := issues[i]

pkg/printers/sarif_test.go

+14
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,17 @@ func TestSarif_Print(t *testing.T) {
6565

6666
assert.Equal(t, expected, buf.String())
6767
}
68+
69+
func TestSarif_Print_empty(t *testing.T) {
70+
buf := new(bytes.Buffer)
71+
72+
printer := NewSarif(buf)
73+
74+
err := printer.Print(nil)
75+
require.NoError(t, err)
76+
77+
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":[]}]}
78+
`
79+
80+
assert.Equal(t, expected, buf.String())
81+
}

0 commit comments

Comments
 (0)