diff --git a/pkg/config/output.go b/pkg/config/output.go index aaa5183ec4e4..caddb095c960 100644 --- a/pkg/config/output.go +++ b/pkg/config/output.go @@ -16,8 +16,8 @@ const ( OutFormatCheckstyle = "checkstyle" OutFormatCodeClimate = "code-climate" OutFormatHTML = "html" - OutFormatJunitXML = "junit-xml" - OutFormatJunitXMLExtended = "junit-xml-extended" + OutFormatJUnitXML = "junit-xml" + OutFormatJUnitXMLExtended = "junit-xml-extended" OutFormatGithubActions = "github-actions" // Deprecated OutFormatTeamCity = "teamcity" OutFormatSarif = "sarif" @@ -32,8 +32,8 @@ var AllOutputFormats = []string{ OutFormatCheckstyle, OutFormatCodeClimate, OutFormatHTML, - OutFormatJunitXML, - OutFormatJunitXMLExtended, + OutFormatJUnitXML, + OutFormatJUnitXMLExtended, OutFormatGithubActions, OutFormatTeamCity, OutFormatSarif, diff --git a/pkg/printers/codeclimate.go b/pkg/printers/codeclimate.go index 7739778e1350..3adcffac61e1 100644 --- a/pkg/printers/codeclimate.go +++ b/pkg/printers/codeclimate.go @@ -31,20 +31,22 @@ func NewCodeClimate(log logutils.Log, w io.Writer) *CodeClimate { } func (p *CodeClimate) Print(issues []result.Issue) error { - codeClimateIssues := make([]CodeClimateIssue, 0, len(issues)) + ccIssues := make([]codeClimateIssue, 0, len(issues)) for i := range issues { issue := issues[i] - codeClimateIssue := CodeClimateIssue{} - codeClimateIssue.Description = issue.Description() - codeClimateIssue.CheckName = issue.FromLinter - codeClimateIssue.Location.Path = issue.Pos.Filename - codeClimateIssue.Location.Lines.Begin = issue.Pos.Line - codeClimateIssue.Fingerprint = issue.Fingerprint() - codeClimateIssue.Severity = p.sanitizer.Sanitize(issue.Severity) + ccIssue := codeClimateIssue{ + Description: issue.Description(), + CheckName: issue.FromLinter, + Severity: p.sanitizer.Sanitize(issue.Severity), + Fingerprint: issue.Fingerprint(), + } - codeClimateIssues = append(codeClimateIssues, codeClimateIssue) + ccIssue.Location.Path = issue.Pos.Filename + ccIssue.Location.Lines.Begin = issue.Pos.Line + + ccIssues = append(ccIssues, ccIssue) } err := p.sanitizer.Err() @@ -52,14 +54,14 @@ func (p *CodeClimate) Print(issues []result.Issue) error { p.log.Infof("%v", err) } - return json.NewEncoder(p.w).Encode(codeClimateIssues) + return json.NewEncoder(p.w).Encode(ccIssues) } -// CodeClimateIssue is a subset of the Code Climate spec. +// codeClimateIssue is a subset of the Code Climate spec. // https://github.com/codeclimate/platform/blob/master/spec/analyzers/SPEC.md#data-types // It is just enough to support GitLab CI Code Quality. // https://docs.gitlab.com/ee/ci/testing/code_quality.html#code-quality-report-format -type CodeClimateIssue struct { +type codeClimateIssue struct { Description string `json:"description"` CheckName string `json:"check_name"` Severity string `json:"severity,omitempty"` diff --git a/pkg/printers/junitxml.go b/pkg/printers/junitxml.go index bc755b256d96..0959fe18fb7d 100644 --- a/pkg/printers/junitxml.go +++ b/pkg/printers/junitxml.go @@ -12,23 +12,23 @@ import ( "github.com/golangci/golangci-lint/pkg/result" ) -// JunitXML prints issues in the Junit XML format. +// JUnitXML prints issues in the JUnit XML format. // There is no official specification for the JUnit XML file format, // and various tools generate and support different flavors of this format. // https://github.com/testmoapp/junitxml -type JunitXML struct { +type JUnitXML struct { extended bool w io.Writer } -func NewJunitXML(w io.Writer, extended bool) *JunitXML { - return &JunitXML{ +func NewJUnitXML(w io.Writer, extended bool) *JUnitXML { + return &JUnitXML{ extended: extended, w: w, } } -func (p JunitXML) Print(issues []result.Issue) error { +func (p JUnitXML) Print(issues []result.Issue) error { suites := make(map[string]testSuiteXML) // use a map to group by file for ind := range issues { diff --git a/pkg/printers/junitxml_test.go b/pkg/printers/junitxml_test.go index 4cf99789124c..b5dbf9242eb5 100644 --- a/pkg/printers/junitxml_test.go +++ b/pkg/printers/junitxml_test.go @@ -11,7 +11,7 @@ import ( "github.com/golangci/golangci-lint/pkg/result" ) -func TestJunitXML_Print(t *testing.T) { +func TestJUnitXML_Print(t *testing.T) { issues := []result.Issue{ { FromLinter: "linter-a", @@ -105,7 +105,7 @@ Details: func foo() { t.Parallel() buf := new(bytes.Buffer) - printer := NewJunitXML(buf, test.extended) + printer := NewJUnitXML(buf, test.extended) err := printer.Print(issues) require.NoError(t, err) diff --git a/pkg/printers/printer.go b/pkg/printers/printer.go index b7d3bc82b441..c04648ad9220 100644 --- a/pkg/printers/printer.go +++ b/pkg/printers/printer.go @@ -127,8 +127,8 @@ func (c *Printer) createPrinter(format string, w io.Writer) (issuePrinter, error p = NewCodeClimate(c.log, w) case config.OutFormatHTML: p = NewHTML(w) - case config.OutFormatJunitXML, config.OutFormatJunitXMLExtended: - p = NewJunitXML(w, format == config.OutFormatJunitXMLExtended) + case config.OutFormatJUnitXML, config.OutFormatJUnitXMLExtended: + p = NewJUnitXML(w, format == config.OutFormatJUnitXMLExtended) case config.OutFormatGithubActions: p = NewGitHubAction(w) case config.OutFormatTeamCity: @@ -168,11 +168,11 @@ func (s *severitySanitizer) Err() error { return nil } - var foo []string + var names []string for k := range s.unsupportedSeverities { - foo = append(foo, "'"+k+"'") + names = append(names, "'"+k+"'") } - return fmt.Errorf("some severities (%v) are not inside supported values (%v), fallback to '%s'", - strings.Join(foo, ", "), strings.Join(s.allowedSeverities, ", "), s.defaultSeverity) + return fmt.Errorf("severities (%v) are not inside supported values (%v), fallback to '%s'", + strings.Join(names, ", "), strings.Join(s.allowedSeverities, ", "), s.defaultSeverity) } diff --git a/pkg/printers/tab.go b/pkg/printers/tab.go index 0a0b176b4a6b..ac04ab0fbe3a 100644 --- a/pkg/printers/tab.go +++ b/pkg/printers/tab.go @@ -11,7 +11,7 @@ import ( "github.com/golangci/golangci-lint/pkg/result" ) -// Tab prints issues using tabulation as field separator. +// Tab prints issues using tabulation as a field separator. type Tab struct { printLinterName bool useColors bool