golangci-lint/pkg/lint/linter/config.go

93 lines
1.8 KiB
Go
Raw Normal View History

2018-06-02 11:36:50 +03:00
package linter
const (
PresetFormatting = "format"
PresetComplexity = "complexity"
PresetStyle = "style"
PresetBugs = "bugs"
PresetUnused = "unused"
PresetPerformance = "performance"
)
type Config struct {
Linter Linter
EnabledByDefault bool
NeedsTypeInfo bool
NeedsDepsTypeInfo bool
NeedsSSARepr bool
2018-06-02 11:36:50 +03:00
InPresets []string
Speed int // more value means faster execution of linter
AlternativeNames []string
2018-06-02 11:36:50 +03:00
OriginalURL string // URL of original (not forked) repo, needed for autogenerated README
ParentLinterName string // used only for megacheck's children now
CanAutoFix bool
2018-06-02 11:36:50 +03:00
}
func (lc *Config) WithTypeInfo() *Config {
lc.NeedsTypeInfo = true
2018-06-02 11:36:50 +03:00
return lc
}
func (lc *Config) WithDepsTypeInfo() *Config {
lc.NeedsTypeInfo = true
lc.NeedsDepsTypeInfo = true
return lc
}
func (lc *Config) WithSSA() *Config {
lc.NeedsTypeInfo = true
2018-06-02 11:36:50 +03:00
lc.NeedsSSARepr = true
return lc
}
func (lc *Config) WithPresets(presets ...string) *Config {
2018-06-02 11:36:50 +03:00
lc.InPresets = presets
return lc
}
func (lc *Config) WithSpeed(speed int) *Config {
2018-06-02 11:36:50 +03:00
lc.Speed = speed
return lc
}
func (lc *Config) WithURL(url string) *Config {
2018-06-02 11:36:50 +03:00
lc.OriginalURL = url
return lc
}
func (lc *Config) WithAlternativeNames(names ...string) *Config {
lc.AlternativeNames = names
return lc
}
func (lc *Config) WithParent(parentLinterName string) *Config {
lc.ParentLinterName = parentLinterName
return lc
}
func (lc *Config) WithAutoFix() *Config {
lc.CanAutoFix = true
return lc
}
func (lc *Config) GetSpeed() int {
2018-06-02 11:36:50 +03:00
return lc.Speed
}
func (lc *Config) AllNames() []string {
return append([]string{lc.Name()}, lc.AlternativeNames...)
}
func (lc *Config) Name() string {
return lc.Linter.Name()
}
2018-06-02 11:36:50 +03:00
func NewConfig(linter Linter) *Config {
return &Config{
Linter: linter,
}
}