forked from golangci/golangci-lint
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlinters_exclusions.go
61 lines (50 loc) · 1.41 KB
/
linters_exclusions.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
package config
import (
"fmt"
"slices"
)
const (
GeneratedModeLax = "lax"
GeneratedModeStrict = "strict"
GeneratedModeDisable = "disable"
)
const (
ExclusionPresetComments = "comments"
ExclusionPresetStdErrorHandling = "stdErrorHandling"
ExclusionPresetCommonFalsePositives = "commonFalsePositives"
ExclusionPresetLegacy = "legacy"
)
const excludeRuleMinConditionsCount = 2
type LinterExclusions struct {
Generated string `mapstructure:"generated"`
WarnUnused bool `mapstructure:"warn-unused"`
Presets []string `mapstructure:"preset"`
Rules []ExcludeRule `mapstructure:"rules"`
Paths []string `mapstructure:"paths"`
PathsExcept []string `mapstructure:"paths-except"`
}
func (e *LinterExclusions) Validate() error {
for i, rule := range e.Rules {
if err := rule.Validate(); err != nil {
return fmt.Errorf("error in exclude rule #%d: %w", i, err)
}
}
allPresets := []string{
ExclusionPresetComments,
ExclusionPresetStdErrorHandling,
ExclusionPresetCommonFalsePositives,
ExclusionPresetLegacy,
}
for _, preset := range e.Presets {
if !slices.Contains(allPresets, preset) {
return fmt.Errorf("invalid preset: %s", preset)
}
}
return nil
}
type ExcludeRule struct {
BaseRule `mapstructure:",squash"`
}
func (e *ExcludeRule) Validate() error {
return e.BaseRule.Validate(excludeRuleMinConditionsCount)
}