Skip to content

Commit

Permalink
config: spread go version on linter's configurations (#2913)
Browse files Browse the repository at this point in the history
  • Loading branch information
ldez authored Jun 13, 2022
1 parent 97eea6e commit 4b218e6
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 5 deletions.
4 changes: 4 additions & 0 deletions .golangci.reference.yml
Original file line number Diff line number Diff line change
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 @@ -1543,6 +1545,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 @@ -1551,6 +1554,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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -318,9 +318,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 @@ -527,6 +529,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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,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

0 comments on commit 4b218e6

Please sign in to comment.