7
7
"strings"
8
8
"unicode/utf8"
9
9
10
+ "github.com/golangci/golangci-lint/pkg/lint/linter"
10
11
"github.com/golangci/golangci-lint/pkg/result"
11
12
)
12
13
@@ -16,16 +17,23 @@ const (
16
17
largeLimit = 4000
17
18
)
18
19
20
+ // Configer used for accessing linter.Config by its name for printing instanceType values.
21
+ type Configer interface {
22
+ GetLinterConfigs (name string ) []* linter.Config
23
+ }
24
+
19
25
// TeamCity printer for TeamCity format.
20
26
type TeamCity struct {
21
27
w io.Writer
28
+ conf Configer
22
29
escaper * strings.Replacer
23
30
}
24
31
25
- // NewTeamCity output format outputs issues according to TeamCity service message format
26
- func NewTeamCity (w io.Writer ) * TeamCity {
32
+ // NewTeamCity output format outputs issues according to TeamCity service message format.
33
+ func NewTeamCity (w io.Writer , conf Configer ) * TeamCity {
27
34
return & TeamCity {
28
- w : w ,
35
+ w : w ,
36
+ conf : conf ,
29
37
// https://www.jetbrains.com/help/teamcity/service-messages.html#Escaped+Values
30
38
escaper : strings .NewReplacer (
31
39
"'" , "|'" ,
@@ -46,27 +54,30 @@ func (p *TeamCity) Print(_ context.Context, issues []result.Issue) error {
46
54
47
55
_ , ok := uniqLinters [issue .FromLinter ]
48
56
if ! ok {
49
- inspectionType := InspectionType {
50
- id : issue .FromLinter ,
51
- name : issue .FromLinter ,
52
- description : issue .FromLinter ,
53
- category : "Golangci-lint reports" ,
54
- }
55
-
56
- _ , err := inspectionType .Print (p .w , p .escaper )
57
- if err != nil {
58
- return err
57
+ linterConfigs := p .conf .GetLinterConfigs (issue .FromLinter )
58
+ for _ , config := range linterConfigs {
59
+ inspectionType := inspectionType {
60
+ id : config .Linter .Name (),
61
+ name : config .Linter .Name (),
62
+ description : config .Linter .Desc (),
63
+ category : "Golangci-lint reports" ,
64
+ }
65
+
66
+ _ , err := inspectionType .Print (p .w , p .escaper )
67
+ if err != nil {
68
+ return err
69
+ }
59
70
}
60
71
61
72
uniqLinters [issue .FromLinter ] = struct {}{}
62
73
}
63
74
64
- instance := InspectionInstance {
65
- typeID : issue .FromLinter ,
66
- message : issue .Text ,
67
- file : issue .FilePath (),
68
- line : issue .Line (),
69
- additionalAttribute : strings . TrimSpace ( issue .Severity ) ,
75
+ instance := inspectionInstance {
76
+ typeID : issue .FromLinter ,
77
+ message : issue .Text ,
78
+ file : issue .FilePath (),
79
+ line : issue .Line (),
80
+ severity : issue .Severity ,
70
81
}
71
82
72
83
_ , err := instance .Print (p .w , p .escaper )
@@ -78,46 +89,36 @@ func (p *TeamCity) Print(_ context.Context, issues []result.Issue) error {
78
89
return nil
79
90
}
80
91
81
- // InspectionType Each specific warning or an error in code (inspection instance) has an inspection type.
92
+ // inspectionType is the unique description of the conducted inspection. Each specific warning or
93
+ // an error in code (inspection instance) has an inspection type.
82
94
// https://www.jetbrains.com/help/teamcity/service-messages.html#Inspection+Type
83
- type InspectionType struct {
95
+ type inspectionType struct {
84
96
id string // (mandatory) limited by 255 characters.
85
97
name string // (mandatory) limited by 255 characters.
86
98
description string // (mandatory) limited by 255 characters.
87
99
category string // (mandatory) limited by 4000 characters.
88
100
}
89
101
90
- func (i InspectionType ) Print (w io.Writer , escaper * strings.Replacer ) (int , error ) {
102
+ func (i inspectionType ) Print (w io.Writer , escaper * strings.Replacer ) (int , error ) {
91
103
return fmt .Fprintf (w , "##teamcity[inspectionType id='%s' name='%s' description='%s' category='%s']\n " ,
92
104
limit (i .id , smallLimit ), limit (i .name , smallLimit ), limit (escaper .Replace (i .description ), largeLimit ), limit (i .category , smallLimit ))
93
105
}
94
106
95
- // InspectionInstance Reports a specific defect, warning, error message.
107
+ // inspectionInstance reports a specific defect, warning, error message.
96
108
// Includes location, description, and various optional and custom attributes.
97
109
// https://www.jetbrains.com/help/teamcity/service-messages.html#Inspection+Instance
98
- type InspectionInstance struct {
99
- typeID string // (mandatory) limited by 255 characters.
100
- message string // (optional) limited by 4000 characters.
101
- file string // (mandatory) file path limited by 4000 characters.
102
- line int // (optional) line of the file, integer .
103
- additionalAttribute string // (optional) can be any attribute.
110
+ type inspectionInstance struct {
111
+ typeID string // (mandatory) limited by 255 characters.
112
+ message string // (optional) limited by 4000 characters.
113
+ file string // (mandatory) file path limited by 4000 characters.
114
+ line int // (optional) line of the file.
115
+ severity string // (optional) severity attribute: INFO, ERROR, WARNING, WEAK WARNING .
104
116
}
105
117
106
- func (i InspectionInstance ) Print (w io.Writer , replacer * strings.Replacer ) (int , error ) {
107
- _ , err := fmt .Fprintf (w , "##teamcity[inspection typeId='%s' message='%s' file='%s' line='%d'" ,
108
- limit (i .typeID , smallLimit ), limit (replacer .Replace (i .message ), largeLimit ), limit (i .file , largeLimit ), i .line )
109
- if err != nil {
110
- return 0 , err
111
- }
112
-
113
- if i .additionalAttribute != "" {
114
- _ , err = fmt .Fprintf (w , " additional attribute='%s'" , i .additionalAttribute )
115
- if err != nil {
116
- return 0 , err
117
- }
118
- }
119
-
120
- return fmt .Fprintln (w , "]" )
118
+ func (i inspectionInstance ) Print (w io.Writer , replacer * strings.Replacer ) (int , error ) {
119
+ return fmt .Fprintf (w , "##teamcity[inspection typeId='%s' message='%s' file='%s' line='%d' SEVERITY='%s']\n " ,
120
+ limit (i .typeID , smallLimit ), limit (replacer .Replace (i .message ), largeLimit ), limit (i .file , largeLimit ), i .line ,
121
+ strings .ToUpper (i .severity ))
121
122
}
122
123
123
124
func limit (s string , max int ) string {
0 commit comments