Skip to content

Commit 8c519af

Browse files
authored
codeclimate: less memory allocation (#3882)
1 parent db881be commit 8c519af

File tree

2 files changed

+3
-8
lines changed

2 files changed

+3
-8
lines changed

pkg/printers/codeclimate.go

+1-7
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package printers
22

33
import (
44
"encoding/json"
5-
"fmt"
65
"io"
76

87
"github.com/golangci/golangci-lint/pkg/result"
@@ -52,12 +51,7 @@ func (p CodeClimate) Print(issues []result.Issue) error {
5251
codeClimateIssues = append(codeClimateIssues, codeClimateIssue)
5352
}
5453

55-
outputJSON, err := json.Marshal(codeClimateIssues)
56-
if err != nil {
57-
return err
58-
}
59-
60-
_, err = fmt.Fprint(p.w, string(outputJSON))
54+
err := json.NewEncoder(p.w).Encode(codeClimateIssues)
6155
if err != nil {
6256
return err
6357
}

pkg/printers/codeclimate_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ func TestCodeClimate_Print(t *testing.T) {
6464
require.NoError(t, err)
6565

6666
//nolint:lll
67-
expected := `[{"description":"linter-a: some issue","severity":"warning","fingerprint":"BA73C5DF4A6FD8462FFF1D3140235777","location":{"path":"path/to/filea.go","lines":{"begin":10}}},{"description":"linter-b: another issue","severity":"error","fingerprint":"0777B4FE60242BD8B2E9B7E92C4B9521","location":{"path":"path/to/fileb.go","lines":{"begin":300}}},{"description":"linter-c: issue c","severity":"critical","fingerprint":"BEE6E9FBB6BFA4B7DB9FB036697FB036","location":{"path":"path/to/filec.go","lines":{"begin":200}}}]`
67+
expected := `[{"description":"linter-a: some issue","severity":"warning","fingerprint":"BA73C5DF4A6FD8462FFF1D3140235777","location":{"path":"path/to/filea.go","lines":{"begin":10}}},{"description":"linter-b: another issue","severity":"error","fingerprint":"0777B4FE60242BD8B2E9B7E92C4B9521","location":{"path":"path/to/fileb.go","lines":{"begin":300}}},{"description":"linter-c: issue c","severity":"critical","fingerprint":"BEE6E9FBB6BFA4B7DB9FB036697FB036","location":{"path":"path/to/filec.go","lines":{"begin":200}}}]
68+
`
6869

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

0 commit comments

Comments
 (0)