forked from golangci/golangci-lint
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathoutput.go
59 lines (52 loc) · 1.55 KB
/
output.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package config
import (
"errors"
"fmt"
"slices"
)
const (
OutFormatJSON = "json"
OutFormatLineNumber = "line-number"
OutFormatColoredLineNumber = "colored-line-number"
OutFormatTab = "tab"
OutFormatColoredTab = "colored-tab"
OutFormatCheckstyle = "checkstyle"
OutFormatCodeClimate = "code-climate"
OutFormatHTML = "html"
OutFormatJunitXML = "junit-xml"
OutFormatGithubActions = "github-actions"
OutFormatTeamCity = "teamcity"
)
var OutFormats = []string{
OutFormatColoredLineNumber,
OutFormatLineNumber,
OutFormatJSON,
OutFormatTab,
OutFormatCheckstyle,
OutFormatCodeClimate,
OutFormatHTML,
OutFormatJunitXML,
OutFormatGithubActions,
OutFormatTeamCity,
}
type Output struct {
Format string `mapstructure:"format"`
PrintIssuedLine bool `mapstructure:"print-issued-lines"`
PrintLinterName bool `mapstructure:"print-linter-name"`
UniqByLine bool `mapstructure:"uniq-by-line"`
SortResults bool `mapstructure:"sort-results"`
SortOrder []string `mapstructure:"sort-order"`
PathPrefix string `mapstructure:"path-prefix"`
ShowStats bool `mapstructure:"show-stats"`
}
func (o *Output) Validate() error {
if !o.SortResults && len(o.SortOrder) > 0 {
return errors.New("sort-results should be 'true' to use sort-order")
}
for _, order := range o.SortOrder {
if !slices.Contains([]string{"linter", "file", "severity"}, order) {
return fmt.Errorf("unsupported sort-order name %q", order)
}
}
return nil
}