codeclimate: less memory allocation (#3882)

This commit is contained in:
Chaliy Roman Aleksandrovich 2023-06-04 08:59:04 +03:00 committed by GitHub
parent db881bee26
commit 8c519af80b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 8 deletions

View File

@ -2,7 +2,6 @@ package printers
import (
"encoding/json"
"fmt"
"io"
"github.com/golangci/golangci-lint/pkg/result"
@ -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
}

View File

@ -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())
}