Skip to content

Commit

Permalink
codeclimate: less memory allocation (#3882)
Browse files Browse the repository at this point in the history
  • Loading branch information
lasiar authored Jun 4, 2023
1 parent db881be commit 8c519af
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 8 deletions.
8 changes: 1 addition & 7 deletions pkg/printers/codeclimate.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package printers

import (
"encoding/json"
"fmt"
"io"

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

outputJSON, err := json.Marshal(codeClimateIssues)
if err != nil {
return err
}

_, err = fmt.Fprint(p.w, string(outputJSON))
err := json.NewEncoder(p.w).Encode(codeClimateIssues)
if err != nil {
return err
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/printers/codeclimate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ func TestCodeClimate_Print(t *testing.T) {
require.NoError(t, err)

//nolint:lll
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}}}]`
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}}}]
`

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

0 comments on commit 8c519af

Please sign in to comment.