
Use go/packages instead of x/tools/loader: it allows to work with go modules and speedups loading of packages with the help of build cache. A lot of linters became "fast": they are enabled by --fast now and work in 1-2 seconds. Only unparam, interfacer and megacheck are "slow" linters now. Average project is analyzed 20-40% faster than before if all linters are enabled! If we enable all linters except unparam, interfacer and megacheck analysis is 10-20x faster!
74 lines
1.3 KiB
Go
74 lines
1.3 KiB
Go
package linter
|
|
|
|
const (
|
|
PresetFormatting = "format"
|
|
PresetComplexity = "complexity"
|
|
PresetStyle = "style"
|
|
PresetBugs = "bugs"
|
|
PresetUnused = "unused"
|
|
PresetPerformance = "performance"
|
|
)
|
|
|
|
type Config struct {
|
|
Linter Linter
|
|
EnabledByDefault bool
|
|
|
|
NeedsTypeInfo bool
|
|
NeedsSSARepr bool
|
|
|
|
InPresets []string
|
|
Speed int // more value means faster execution of linter
|
|
AlternativeNames []string
|
|
|
|
OriginalURL string // URL of original (not forked) repo, needed for autogenerated README
|
|
}
|
|
|
|
func (lc Config) WithTypeInfo() Config {
|
|
lc.NeedsTypeInfo = true
|
|
return lc
|
|
}
|
|
|
|
func (lc Config) WithSSA() Config {
|
|
lc.NeedsTypeInfo = true
|
|
lc.NeedsSSARepr = true
|
|
return lc
|
|
}
|
|
|
|
func (lc Config) WithPresets(presets ...string) Config {
|
|
lc.InPresets = presets
|
|
return lc
|
|
}
|
|
|
|
func (lc Config) WithSpeed(speed int) Config {
|
|
lc.Speed = speed
|
|
return lc
|
|
}
|
|
|
|
func (lc Config) WithURL(url string) Config {
|
|
lc.OriginalURL = url
|
|
return lc
|
|
}
|
|
|
|
func (lc Config) WithAlternativeNames(names ...string) Config {
|
|
lc.AlternativeNames = names
|
|
return lc
|
|
}
|
|
|
|
func (lc Config) GetSpeed() int {
|
|
return lc.Speed
|
|
}
|
|
|
|
func (lc Config) AllNames() []string {
|
|
return append([]string{lc.Name()}, lc.AlternativeNames...)
|
|
}
|
|
|
|
func (lc Config) Name() string {
|
|
return lc.Linter.Name()
|
|
}
|
|
|
|
func NewConfig(linter Linter) *Config {
|
|
return &Config{
|
|
Linter: linter,
|
|
}
|
|
}
|