Skip to content

Commit 2602996

Browse files
committed
chore: document printers
1 parent 87da074 commit 2602996

File tree

9 files changed

+131
-114
lines changed

9 files changed

+131
-114
lines changed

pkg/printers/checkstyle.go

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,8 @@ import (
1414

1515
const defaultCheckstyleSeverity = "error"
1616

17-
type checkstyleOutput struct {
18-
XMLName xml.Name `xml:"checkstyle"`
19-
Version string `xml:"version,attr"`
20-
Files []*checkstyleFile `xml:"file"`
21-
}
22-
23-
type checkstyleFile struct {
24-
Name string `xml:"name,attr"`
25-
Errors []*checkstyleError `xml:"error"`
26-
}
27-
28-
type checkstyleError struct {
29-
Column int `xml:"column,attr"`
30-
Line int `xml:"line,attr"`
31-
Message string `xml:"message,attr"`
32-
Severity string `xml:"severity,attr"`
33-
Source string `xml:"source,attr"`
34-
}
35-
17+
// Checkstyle prints issues in the Checkstyle format.
18+
// https://checkstyle.org/config.html
3619
type Checkstyle struct {
3720
w io.Writer
3821
}
@@ -93,3 +76,22 @@ func (p Checkstyle) Print(issues []result.Issue) error {
9376

9477
return nil
9578
}
79+
80+
type checkstyleOutput struct {
81+
XMLName xml.Name `xml:"checkstyle"`
82+
Version string `xml:"version,attr"`
83+
Files []*checkstyleFile `xml:"file"`
84+
}
85+
86+
type checkstyleFile struct {
87+
Name string `xml:"name,attr"`
88+
Errors []*checkstyleError `xml:"error"`
89+
}
90+
91+
type checkstyleError struct {
92+
Column int `xml:"column,attr"`
93+
Line int `xml:"line,attr"`
94+
Message string `xml:"message,attr"`
95+
Severity string `xml:"severity,attr"`
96+
Source string `xml:"source,attr"`
97+
}

pkg/printers/codeclimate.go

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,8 @@ import (
1010

1111
const defaultCodeClimateSeverity = "critical"
1212

13-
// CodeClimateIssue is a subset of the Code Climate spec.
14-
// https://github.com/codeclimate/platform/blob/master/spec/analyzers/SPEC.md#data-types
15-
// It is just enough to support GitLab CI Code Quality.
16-
// https://docs.gitlab.com/ee/ci/testing/code_quality.html#code-quality-report-format
17-
type CodeClimateIssue struct {
18-
Description string `json:"description"`
19-
CheckName string `json:"check_name"`
20-
Severity string `json:"severity,omitempty"`
21-
Fingerprint string `json:"fingerprint"`
22-
Location struct {
23-
Path string `json:"path"`
24-
Lines struct {
25-
Begin int `json:"begin"`
26-
} `json:"lines"`
27-
} `json:"location"`
28-
}
29-
13+
// CodeClimate prints issues in the Code Climate format.
14+
// https://github.com/codeclimate/platform/blob/master/spec/analyzers/SPEC.md
3015
type CodeClimate struct {
3116
w io.Writer
3217

@@ -44,7 +29,7 @@ func (p CodeClimate) Print(issues []result.Issue) error {
4429
codeClimateIssues := make([]CodeClimateIssue, 0, len(issues))
4530

4631
for i := range issues {
47-
issue := &issues[i]
32+
issue := issues[i]
4833

4934
codeClimateIssue := CodeClimateIssue{}
5035
codeClimateIssue.Description = issue.Description()
@@ -63,3 +48,20 @@ func (p CodeClimate) Print(issues []result.Issue) error {
6348

6449
return json.NewEncoder(p.w).Encode(codeClimateIssues)
6550
}
51+
52+
// CodeClimateIssue is a subset of the Code Climate spec.
53+
// https://github.com/codeclimate/platform/blob/master/spec/analyzers/SPEC.md#data-types
54+
// It is just enough to support GitLab CI Code Quality.
55+
// https://docs.gitlab.com/ee/ci/testing/code_quality.html#code-quality-report-format
56+
type CodeClimateIssue struct {
57+
Description string `json:"description"`
58+
CheckName string `json:"check_name"`
59+
Severity string `json:"severity,omitempty"`
60+
Fingerprint string `json:"fingerprint"`
61+
Location struct {
62+
Path string `json:"path"`
63+
Lines struct {
64+
Begin int `json:"begin"`
65+
} `json:"lines"`
66+
} `json:"location"`
67+
}

pkg/printers/html.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ type htmlIssue struct {
122122
Code string
123123
}
124124

125+
// HTML prints issues in an HTML page.
126+
// It uses the Cloudflare CDN (cdnjs) and React.
125127
type HTML struct {
126128
w io.Writer
127129
}

pkg/printers/json.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ import (
88
"github.com/golangci/golangci-lint/pkg/result"
99
)
1010

11+
// JSON prints issues in a JSON representation.
1112
type JSON struct {
12-
rd *report.Data // TODO(ldez) should be drop in v2. Only use by JSON reporter.
13+
rd *report.Data
1314
w io.Writer
1415
}
1516

pkg/printers/junitxml.go

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -12,34 +12,10 @@ import (
1212
"github.com/golangci/golangci-lint/pkg/result"
1313
)
1414

15-
type testSuitesXML struct {
16-
XMLName xml.Name `xml:"testsuites"`
17-
TestSuites []testSuiteXML
18-
}
19-
20-
type testSuiteXML struct {
21-
XMLName xml.Name `xml:"testsuite"`
22-
Suite string `xml:"name,attr"`
23-
Tests int `xml:"tests,attr"`
24-
Errors int `xml:"errors,attr"`
25-
Failures int `xml:"failures,attr"`
26-
TestCases []testCaseXML `xml:"testcase"`
27-
}
28-
29-
type testCaseXML struct {
30-
Name string `xml:"name,attr"`
31-
ClassName string `xml:"classname,attr"`
32-
Failure failureXML `xml:"failure"`
33-
File string `xml:"file,attr,omitempty"`
34-
Line int `xml:"line,attr,omitempty"`
35-
}
36-
37-
type failureXML struct {
38-
Message string `xml:"message,attr"`
39-
Type string `xml:"type,attr"`
40-
Content string `xml:",cdata"`
41-
}
42-
15+
// JunitXML prints issues in the Junit XML format.
16+
// There is no official specification for the JUnit XML file format,
17+
// and various tools generate and support different flavors of this format.
18+
// https://github.com/testmoapp/junitxml
4319
type JunitXML struct {
4420
extended bool
4521
w io.Writer
@@ -97,3 +73,31 @@ func (p JunitXML) Print(issues []result.Issue) error {
9773
}
9874
return nil
9975
}
76+
77+
type testSuitesXML struct {
78+
XMLName xml.Name `xml:"testsuites"`
79+
TestSuites []testSuiteXML
80+
}
81+
82+
type testSuiteXML struct {
83+
XMLName xml.Name `xml:"testsuite"`
84+
Suite string `xml:"name,attr"`
85+
Tests int `xml:"tests,attr"`
86+
Errors int `xml:"errors,attr"`
87+
Failures int `xml:"failures,attr"`
88+
TestCases []testCaseXML `xml:"testcase"`
89+
}
90+
91+
type testCaseXML struct {
92+
Name string `xml:"name,attr"`
93+
ClassName string `xml:"classname,attr"`
94+
Failure failureXML `xml:"failure"`
95+
File string `xml:"file,attr,omitempty"`
96+
Line int `xml:"line,attr,omitempty"`
97+
}
98+
99+
type failureXML struct {
100+
Message string `xml:"message,attr"`
101+
Type string `xml:"type,attr"`
102+
Content string `xml:",cdata"`
103+
}

pkg/printers/sarif.go

Lines changed: 50 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -12,53 +12,9 @@ const (
1212
sarifSchemaURI = "https://schemastore.azurewebsites.net/schemas/json/sarif-2.1.0-rtm.6.json"
1313
)
1414

15-
type SarifOutput struct {
16-
Version string `json:"version"`
17-
Schema string `json:"$schema"`
18-
Runs []sarifRun `json:"runs"`
19-
}
20-
21-
type sarifRun struct {
22-
Tool sarifTool `json:"tool"`
23-
Results []sarifResult `json:"results"`
24-
}
25-
26-
type sarifTool struct {
27-
Driver struct {
28-
Name string `json:"name"`
29-
} `json:"driver"`
30-
}
31-
32-
type sarifResult struct {
33-
RuleID string `json:"ruleId"`
34-
Level string `json:"level"`
35-
Message sarifMessage `json:"message"`
36-
Locations []sarifLocation `json:"locations"`
37-
}
38-
39-
type sarifMessage struct {
40-
Text string `json:"text"`
41-
}
42-
43-
type sarifLocation struct {
44-
PhysicalLocation sarifPhysicalLocation `json:"physicalLocation"`
45-
}
46-
47-
type sarifPhysicalLocation struct {
48-
ArtifactLocation sarifArtifactLocation `json:"artifactLocation"`
49-
Region sarifRegion `json:"region"`
50-
}
51-
52-
type sarifArtifactLocation struct {
53-
URI string `json:"uri"`
54-
Index int `json:"index"`
55-
}
56-
57-
type sarifRegion struct {
58-
StartLine int `json:"startLine"`
59-
StartColumn int `json:"startColumn"`
60-
}
61-
15+
// Sarif prints issues in the SARIF format.
16+
// https://sarifweb.azurewebsites.net/
17+
// https://docs.oasis-open.org/sarif/sarif/v2.1.0/
6218
type Sarif struct {
6319
w io.Writer
6420
}
@@ -115,3 +71,50 @@ func (p Sarif) Print(issues []result.Issue) error {
11571

11672
return json.NewEncoder(p.w).Encode(output)
11773
}
74+
75+
type SarifOutput struct {
76+
Version string `json:"version"`
77+
Schema string `json:"$schema"`
78+
Runs []sarifRun `json:"runs"`
79+
}
80+
81+
type sarifRun struct {
82+
Tool sarifTool `json:"tool"`
83+
Results []sarifResult `json:"results"`
84+
}
85+
86+
type sarifTool struct {
87+
Driver struct {
88+
Name string `json:"name"`
89+
} `json:"driver"`
90+
}
91+
92+
type sarifResult struct {
93+
RuleID string `json:"ruleId"`
94+
Level string `json:"level"`
95+
Message sarifMessage `json:"message"`
96+
Locations []sarifLocation `json:"locations"`
97+
}
98+
99+
type sarifMessage struct {
100+
Text string `json:"text"`
101+
}
102+
103+
type sarifLocation struct {
104+
PhysicalLocation sarifPhysicalLocation `json:"physicalLocation"`
105+
}
106+
107+
type sarifPhysicalLocation struct {
108+
ArtifactLocation sarifArtifactLocation `json:"artifactLocation"`
109+
Region sarifRegion `json:"region"`
110+
}
111+
112+
type sarifArtifactLocation struct {
113+
URI string `json:"uri"`
114+
Index int `json:"index"`
115+
}
116+
117+
type sarifRegion struct {
118+
StartLine int `json:"startLine"`
119+
StartColumn int `json:"startColumn"`
120+
}

pkg/printers/tab.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/golangci/golangci-lint/pkg/result"
1212
)
1313

14+
// Tab prints issues using tabulation as field separator.
1415
type Tab struct {
1516
printLinterName bool
1617
useColors bool

pkg/printers/teamcity.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ const (
1414
largeLimit = 4000
1515
)
1616

17-
// TeamCity printer for TeamCity format.
17+
// TeamCity prints issues in the TeamCity format.
18+
// https://www.jetbrains.com/help/teamcity/service-messages.html
1819
type TeamCity struct {
1920
w io.Writer
2021
escaper *strings.Replacer

pkg/printers/text.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/golangci/golangci-lint/pkg/result"
1212
)
1313

14+
// Text prints issues with a human friendly representation.
1415
type Text struct {
1516
printIssuedLine bool
1617
printLinterName bool

0 commit comments

Comments
 (0)