Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

code-climate: add default severity #3294

Merged
merged 3 commits into from Oct 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions pkg/printers/checkstyle.go
Expand Up @@ -12,6 +12,8 @@ import (
"github.com/golangci/golangci-lint/pkg/result"
)

const defaultCheckstyleSeverity = "error"

type checkstyleOutput struct {
XMLName xml.Name `xml:"checkstyle"`
Version string `xml:"version,attr"`
Expand All @@ -31,8 +33,6 @@ type checkstyleError struct {
Source string `xml:"source,attr"`
}

const defaultCheckstyleSeverity = "error"

type Checkstyle struct {
w io.Writer
}
Expand Down
9 changes: 7 additions & 2 deletions pkg/printers/codeclimate.go
Expand Up @@ -9,8 +9,12 @@ import (
"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
// It is just enough to support GitLab CI Code Quality - https://docs.gitlab.com/ee/user/project/merge_requests/code_quality.html
const defaultCodeClimateSeverity = "critical"

// 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 {
Description string `json:"description"`
Severity string `json:"severity,omitempty"`
Expand Down Expand Up @@ -40,6 +44,7 @@ func (p CodeClimate) Print(ctx context.Context, issues []result.Issue) error {
codeClimateIssue.Location.Path = issue.Pos.Filename
codeClimateIssue.Location.Lines.Begin = issue.Pos.Line
codeClimateIssue.Fingerprint = issue.Fingerprint()
codeClimateIssue.Severity = defaultCodeClimateSeverity

if issue.Severity != "" {
codeClimateIssue.Severity = issue.Severity
Expand Down
18 changes: 16 additions & 2 deletions pkg/printers/codeclimate_test.go
@@ -1,4 +1,3 @@
//nolint:dupl
package printers

import (
Expand Down Expand Up @@ -42,6 +41,21 @@ func TestCodeClimate_Print(t *testing.T) {
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)
Expand All @@ -51,7 +65,7 @@ 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}}}]`
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())
}
1 change: 1 addition & 0 deletions pkg/printers/github_test.go
@@ -1,3 +1,4 @@
//nolint:dupl
package printers

import (
Expand Down