-
Notifications
You must be signed in to change notification settings - Fork 293
/
Copy pathconfig.go
71 lines (61 loc) · 2.08 KB
/
config.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
65
66
67
68
69
70
71
package lint
import (
goversion "github.com/hashicorp/go-version"
)
// Arguments is type used for the arguments of a rule.
type Arguments = []any
// FileFilters is type used for modeling file filters to apply to rules.
type FileFilters = []*FileFilter
// RuleConfig is type used for the rule configuration.
type RuleConfig struct {
Arguments Arguments
Severity Severity
Disabled bool
// Exclude - rule-level file excludes, TOML related (strings)
Exclude []string
// excludeFilters - regex-based file filters, initialized from Exclude
excludeFilters []*FileFilter
}
// Initialize - should be called after reading from TOML file
func (rc *RuleConfig) Initialize() error {
for _, f := range rc.Exclude {
ff, err := ParseFileFilter(f)
if err != nil {
return err
}
rc.excludeFilters = append(rc.excludeFilters, ff)
}
return nil
}
// RulesConfig defines the config for all rules.
type RulesConfig = map[string]RuleConfig
// MustExclude - checks if given filename `name` must be excluded
func (rc *RuleConfig) MustExclude(name string) bool {
for _, exclude := range rc.excludeFilters {
if exclude.MatchFileName(name) {
return true
}
}
return false
}
// DirectiveConfig is type used for the linter directive configuration.
type DirectiveConfig struct {
Severity Severity
}
// DirectivesConfig defines the config for all directives.
type DirectivesConfig = map[string]DirectiveConfig
// Config defines the config of the linter.
type Config struct {
IgnoreGeneratedHeader bool `toml:"ignoreGeneratedHeader"`
Confidence float64
Severity Severity
EnableAllRules bool `toml:"enableAllRules"`
Rules RulesConfig `toml:"rule"`
ErrorCode int `toml:"errorCode"`
WarningCode int `toml:"warningCode"`
Directives DirectivesConfig `toml:"directive"`
Exclude []string `toml:"exclude"`
// If set, overrides the go language version specified in go.mod of
// packages being linted, and assumes this specific language version.
GoVersion *goversion.Version
}