Skip to content

Commit 4b218e6

Browse files
authored
config: spread go version on linter's configurations (#2913)
1 parent 97eea6e commit 4b218e6

File tree

6 files changed

+35
-5
lines changed

6 files changed

+35
-5
lines changed

.golangci.reference.yml

+4
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,7 @@ linters-settings:
557557
gofumpt:
558558
# Select the Go version to target.
559559
# Default: "1.15"
560+
# Deprecated: use the global `run.go` instead.
560561
lang-version: "1.17"
561562

562563
# Module path which contains the source code being formatted.
@@ -699,6 +700,7 @@ linters-settings:
699700
gosimple:
700701
# Select the Go version to target.
701702
# Default: 1.13
703+
# Deprecated: use the global `run.go` instead.
702704
go: "1.15"
703705
# https://staticcheck.io/docs/options#checks
704706
# Default: ["*"]
@@ -1543,6 +1545,7 @@ linters-settings:
15431545
staticcheck:
15441546
# Select the Go version to target.
15451547
# Default: "1.13"
1548+
# Deprecated: use the global `run.go` instead.
15461549
go: "1.15"
15471550
# https://staticcheck.io/docs/options#checks
15481551
# Default: ["*"]
@@ -1551,6 +1554,7 @@ linters-settings:
15511554
stylecheck:
15521555
# Select the Go version to target.
15531556
# Default: 1.13
1557+
# Deprecated: use the global `run.go` instead.
15541558
go: "1.15"
15551559
# https://staticcheck.io/docs/options#checks
15561560
# Default: ["*"]

.golangci.yml

+8
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,14 @@ issues:
134134
- path: pkg/commands/run.go
135135
text: "SA1019: e.cfg.Run.Deadline is deprecated: Deadline exists for historical compatibility and should not be used."
136136

137+
- path: pkg/golinters/gofumpt.go
138+
text: "SA1019: settings.LangVersion is deprecated: use the global `run.go` instead."
139+
- path: pkg/golinters/staticcheck_common.go
140+
text: "SA1019: settings.GoVersion is deprecated: use the global `run.go` instead."
141+
- path: pkg/lint/lintersdb/manager.go
142+
text: "SA1019: (.+).(GoVersion|LangVersion) is deprecated: use the global `run.go` instead."
143+
144+
137145
run:
138146
timeout: 5m
139147
go: '1.17' # TODO(ldez): we force to use an old version of Go for the CI and the tests.

pkg/config/linters_settings.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -318,9 +318,11 @@ type GoFmtSettings struct {
318318
}
319319

320320
type GofumptSettings struct {
321+
ModulePath string `mapstructure:"module-path"`
322+
ExtraRules bool `mapstructure:"extra-rules"`
323+
324+
// Deprecated: use the global `run.go` instead.
321325
LangVersion string `mapstructure:"lang-version"`
322-
ModulePath string `mapstructure:"module-path"`
323-
ExtraRules bool `mapstructure:"extra-rules"`
324326
}
325327

326328
type GoHeaderSettings struct {
@@ -527,6 +529,7 @@ type RowsErrCheckSettings struct {
527529
}
528530

529531
type StaticCheckSettings struct {
532+
// Deprecated: use the global `run.go` instead.
530533
GoVersion string `mapstructure:"go"`
531534

532535
Checks []string `mapstructure:"checks"`

pkg/golinters/staticcheck.go

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99

1010
func NewStaticcheck(settings *config.StaticCheckSettings) *goanalysis.Linter {
1111
cfg := staticCheckConfig(settings)
12-
1312
analyzers := setupStaticCheckAnalyzers(staticcheck.Analyzers, getGoVersion(settings), cfg.Checks)
1413

1514
return goanalysis.NewLinter(

pkg/golinters/staticcheck_common.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ func getGoVersion(settings *config.StaticCheckSettings) string {
2424
return goVersion
2525
}
2626

27-
// TODO: uses "1.13" for backward compatibility, but in the future (v2) must be set by using build.Default.ReleaseTags like staticcheck.
28-
return "1.13"
27+
return "1.17"
2928
}
3029

3130
func setupStaticCheckAnalyzers(src []*lint.Analyzer, goVersion string, checks []string) []*analysis.Analyzer {

pkg/lint/lintersdb/manager.go

+17
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,23 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
240240
if govetCfg != nil {
241241
govetCfg.Go = m.cfg.Run.Go
242242
}
243+
244+
if gofumptCfg != nil && gofumptCfg.LangVersion == "" {
245+
gofumptCfg.LangVersion = m.cfg.Run.Go
246+
}
247+
248+
if staticcheckCfg != nil && staticcheckCfg.GoVersion == "" {
249+
staticcheckCfg.GoVersion = m.cfg.Run.Go
250+
}
251+
if gosimpleCfg != nil && gosimpleCfg.GoVersion == "" {
252+
gosimpleCfg.GoVersion = m.cfg.Run.Go
253+
}
254+
if stylecheckCfg != nil && stylecheckCfg.GoVersion != "" {
255+
stylecheckCfg.GoVersion = m.cfg.Run.Go
256+
}
257+
if unusedCfg != nil && unusedCfg.GoVersion == "" {
258+
unusedCfg.GoVersion = m.cfg.Run.Go
259+
}
243260
}
244261

245262
const megacheckName = "megacheck"

0 commit comments

Comments
 (0)