code-climate: add default severity (#3294)

Co-authored-by: Fernandez Ludovic <ldez@users.noreply.github.com>
This commit is contained in:
sink 2022-10-21 05:18:24 +08:00 committed by GitHub
parent c1e24c1507
commit 6740559b13
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 26 additions and 6 deletions

View File

@ -12,6 +12,8 @@ import (
"github.com/golangci/golangci-lint/pkg/result" "github.com/golangci/golangci-lint/pkg/result"
) )
const defaultCheckstyleSeverity = "error"
type checkstyleOutput struct { type checkstyleOutput struct {
XMLName xml.Name `xml:"checkstyle"` XMLName xml.Name `xml:"checkstyle"`
Version string `xml:"version,attr"` Version string `xml:"version,attr"`
@ -31,8 +33,6 @@ type checkstyleError struct {
Source string `xml:"source,attr"` Source string `xml:"source,attr"`
} }
const defaultCheckstyleSeverity = "error"
type Checkstyle struct { type Checkstyle struct {
w io.Writer w io.Writer
} }

View File

@ -9,8 +9,12 @@ import (
"github.com/golangci/golangci-lint/pkg/result" "github.com/golangci/golangci-lint/pkg/result"
) )
// CodeClimateIssue is a subset of the Code Climate spec - https://github.com/codeclimate/spec/blob/master/SPEC.md#data-types const defaultCodeClimateSeverity = "critical"
// It is just enough to support GitLab CI Code Quality - https://docs.gitlab.com/ee/user/project/merge_requests/code_quality.html
// CodeClimateIssue is a subset of the Code Climate spec.
// https://github.com/codeclimate/platform/blob/master/spec/analyzers/SPEC.md#data-types
// It is just enough to support GitLab CI Code Quality.
// https://docs.gitlab.com/ee/user/project/merge_requests/code_quality.html
type CodeClimateIssue struct { type CodeClimateIssue struct {
Description string `json:"description"` Description string `json:"description"`
Severity string `json:"severity,omitempty"` Severity string `json:"severity,omitempty"`
@ -40,6 +44,7 @@ func (p CodeClimate) Print(ctx context.Context, issues []result.Issue) error {
codeClimateIssue.Location.Path = issue.Pos.Filename codeClimateIssue.Location.Path = issue.Pos.Filename
codeClimateIssue.Location.Lines.Begin = issue.Pos.Line codeClimateIssue.Location.Lines.Begin = issue.Pos.Line
codeClimateIssue.Fingerprint = issue.Fingerprint() codeClimateIssue.Fingerprint = issue.Fingerprint()
codeClimateIssue.Severity = defaultCodeClimateSeverity
if issue.Severity != "" { if issue.Severity != "" {
codeClimateIssue.Severity = issue.Severity codeClimateIssue.Severity = issue.Severity

View File

@ -1,4 +1,3 @@
//nolint:dupl
package printers package printers
import ( import (
@ -42,6 +41,21 @@ func TestCodeClimate_Print(t *testing.T) {
Column: 9, Column: 9,
}, },
}, },
{
FromLinter: "linter-c",
Text: "issue c",
SourceLines: []string{
"func foo() {",
"\tfmt.Println(\"ccc\")",
"}",
},
Pos: token.Position{
Filename: "path/to/filec.go",
Offset: 6,
Line: 200,
Column: 2,
},
},
} }
buf := new(bytes.Buffer) buf := new(bytes.Buffer)
@ -51,7 +65,7 @@ func TestCodeClimate_Print(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
//nolint:lll //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}}}]` 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()) assert.Equal(t, expected, buf.String())
} }

View File

@ -1,3 +1,4 @@
//nolint:dupl
package printers package printers
import ( import (