Skip to content

Commit

Permalink
feat: auto-detect go version
Browse files Browse the repository at this point in the history
  • Loading branch information
ldez committed Mar 21, 2022
1 parent f055441 commit 1c92353
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions .golangci.yml
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pkg/commands/run.go
Expand Up @@ -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=<mode> 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"))
Expand Down
14 changes: 14 additions & 0 deletions pkg/lint/lintersdb/manager.go
Expand Up @@ -5,6 +5,7 @@ import (
"path/filepath"
"plugin"

"github.com/ldez/gomoddirectives"
"github.com/spf13/viper"
"golang.org/x/tools/go/analysis"

Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 1c92353

Please sign in to comment.