Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from Jun 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions .golangci.reference.yml
Expand Up @@ -557,6 +557,7 @@ linters-settings:
gofumpt:
# Select the Go version to target.
# Default: "1.15"
# Deprecated: use the global `run.go` instead.
lang-version: "1.17"

# Module path which contains the source code being formatted.
Expand Down Expand Up @@ -699,6 +700,7 @@ linters-settings:
gosimple:
# Select the Go version to target.
# Default: 1.13
# Deprecated: use the global `run.go` instead.
go: "1.15"
# https://staticcheck.io/docs/options#checks
# Default: ["*"]
Expand Down Expand Up @@ -1538,6 +1540,7 @@ linters-settings:
staticcheck:
# Select the Go version to target.
# Default: "1.13"
# Deprecated: use the global `run.go` instead.
go: "1.15"
# https://staticcheck.io/docs/options#checks
# Default: ["*"]
Expand All @@ -1546,6 +1549,7 @@ linters-settings:
stylecheck:
# Select the Go version to target.
# Default: 1.13
# Deprecated: use the global `run.go` instead.
go: "1.15"
# https://staticcheck.io/docs/options#checks
# Default: ["*"]
Expand Down
8 changes: 8 additions & 0 deletions .golangci.yml
Expand Up @@ -134,6 +134,14 @@ issues:
- path: pkg/commands/run.go
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:
timeout: 5m
go: '1.17' # TODO(ldez): we force to use an old version of Go for the CI and the tests.
Expand Down
7 changes: 5 additions & 2 deletions pkg/config/linters_settings.go
Expand Up @@ -317,9 +317,11 @@ type GoFmtSettings 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"`
ModulePath string `mapstructure:"module-path"`
ExtraRules bool `mapstructure:"extra-rules"`
}

type GoHeaderSettings struct {
Expand Down Expand Up @@ -522,6 +524,7 @@ type RowsErrCheckSettings struct {
}

type StaticCheckSettings struct {
// Deprecated: use the global `run.go` instead.
GoVersion string `mapstructure:"go"`

Checks []string `mapstructure:"checks"`
Expand Down
1 change: 0 additions & 1 deletion pkg/golinters/staticcheck.go
Expand Up @@ -9,7 +9,6 @@ import (

func NewStaticcheck(settings *config.StaticCheckSettings) *goanalysis.Linter {
cfg := staticCheckConfig(settings)

analyzers := setupStaticCheckAnalyzers(staticcheck.Analyzers, getGoVersion(settings), cfg.Checks)

return goanalysis.NewLinter(
Expand Down
3 changes: 1 addition & 2 deletions pkg/golinters/staticcheck_common.go
Expand Up @@ -24,8 +24,7 @@ func getGoVersion(settings *config.StaticCheckSettings) string {
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.13"
return "1.17"
}

func setupStaticCheckAnalyzers(src []*lint.Analyzer, goVersion string, checks []string) []*analysis.Analyzer {
Expand Down
17 changes: 17 additions & 0 deletions pkg/lint/lintersdb/manager.go
Expand Up @@ -238,6 +238,23 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
if govetCfg != nil {
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"
Expand Down