Skip to content

Commit 6740559

Browse files
shaunthegeekldez
andauthored
code-climate: add default severity (#3294)
Co-authored-by: Fernandez Ludovic <[email protected]>
1 parent c1e24c1 commit 6740559

File tree

4 files changed

+26
-6
lines changed

4 files changed

+26
-6
lines changed

pkg/printers/checkstyle.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import (
1212
"github.com/golangci/golangci-lint/pkg/result"
1313
)
1414

15+
const defaultCheckstyleSeverity = "error"
16+
1517
type checkstyleOutput struct {
1618
XMLName xml.Name `xml:"checkstyle"`
1719
Version string `xml:"version,attr"`
@@ -31,8 +33,6 @@ type checkstyleError struct {
3133
Source string `xml:"source,attr"`
3234
}
3335

34-
const defaultCheckstyleSeverity = "error"
35-
3636
type Checkstyle struct {
3737
w io.Writer
3838
}

pkg/printers/codeclimate.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,12 @@ import (
99
"github.com/golangci/golangci-lint/pkg/result"
1010
)
1111

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

4449
if issue.Severity != "" {
4550
codeClimateIssue.Severity = issue.Severity

pkg/printers/codeclimate_test.go

+16-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
//nolint:dupl
21
package printers
32

43
import (
@@ -42,6 +41,21 @@ func TestCodeClimate_Print(t *testing.T) {
4241
Column: 9,
4342
},
4443
},
44+
{
45+
FromLinter: "linter-c",
46+
Text: "issue c",
47+
SourceLines: []string{
48+
"func foo() {",
49+
"\tfmt.Println(\"ccc\")",
50+
"}",
51+
},
52+
Pos: token.Position{
53+
Filename: "path/to/filec.go",
54+
Offset: 6,
55+
Line: 200,
56+
Column: 2,
57+
},
58+
},
4559
}
4660

4761
buf := new(bytes.Buffer)
@@ -51,7 +65,7 @@ func TestCodeClimate_Print(t *testing.T) {
5165
require.NoError(t, err)
5266

5367
//nolint:lll
54-
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}}}]`
68+
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}}}]`
5569

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

pkg/printers/github_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//nolint:dupl
12
package printers
23

34
import (

0 commit comments

Comments
 (0)