Skip to content

Commit 66ec75e

Browse files
authored
fix: display warnings on deprecated linter options (#4568)
1 parent 9ec57c8 commit 66ec75e

File tree

5 files changed

+88
-29
lines changed

5 files changed

+88
-29
lines changed

.golangci.yml

+20-9
Original file line numberDiff line numberDiff line change
@@ -143,36 +143,46 @@ linters:
143143
# See the comment on top of this file.
144144

145145
issues:
146-
# Excluding configuration per-path, per-linter, per-text and per-source
147146
exclude-rules:
148147
- path: (.+)_test\.go
149148
linters:
150149
- dupl
151150
- gomnd
152151
- lll
153152

153+
# The logic of creating a linter is similar between linters, it's not duplication.
154154
- path: pkg/golinters
155155
linters:
156156
- dupl
157157

158+
# Deprecated configuration options.
159+
- path: pkg/commands/run.go
160+
linters: [staticcheck]
161+
text: "SA1019: c.cfg.Run.ShowStats is deprecated: use Output.ShowStats instead."
162+
- path: pkg/commands/config.go
163+
text: "SA1019: cfg.Run.UseDefaultSkipDirs is deprecated: use Issues.UseDefaultExcludeDirs instead."
164+
165+
# Deprecated linter options.
158166
- path: pkg/golinters/errcheck.go
159167
linters: [staticcheck]
160168
text: "SA1019: errCfg.Exclude is deprecated: use ExcludeFunctions instead"
161169
- path: pkg/commands/run.go
162170
linters: [staticcheck]
163171
text: "SA1019: lsc.Errcheck.Exclude is deprecated: use ExcludeFunctions instead"
164-
- path: pkg/commands/run.go
165-
linters: [staticcheck]
166-
text: "SA1019: c.cfg.Run.ShowStats is deprecated: use Output.ShowStats instead."
167172
- path: pkg/golinters/govet.go
168-
text: "SA1019: cfg.CheckShadowing is deprecated: the linter should be enabled inside `Enable`."
169-
- path: pkg/commands/config.go
170-
text: "SA1019: cfg.Run.UseDefaultSkipDirs is deprecated: use Issues.UseDefaultExcludeDirs instead."
171-
173+
linters: [staticcheck]
174+
text: "SA1019: cfg.CheckShadowing is deprecated: the linter should be enabled inside Enable."
172175
- path: pkg/golinters/godot.go
173176
linters: [staticcheck]
174-
text: "SA1019: settings.CheckAll is deprecated: use `Scope` instead"
177+
text: "SA1019: settings.CheckAll is deprecated: use Scope instead"
178+
- path: pkg/golinters/gci.go
179+
linters: [staticcheck]
180+
text: "SA1019: settings.LocalPrefixes is deprecated: use Sections instead."
181+
- path: pkg/golinters/gomnd.go
182+
linters: [staticcheck]
183+
text: "SA1019: settings.Settings is deprecated: use root level settings instead."
175184

185+
# Related to `run.go`, it cannot be removed.
176186
- path: pkg/golinters/gofumpt.go
177187
linters: [staticcheck]
178188
text: "SA1019: settings.LangVersion is deprecated: use the global `run.go` instead."
@@ -183,6 +193,7 @@ issues:
183193
linters: [staticcheck]
184194
text: "SA1019: (.+).(GoVersion|LangVersion) is deprecated: use the global `run.go` instead."
185195

196+
# Based on existing code, the modifications should be limited to make maintenance easier.
186197
- path: pkg/golinters/unused.go
187198
linters: [gocritic]
188199
text: "rangeValCopy: each iteration copies 160 bytes \\(consider pointers or indexing\\)"

pkg/config/linters_settings.go

+15-11
Original file line numberDiff line numberDiff line change
@@ -452,10 +452,12 @@ type FunlenSettings struct {
452452
}
453453

454454
type GciSettings struct {
455-
LocalPrefixes string `mapstructure:"local-prefixes"` // Deprecated
456455
Sections []string `mapstructure:"sections"`
457456
SkipGenerated bool `mapstructure:"skip-generated"`
458457
CustomOrder bool `mapstructure:"custom-order"`
458+
459+
// Deprecated: use Sections instead.
460+
LocalPrefixes string `mapstructure:"local-prefixes"`
459461
}
460462

461463
type GinkgoLinterSettings struct {
@@ -511,7 +513,7 @@ type GodotSettings struct {
511513
Capital bool `mapstructure:"capital"`
512514
Period bool `mapstructure:"period"`
513515

514-
// Deprecated: use `Scope` instead
516+
// Deprecated: use Scope instead
515517
CheckAll bool `mapstructure:"check-all"`
516518
}
517519

@@ -548,11 +550,13 @@ type GoImportsSettings struct {
548550
}
549551

550552
type GoMndSettings struct {
551-
Settings map[string]map[string]any // Deprecated
552-
Checks []string `mapstructure:"checks"`
553-
IgnoredNumbers []string `mapstructure:"ignored-numbers"`
554-
IgnoredFiles []string `mapstructure:"ignored-files"`
555-
IgnoredFunctions []string `mapstructure:"ignored-functions"`
553+
Checks []string `mapstructure:"checks"`
554+
IgnoredNumbers []string `mapstructure:"ignored-numbers"`
555+
IgnoredFiles []string `mapstructure:"ignored-files"`
556+
IgnoredFunctions []string `mapstructure:"ignored-functions"`
557+
558+
// Deprecated: use root level settings instead.
559+
Settings map[string]map[string]any
556560
}
557561

558562
type GoModDirectivesSettings struct {
@@ -607,7 +611,7 @@ type GovetSettings struct {
607611

608612
Settings map[string]map[string]any
609613

610-
// Deprecated: the linter should be enabled inside `Enable`.
614+
// Deprecated: the linter should be enabled inside Enable.
611615
CheckShadowing bool `mapstructure:"check-shadowing"`
612616
}
613617

@@ -814,13 +818,13 @@ type SpancheckSettings struct {
814818
}
815819

816820
type StaticCheckSettings struct {
817-
// Deprecated: use the global `run.go` instead.
818-
GoVersion string `mapstructure:"go"`
819-
820821
Checks []string `mapstructure:"checks"`
821822
Initialisms []string `mapstructure:"initialisms"` // only for stylecheck
822823
DotImportWhitelist []string `mapstructure:"dot-import-whitelist"` // only for stylecheck
823824
HTTPStatusCodeWhitelist []string `mapstructure:"http-status-code-whitelist"` // only for stylecheck
825+
826+
// Deprecated: use the global `run.go` instead.
827+
GoVersion string `mapstructure:"go"`
824828
}
825829

826830
func (s *StaticCheckSettings) HasConfiguration() bool {

pkg/config/loader.go

+50-5
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,13 @@ func (l *Loader) Load() error {
5959

6060
l.applyStringSliceHack()
6161

62-
l.handleGoVersion()
63-
6462
err = l.handleDeprecation()
6563
if err != nil {
6664
return err
6765
}
6866

67+
l.handleGoVersion()
68+
6969
err = l.handleEnableOnlyOption()
7070
if err != nil {
7171
return err
@@ -277,7 +277,7 @@ func (l *Loader) handleGoVersion() {
277277
if l.cfg.LintersSettings.Gosimple.GoVersion == "" {
278278
l.cfg.LintersSettings.Gosimple.GoVersion = trimmedGoVersion
279279
}
280-
if l.cfg.LintersSettings.Stylecheck.GoVersion != "" {
280+
if l.cfg.LintersSettings.Stylecheck.GoVersion == "" {
281281
l.cfg.LintersSettings.Stylecheck.GoVersion = trimmedGoVersion
282282
}
283283
}
@@ -322,14 +322,59 @@ func (l *Loader) handleDeprecation() error {
322322
l.cfg.Output.Formats = f
323323
}
324324

325+
l.handleLinterOptionDeprecations()
326+
327+
return nil
328+
}
329+
330+
func (l *Loader) handleLinterOptionDeprecations() {
325331
// Deprecated since v1.57.0,
326332
// but it was unofficially deprecated since v1.19 (2019) (https://github.com/golangci/golangci-lint/pull/697).
327333
if l.cfg.LintersSettings.Govet.CheckShadowing {
328-
l.warn("The configuration option `govet.check-shadowing` is deprecated. " +
334+
l.warn("The configuration option `linters.govet.check-shadowing` is deprecated. " +
329335
"Please enable `shadow` instead, if you are not using `enable-all`.")
330336
}
331337

332-
return nil
338+
// Deprecated since v1.42.0.
339+
if l.cfg.LintersSettings.Errcheck.Exclude != "" {
340+
l.warn("The configuration option `linters.errcheck.exclude` is deprecated, please use `linters.errcheck.exclude-functions`.")
341+
}
342+
343+
// Deprecated since v1.44.0.
344+
if l.cfg.LintersSettings.Gci.LocalPrefixes != "" {
345+
l.warn("The configuration option `linters.gci.local-prefixes` is deprecated, please use `prefix()` inside `linters.gci.sections`.")
346+
}
347+
348+
// Deprecated since v1.33.0.
349+
if l.cfg.LintersSettings.Godot.CheckAll {
350+
l.warn("The configuration option `linters.godot.check-all` is deprecated, please use `linters.godot.scope: all`.")
351+
}
352+
353+
// Deprecated since v1.44.0.
354+
if len(l.cfg.LintersSettings.Gomnd.Settings) > 0 {
355+
l.warn("The configuration option `linters.gomnd.settings` is deprecated. Please use the options " +
356+
"`linters.gomnd.checks`,`linters.gomnd.ignored-numbers`,`linters.gomnd.ignored-files`,`linters.gomnd.ignored-functions`.")
357+
}
358+
359+
// Deprecated since v1.47.0
360+
if l.cfg.LintersSettings.Gofumpt.LangVersion != "" {
361+
l.warn("The configuration option `linters.gofumpt.lang-version` is deprecated, please use global `run.go`.")
362+
}
363+
364+
// Deprecated since v1.47.0
365+
if l.cfg.LintersSettings.Staticcheck.GoVersion != "" {
366+
l.warn("The configuration option `linters.staticcheck.go` is deprecated, please use global `run.go`.")
367+
}
368+
369+
// Deprecated since v1.47.0
370+
if l.cfg.LintersSettings.Gosimple.GoVersion != "" {
371+
l.warn("The configuration option `linters.gosimple.go` is deprecated, please use global `run.go`.")
372+
}
373+
374+
// Deprecated since v1.47.0
375+
if l.cfg.LintersSettings.Stylecheck.GoVersion != "" {
376+
l.warn("The configuration option `linters.stylecheck.go` is deprecated, please use global `run.go`.")
377+
}
333378
}
334379

335380
func (l *Loader) handleEnableOnlyOption() error {

pkg/config/run.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,16 @@ type Run struct {
2121
ExitCodeIfIssuesFound int `mapstructure:"issues-exit-code"`
2222
AnalyzeTests bool `mapstructure:"tests"`
2323

24+
AllowParallelRunners bool `mapstructure:"allow-parallel-runners"`
25+
AllowSerialRunners bool `mapstructure:"allow-serial-runners"`
26+
2427
// Deprecated: use Issues.ExcludeFiles instead.
2528
SkipFiles []string `mapstructure:"skip-files"`
2629
// Deprecated: use Issues.ExcludeDirs instead.
2730
SkipDirs []string `mapstructure:"skip-dirs"`
2831
// Deprecated: use Issues.UseDefaultExcludeDirs instead.
2932
UseDefaultSkipDirs bool `mapstructure:"skip-dirs-use-default"`
3033

31-
AllowParallelRunners bool `mapstructure:"allow-parallel-runners"`
32-
AllowSerialRunners bool `mapstructure:"allow-serial-runners"`
33-
3434
// Deprecated: use Output.ShowStats instead.
3535
ShowStats bool `mapstructure:"show-stats"`
3636
}

pkg/golinters/godot.go

-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ func NewGodot(settings *config.GodotSettings) *goanalysis.Linter {
2929
}
3030

3131
// Convert deprecated setting
32-
// todo(butuzov): remove on v2 release
3332
if settings.CheckAll {
3433
dotSettings.Scope = godot.AllScope
3534
}

0 commit comments

Comments
 (0)