4
4
"context"
5
5
"encoding/json"
6
6
"fmt"
7
+ "strings"
7
8
8
9
"github.com/golangci/golangci-lint/pkg/logutils"
9
10
"github.com/golangci/golangci-lint/pkg/result"
@@ -13,6 +14,7 @@ import (
13
14
// It is just enough to support GitLab CI Code Quality - https://docs.gitlab.com/ee/user/project/merge_requests/code_quality.html
14
15
type CodeClimateIssue struct {
15
16
Description string `json:"description"`
17
+ Content string `json:"content,omitempty"`
16
18
Severity string `json:"severity,omitempty"`
17
19
Fingerprint string `json:"fingerprint"`
18
20
Location struct {
@@ -40,6 +42,11 @@ func (p CodeClimate) Print(ctx context.Context, issues []result.Issue) error {
40
42
codeClimateIssue .Location .Lines .Begin = issue .Pos .Line
41
43
codeClimateIssue .Fingerprint = issue .Fingerprint ()
42
44
45
+ content := p .buildContentString (& issues [i ])
46
+ if content != "" {
47
+ codeClimateIssue .Content = content
48
+ }
49
+
43
50
if issue .Severity != "" {
44
51
codeClimateIssue .Severity = issue .Severity
45
52
}
@@ -55,3 +62,23 @@ func (p CodeClimate) Print(ctx context.Context, issues []result.Issue) error {
55
62
fmt .Fprint (logutils .StdOut , string (outputJSON ))
56
63
return nil
57
64
}
65
+
66
+ func (p CodeClimate ) buildContentString (issue * result.Issue ) string {
67
+ if len (issue .SuggestedFixes ) == 0 {
68
+ return ""
69
+ }
70
+
71
+ var text string
72
+ for _ , fix := range issue .SuggestedFixes {
73
+ text += fmt .Sprintf ("%s\n " , strings .TrimSpace (fix .Message ))
74
+ var suggestedEdits []string
75
+ for _ , textEdit := range fix .TextEdits {
76
+ suggestedEdits = append (suggestedEdits , strings .TrimSpace (textEdit .NewText ))
77
+ }
78
+ if len (suggestedEdits ) > 0 {
79
+ text += "```\n " + strings .Join (suggestedEdits , "\n " ) + "\n " + "```\n "
80
+ }
81
+ }
82
+
83
+ return text
84
+ }
0 commit comments