config: spread go version on linter's configurations (#2913)

This commit is contained in:
Ludovic Fernandez 2022-06-13 09:01:05 +02:00 committed by GitHub
parent 97eea6ea49
commit 4b218e664c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 35 additions and 5 deletions

View File

@ -557,6 +557,7 @@ linters-settings:
gofumpt: gofumpt:
# Select the Go version to target. # Select the Go version to target.
# Default: "1.15" # Default: "1.15"
# Deprecated: use the global `run.go` instead.
lang-version: "1.17" lang-version: "1.17"
# Module path which contains the source code being formatted. # Module path which contains the source code being formatted.
@ -699,6 +700,7 @@ linters-settings:
gosimple: gosimple:
# Select the Go version to target. # Select the Go version to target.
# Default: 1.13 # Default: 1.13
# Deprecated: use the global `run.go` instead.
go: "1.15" go: "1.15"
# https://staticcheck.io/docs/options#checks # https://staticcheck.io/docs/options#checks
# Default: ["*"] # Default: ["*"]
@ -1543,6 +1545,7 @@ linters-settings:
staticcheck: staticcheck:
# Select the Go version to target. # Select the Go version to target.
# Default: "1.13" # Default: "1.13"
# Deprecated: use the global `run.go` instead.
go: "1.15" go: "1.15"
# https://staticcheck.io/docs/options#checks # https://staticcheck.io/docs/options#checks
# Default: ["*"] # Default: ["*"]
@ -1551,6 +1554,7 @@ linters-settings:
stylecheck: stylecheck:
# Select the Go version to target. # Select the Go version to target.
# Default: 1.13 # Default: 1.13
# Deprecated: use the global `run.go` instead.
go: "1.15" go: "1.15"
# https://staticcheck.io/docs/options#checks # https://staticcheck.io/docs/options#checks
# Default: ["*"] # Default: ["*"]

View File

@ -134,6 +134,14 @@ issues:
- path: pkg/commands/run.go - path: pkg/commands/run.go
text: "SA1019: e.cfg.Run.Deadline is deprecated: Deadline exists for historical compatibility and should not be used." text: "SA1019: e.cfg.Run.Deadline is deprecated: Deadline exists for historical compatibility and should not be used."
- path: pkg/golinters/gofumpt.go
text: "SA1019: settings.LangVersion is deprecated: use the global `run.go` instead."
- path: pkg/golinters/staticcheck_common.go
text: "SA1019: settings.GoVersion is deprecated: use the global `run.go` instead."
- path: pkg/lint/lintersdb/manager.go
text: "SA1019: (.+).(GoVersion|LangVersion) is deprecated: use the global `run.go` instead."
run: run:
timeout: 5m timeout: 5m
go: '1.17' # TODO(ldez): we force to use an old version of Go for the CI and the tests. go: '1.17' # TODO(ldez): we force to use an old version of Go for the CI and the tests.

View File

@ -318,9 +318,11 @@ type GoFmtSettings struct {
} }
type GofumptSettings struct { type GofumptSettings struct {
ModulePath string `mapstructure:"module-path"`
ExtraRules bool `mapstructure:"extra-rules"`
// Deprecated: use the global `run.go` instead.
LangVersion string `mapstructure:"lang-version"` LangVersion string `mapstructure:"lang-version"`
ModulePath string `mapstructure:"module-path"`
ExtraRules bool `mapstructure:"extra-rules"`
} }
type GoHeaderSettings struct { type GoHeaderSettings struct {
@ -527,6 +529,7 @@ type RowsErrCheckSettings struct {
} }
type StaticCheckSettings struct { type StaticCheckSettings struct {
// Deprecated: use the global `run.go` instead.
GoVersion string `mapstructure:"go"` GoVersion string `mapstructure:"go"`
Checks []string `mapstructure:"checks"` Checks []string `mapstructure:"checks"`

View File

@ -9,7 +9,6 @@ import (
func NewStaticcheck(settings *config.StaticCheckSettings) *goanalysis.Linter { func NewStaticcheck(settings *config.StaticCheckSettings) *goanalysis.Linter {
cfg := staticCheckConfig(settings) cfg := staticCheckConfig(settings)
analyzers := setupStaticCheckAnalyzers(staticcheck.Analyzers, getGoVersion(settings), cfg.Checks) analyzers := setupStaticCheckAnalyzers(staticcheck.Analyzers, getGoVersion(settings), cfg.Checks)
return goanalysis.NewLinter( return goanalysis.NewLinter(

View File

@ -24,8 +24,7 @@ func getGoVersion(settings *config.StaticCheckSettings) string {
return goVersion return goVersion
} }
// TODO: uses "1.13" for backward compatibility, but in the future (v2) must be set by using build.Default.ReleaseTags like staticcheck. return "1.17"
return "1.13"
} }
func setupStaticCheckAnalyzers(src []*lint.Analyzer, goVersion string, checks []string) []*analysis.Analyzer { func setupStaticCheckAnalyzers(src []*lint.Analyzer, goVersion string, checks []string) []*analysis.Analyzer {

View File

@ -240,6 +240,23 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
if govetCfg != nil { if govetCfg != nil {
govetCfg.Go = m.cfg.Run.Go govetCfg.Go = m.cfg.Run.Go
} }
if gofumptCfg != nil && gofumptCfg.LangVersion == "" {
gofumptCfg.LangVersion = m.cfg.Run.Go
}
if staticcheckCfg != nil && staticcheckCfg.GoVersion == "" {
staticcheckCfg.GoVersion = m.cfg.Run.Go
}
if gosimpleCfg != nil && gosimpleCfg.GoVersion == "" {
gosimpleCfg.GoVersion = m.cfg.Run.Go
}
if stylecheckCfg != nil && stylecheckCfg.GoVersion != "" {
stylecheckCfg.GoVersion = m.cfg.Run.Go
}
if unusedCfg != nil && unusedCfg.GoVersion == "" {
unusedCfg.GoVersion = m.cfg.Run.Go
}
} }
const megacheckName = "megacheck" const megacheckName = "megacheck"