2018-02-04 05:37:38 +02:00
|
|
|
package lint
|
|
|
|
|
|
|
|
// Arguments is type used for the arguments of a rule.
|
|
|
|
type Arguments = []interface{}
|
|
|
|
|
2023-09-23 10:41:34 +02:00
|
|
|
// FileFilters is type used for modeling file filters to apply to rules.
|
2023-08-12 08:21:11 +02:00
|
|
|
type FileFilters = []*FileFilter
|
|
|
|
|
2018-02-04 05:37:38 +02:00
|
|
|
// RuleConfig is type used for the rule configuration.
|
|
|
|
type RuleConfig struct {
|
|
|
|
Arguments Arguments
|
|
|
|
Severity Severity
|
2021-05-21 09:53:10 +02:00
|
|
|
Disabled bool
|
2023-08-12 08:21:11 +02:00
|
|
|
// 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
|
2018-02-04 05:37:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// RulesConfig defines the config for all rules.
|
|
|
|
type RulesConfig = map[string]RuleConfig
|
|
|
|
|
2023-08-12 08:21:11 +02:00
|
|
|
// MustExclude - checks if given filename `name` must be excluded
|
2023-10-03 20:07:00 +02:00
|
|
|
func (rc *RuleConfig) MustExclude(name string) bool {
|
|
|
|
for _, exclude := range rc.excludeFilters {
|
2023-08-12 08:21:11 +02:00
|
|
|
if exclude.MatchFileName(name) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2019-08-02 17:21:33 +02:00
|
|
|
// 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
|
|
|
|
|
2018-02-04 05:37:38 +02:00
|
|
|
// Config defines the config of the linter.
|
|
|
|
type Config struct {
|
|
|
|
IgnoreGeneratedHeader bool `toml:"ignoreGeneratedHeader"`
|
|
|
|
Confidence float64
|
|
|
|
Severity Severity
|
2021-05-21 09:53:10 +02:00
|
|
|
EnableAllRules bool `toml:"enableAllRules"`
|
2019-08-02 17:21:33 +02:00
|
|
|
Rules RulesConfig `toml:"rule"`
|
|
|
|
ErrorCode int `toml:"errorCode"`
|
|
|
|
WarningCode int `toml:"warningCode"`
|
|
|
|
Directives DirectivesConfig `toml:"directive"`
|
2021-03-21 00:43:44 +02:00
|
|
|
Exclude []string `toml:"exclude"`
|
2018-02-04 05:37:38 +02:00
|
|
|
}
|