diff --git a/.golangci.yml b/.golangci.yml index a17d2b119bad..928fd18c7abe 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -130,6 +130,7 @@ issues: run: timeout: 5m + go: '1.17' # TODO(ldez): we force to use an old Go version for the CI and the tests. skip-dirs: - test/testdata_etc - internal/cache diff --git a/pkg/commands/run.go b/pkg/commands/run.go index 61f86ee52368..f4716d184819 100644 --- a/pkg/commands/run.go +++ b/pkg/commands/run.go @@ -95,7 +95,7 @@ func initFlagSet(fs *pflag.FlagSet, cfg *config.Config, m *lintersdb.Manager, is "Modules download mode. If not empty, passed as -mod= to go tools") fs.IntVar(&rc.ExitCodeIfIssuesFound, "issues-exit-code", exitcodes.IssuesFound, wh("Exit code when issues were found")) - fs.StringVar(&rc.Go, "go", "1.17", wh("Targeted Go version")) + fs.StringVar(&rc.Go, "go", "", wh("Targeted Go version")) fs.StringSliceVar(&rc.BuildTags, "build-tags", nil, wh("Build tags")) fs.DurationVar(&rc.Timeout, "deadline", defaultTimeout, wh("Deadline for total work")) diff --git a/pkg/lint/lintersdb/manager.go b/pkg/lint/lintersdb/manager.go index 736bffd16146..afcfdd0a17dd 100644 --- a/pkg/lint/lintersdb/manager.go +++ b/pkg/lint/lintersdb/manager.go @@ -5,6 +5,7 @@ import ( "path/filepath" "plugin" + "github.com/ldez/gomoddirectives" "github.com/spf13/viper" "golang.org/x/tools/go/analysis" @@ -164,6 +165,19 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config { unusedCfg = &m.cfg.LintersSettings.Unused varnamelenCfg = &m.cfg.LintersSettings.Varnamelen wrapcheckCfg = &m.cfg.LintersSettings.Wrapcheck + + if m.cfg.Run.Go == "" { + file, err := gomoddirectives.GetModuleFile() + if err != nil { + m.log.Warnf("unable to find go.mod file: %v", err) + } + + if file != nil && file.Go != nil { + m.cfg.Run.Go = file.Go.Version + } else { + m.cfg.Run.Go = "1.17" + } + } } const megacheckName = "megacheck"