forked from golangci/golangci-lint
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlinters.go
64 lines (51 loc) · 1.23 KB
/
linters.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
60
61
62
63
64
package config
import (
"fmt"
"slices"
)
const (
GroupStandard = "standard"
GroupAll = "all"
GroupNone = "none"
GroupFast = "fast"
)
type Linters struct {
Default string `mapstructure:"default"`
Enable []string `mapstructure:"enable"`
Disable []string `mapstructure:"disable"`
FastOnly bool `mapstructure:"fast-only"` // Flag only option.
Settings LintersSettings `mapstructure:"settings"`
Exclusions LinterExclusions `mapstructure:"exclusions"`
}
func (l *Linters) Validate() error {
validators := []func() error{
l.Exclusions.Validate,
l.validateNoFormattersEnabled,
l.validateNoFormattersDisabled,
}
for _, v := range validators {
if err := v(); err != nil {
return err
}
}
return nil
}
func (l *Linters) validateNoFormattersEnabled() error {
for _, n := range l.Enable {
if slices.Contains(getAllFormatterNames(), n) {
return fmt.Errorf("%s is a formatter", n)
}
}
return nil
}
func (l *Linters) validateNoFormattersDisabled() error {
for _, n := range l.Enable {
if slices.Contains(getAllFormatterNames(), n) {
return fmt.Errorf("%s is a formatter", n)
}
}
return nil
}
func getAllFormatterNames() []string {
return []string{"gci", "gofmt", "gofumpt", "goimports"}
}