feat: automatic Go version detection (#2669)

* feat: disable unsupported go1.18 govet analyzers
* fix: inactivate interfacer with go1.18
This commit is contained in:
Ludovic Fernandez 2022-03-23 16:54:11 +01:00 committed by GitHub
parent da0a6b3b8a
commit 7bbbe77e5e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 112 additions and 69 deletions

View file

@ -1,9 +1,6 @@
package linter
import (
"strings"
hcversion "github.com/hashicorp/go-version"
"golang.org/x/tools/go/analysis"
"golang.org/x/tools/go/packages"
@ -126,7 +123,7 @@ func (lc *Config) Name() string {
}
func (lc *Config) WithNoopFallback(cfg *config.Config) *Config {
if isGreaterThanOrEqualGo118(cfg) {
if cfg != nil && config.IsGreaterThanOrEqualGo118(cfg.Run.Go) {
lc.Linter = &Noop{
name: lc.Linter.Name(),
desc: lc.Linter.Desc(),
@ -134,6 +131,9 @@ func (lc *Config) WithNoopFallback(cfg *config.Config) *Config {
return nil, nil
},
}
lc.LoadMode = 0
return lc.WithLoadFiles()
}
return lc
@ -145,21 +145,3 @@ func NewConfig(linter Linter) *Config {
}
return lc.WithLoadFiles()
}
func isGreaterThanOrEqualGo118(cfg *config.Config) bool {
if cfg == nil {
return false
}
v1, err := hcversion.NewVersion(strings.TrimPrefix(cfg.Run.Go, "go"))
if err != nil {
return false
}
limit, err := hcversion.NewVersion("1.18")
if err != nil {
return false
}
return v1.GreaterThanOrEqual(limit)
}