From 1c6caf1bcedb5816b6910b23293613bdf8474b3c Mon Sep 17 00:00:00 2001 From: sink Date: Sat, 15 Oct 2022 16:01:23 +0800 Subject: [PATCH] fix: code climate report need severity --- pkg/printers/codeclimate.go | 1 + pkg/printers/codeclimate_test.go | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/pkg/printers/codeclimate.go b/pkg/printers/codeclimate.go index 8127632e74d6..99546b3bd5c8 100644 --- a/pkg/printers/codeclimate.go +++ b/pkg/printers/codeclimate.go @@ -40,6 +40,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 = "critical" if issue.Severity != "" { codeClimateIssue.Severity = issue.Severity diff --git a/pkg/printers/codeclimate_test.go b/pkg/printers/codeclimate_test.go index 5c25002a8907..b0097950dbce 100644 --- a/pkg/printers/codeclimate_test.go +++ b/pkg/printers/codeclimate_test.go @@ -42,6 +42,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) @@ -51,7 +66,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()) }