Skip to content

Commit dfd79c9

Browse files
authored
dev: cleanup printers (#5361)
1 parent 980a911 commit dfd79c9

File tree

6 files changed

+32
-30
lines changed

6 files changed

+32
-30
lines changed

pkg/config/output.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ const (
1616
OutFormatCheckstyle = "checkstyle"
1717
OutFormatCodeClimate = "code-climate"
1818
OutFormatHTML = "html"
19-
OutFormatJunitXML = "junit-xml"
20-
OutFormatJunitXMLExtended = "junit-xml-extended"
19+
OutFormatJUnitXML = "junit-xml"
20+
OutFormatJUnitXMLExtended = "junit-xml-extended"
2121
OutFormatGithubActions = "github-actions" // Deprecated
2222
OutFormatTeamCity = "teamcity"
2323
OutFormatSarif = "sarif"
@@ -32,8 +32,8 @@ var AllOutputFormats = []string{
3232
OutFormatCheckstyle,
3333
OutFormatCodeClimate,
3434
OutFormatHTML,
35-
OutFormatJunitXML,
36-
OutFormatJunitXMLExtended,
35+
OutFormatJUnitXML,
36+
OutFormatJUnitXMLExtended,
3737
OutFormatGithubActions,
3838
OutFormatTeamCity,
3939
OutFormatSarif,

pkg/printers/codeclimate.go

+14-12
Original file line numberDiff line numberDiff line change
@@ -31,35 +31,37 @@ func NewCodeClimate(log logutils.Log, w io.Writer) *CodeClimate {
3131
}
3232

3333
func (p *CodeClimate) Print(issues []result.Issue) error {
34-
codeClimateIssues := make([]CodeClimateIssue, 0, len(issues))
34+
ccIssues := make([]codeClimateIssue, 0, len(issues))
3535

3636
for i := range issues {
3737
issue := issues[i]
3838

39-
codeClimateIssue := CodeClimateIssue{}
40-
codeClimateIssue.Description = issue.Description()
41-
codeClimateIssue.CheckName = issue.FromLinter
42-
codeClimateIssue.Location.Path = issue.Pos.Filename
43-
codeClimateIssue.Location.Lines.Begin = issue.Pos.Line
44-
codeClimateIssue.Fingerprint = issue.Fingerprint()
45-
codeClimateIssue.Severity = p.sanitizer.Sanitize(issue.Severity)
39+
ccIssue := codeClimateIssue{
40+
Description: issue.Description(),
41+
CheckName: issue.FromLinter,
42+
Severity: p.sanitizer.Sanitize(issue.Severity),
43+
Fingerprint: issue.Fingerprint(),
44+
}
4645

47-
codeClimateIssues = append(codeClimateIssues, codeClimateIssue)
46+
ccIssue.Location.Path = issue.Pos.Filename
47+
ccIssue.Location.Lines.Begin = issue.Pos.Line
48+
49+
ccIssues = append(ccIssues, ccIssue)
4850
}
4951

5052
err := p.sanitizer.Err()
5153
if err != nil {
5254
p.log.Infof("%v", err)
5355
}
5456

55-
return json.NewEncoder(p.w).Encode(codeClimateIssues)
57+
return json.NewEncoder(p.w).Encode(ccIssues)
5658
}
5759

58-
// CodeClimateIssue is a subset of the Code Climate spec.
60+
// codeClimateIssue is a subset of the Code Climate spec.
5961
// https://github.com/codeclimate/platform/blob/master/spec/analyzers/SPEC.md#data-types
6062
// It is just enough to support GitLab CI Code Quality.
6163
// https://docs.gitlab.com/ee/ci/testing/code_quality.html#code-quality-report-format
62-
type CodeClimateIssue struct {
64+
type codeClimateIssue struct {
6365
Description string `json:"description"`
6466
CheckName string `json:"check_name"`
6567
Severity string `json:"severity,omitempty"`

pkg/printers/junitxml.go

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

15-
// JunitXML prints issues in the Junit XML format.
15+
// JUnitXML prints issues in the JUnit XML format.
1616
// There is no official specification for the JUnit XML file format,
1717
// and various tools generate and support different flavors of this format.
1818
// https://github.com/testmoapp/junitxml
19-
type JunitXML struct {
19+
type JUnitXML struct {
2020
extended bool
2121
w io.Writer
2222
}
2323

24-
func NewJunitXML(w io.Writer, extended bool) *JunitXML {
25-
return &JunitXML{
24+
func NewJUnitXML(w io.Writer, extended bool) *JUnitXML {
25+
return &JUnitXML{
2626
extended: extended,
2727
w: w,
2828
}
2929
}
3030

31-
func (p JunitXML) Print(issues []result.Issue) error {
31+
func (p JUnitXML) Print(issues []result.Issue) error {
3232
suites := make(map[string]testSuiteXML) // use a map to group by file
3333

3434
for ind := range issues {

pkg/printers/junitxml_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"github.com/golangci/golangci-lint/pkg/result"
1212
)
1313

14-
func TestJunitXML_Print(t *testing.T) {
14+
func TestJUnitXML_Print(t *testing.T) {
1515
issues := []result.Issue{
1616
{
1717
FromLinter: "linter-a",
@@ -105,7 +105,7 @@ Details: func foo() {
105105
t.Parallel()
106106

107107
buf := new(bytes.Buffer)
108-
printer := NewJunitXML(buf, test.extended)
108+
printer := NewJUnitXML(buf, test.extended)
109109

110110
err := printer.Print(issues)
111111
require.NoError(t, err)

pkg/printers/printer.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,8 @@ func (c *Printer) createPrinter(format string, w io.Writer) (issuePrinter, error
127127
p = NewCodeClimate(c.log, w)
128128
case config.OutFormatHTML:
129129
p = NewHTML(w)
130-
case config.OutFormatJunitXML, config.OutFormatJunitXMLExtended:
131-
p = NewJunitXML(w, format == config.OutFormatJunitXMLExtended)
130+
case config.OutFormatJUnitXML, config.OutFormatJUnitXMLExtended:
131+
p = NewJUnitXML(w, format == config.OutFormatJUnitXMLExtended)
132132
case config.OutFormatGithubActions:
133133
p = NewGitHubAction(w)
134134
case config.OutFormatTeamCity:
@@ -168,11 +168,11 @@ func (s *severitySanitizer) Err() error {
168168
return nil
169169
}
170170

171-
var foo []string
171+
var names []string
172172
for k := range s.unsupportedSeverities {
173-
foo = append(foo, "'"+k+"'")
173+
names = append(names, "'"+k+"'")
174174
}
175175

176-
return fmt.Errorf("some severities (%v) are not inside supported values (%v), fallback to '%s'",
177-
strings.Join(foo, ", "), strings.Join(s.allowedSeverities, ", "), s.defaultSeverity)
176+
return fmt.Errorf("severities (%v) are not inside supported values (%v), fallback to '%s'",
177+
strings.Join(names, ", "), strings.Join(s.allowedSeverities, ", "), s.defaultSeverity)
178178
}

pkg/printers/tab.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"github.com/golangci/golangci-lint/pkg/result"
1212
)
1313

14-
// Tab prints issues using tabulation as field separator.
14+
// Tab prints issues using tabulation as a field separator.
1515
type Tab struct {
1616
printLinterName bool
1717
useColors bool

0 commit comments

Comments
 (0)