From 0535baa6dcc223b436c4d1dcee6ff0d2f10d96cd Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Sun, 24 Mar 2024 11:17:38 +0100 Subject: [PATCH 1/8] fix: display warnings on deprecated linter settings --- pkg/config/loader.go | 21 +++++++++++++++++++++ pkg/golinters/godot.go | 1 - 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/pkg/config/loader.go b/pkg/config/loader.go index 782daa4c9250..125d85b542b4 100644 --- a/pkg/config/loader.go +++ b/pkg/config/loader.go @@ -329,6 +329,27 @@ func (l *Loader) handleDeprecation() error { "Please enable `shadow` instead, if you are not using `enable-all`.") } + // Deprecated since v1.42.0. + if l.cfg.LintersSettings.Errcheck.Exclude != "" { + l.warn("The configuration option `errcheck.exclude` is deprecated, please use `errcheck.exclude-functions`.") + } + + // Deprecated since v1.44.0. + if l.cfg.LintersSettings.Gci.LocalPrefixes != "" { + l.warn("The configuration option `gci.local-prefixes` is deprecated, please use `prefix()` inside `gci.sections`.") + } + + // Deprecated since v1.33.0. + if l.cfg.LintersSettings.Godot.CheckAll { + l.warn("The configuration option `godot.check-all` is deprecated, please use `godot.scope: all`.") + } + + // Deprecated since v1.44.0. + if len(l.cfg.LintersSettings.Gomnd.Settings) > 0 { + l.warn("The configuration option `gomnd.settings` is deprecated. " + + "Please use the options `gomnd.checks`,`gomnd.ignored-numbers`,`gomnd.ignored-files`,`gomnd.ignored-functions`.") + } + return nil } diff --git a/pkg/golinters/godot.go b/pkg/golinters/godot.go index 06c160fec613..55394b10fe1f 100644 --- a/pkg/golinters/godot.go +++ b/pkg/golinters/godot.go @@ -29,7 +29,6 @@ func NewGodot(settings *config.GodotSettings) *goanalysis.Linter { } // Convert deprecated setting - // todo(butuzov): remove on v2 release if settings.CheckAll { dotSettings.Scope = godot.AllScope } From ffa295bd1f14e5b091452d09891bda5f7fa4c872 Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Sun, 24 Mar 2024 11:19:12 +0100 Subject: [PATCH 2/8] chore: isolate deprecated settings --- pkg/config/linters_settings.go | 26 +++++++++++++++----------- pkg/config/run.go | 6 +++--- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/pkg/config/linters_settings.go b/pkg/config/linters_settings.go index 6097be06b105..1ac90be1d367 100644 --- a/pkg/config/linters_settings.go +++ b/pkg/config/linters_settings.go @@ -452,10 +452,12 @@ type FunlenSettings struct { } type GciSettings struct { - LocalPrefixes string `mapstructure:"local-prefixes"` // Deprecated Sections []string `mapstructure:"sections"` SkipGenerated bool `mapstructure:"skip-generated"` CustomOrder bool `mapstructure:"custom-order"` + + // Deprecated: use Sections instead. + LocalPrefixes string `mapstructure:"local-prefixes"` } type GinkgoLinterSettings struct { @@ -511,7 +513,7 @@ type GodotSettings struct { Capital bool `mapstructure:"capital"` Period bool `mapstructure:"period"` - // Deprecated: use `Scope` instead + // Deprecated: use Scope instead CheckAll bool `mapstructure:"check-all"` } @@ -548,11 +550,13 @@ type GoImportsSettings struct { } type GoMndSettings struct { - Settings map[string]map[string]any // Deprecated - Checks []string `mapstructure:"checks"` - IgnoredNumbers []string `mapstructure:"ignored-numbers"` - IgnoredFiles []string `mapstructure:"ignored-files"` - IgnoredFunctions []string `mapstructure:"ignored-functions"` + Checks []string `mapstructure:"checks"` + IgnoredNumbers []string `mapstructure:"ignored-numbers"` + IgnoredFiles []string `mapstructure:"ignored-files"` + IgnoredFunctions []string `mapstructure:"ignored-functions"` + + // Deprecated: use root level settings instead. + Settings map[string]map[string]any } type GoModDirectivesSettings struct { @@ -607,7 +611,7 @@ type GovetSettings struct { Settings map[string]map[string]any - // Deprecated: the linter should be enabled inside `Enable`. + // Deprecated: the linter should be enabled inside Enable. CheckShadowing bool `mapstructure:"check-shadowing"` } @@ -814,13 +818,13 @@ type SpancheckSettings struct { } type StaticCheckSettings struct { - // Deprecated: use the global `run.go` instead. - GoVersion string `mapstructure:"go"` - Checks []string `mapstructure:"checks"` Initialisms []string `mapstructure:"initialisms"` // only for stylecheck DotImportWhitelist []string `mapstructure:"dot-import-whitelist"` // only for stylecheck HTTPStatusCodeWhitelist []string `mapstructure:"http-status-code-whitelist"` // only for stylecheck + + // Deprecated: use the global `run.go` instead. + GoVersion string `mapstructure:"go"` } func (s *StaticCheckSettings) HasConfiguration() bool { diff --git a/pkg/config/run.go b/pkg/config/run.go index 1531ab883008..2f6523c0b964 100644 --- a/pkg/config/run.go +++ b/pkg/config/run.go @@ -21,6 +21,9 @@ type Run struct { ExitCodeIfIssuesFound int `mapstructure:"issues-exit-code"` AnalyzeTests bool `mapstructure:"tests"` + AllowParallelRunners bool `mapstructure:"allow-parallel-runners"` + AllowSerialRunners bool `mapstructure:"allow-serial-runners"` + // Deprecated: use Issues.ExcludeFiles instead. SkipFiles []string `mapstructure:"skip-files"` // Deprecated: use Issues.ExcludeDirs instead. @@ -28,9 +31,6 @@ type Run struct { // Deprecated: use Issues.UseDefaultExcludeDirs instead. UseDefaultSkipDirs bool `mapstructure:"skip-dirs-use-default"` - AllowParallelRunners bool `mapstructure:"allow-parallel-runners"` - AllowSerialRunners bool `mapstructure:"allow-serial-runners"` - // Deprecated: use Output.ShowStats instead. ShowStats bool `mapstructure:"show-stats"` } From 21a1a68642260eb04886ea80a58549a730a2b8e8 Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Sun, 24 Mar 2024 11:35:24 +0100 Subject: [PATCH 3/8] chore: manage exclusions --- .golangci.yml | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 28a5dda7b992..bf01de506275 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -143,7 +143,6 @@ linters: # See the comment on top of this file. issues: - # Excluding configuration per-path, per-linter, per-text and per-source exclude-rules: - path: (.+)_test\.go linters: @@ -151,28 +150,39 @@ issues: - gomnd - lll + # The logic of creating a linter is similar between linters, it's not duplication. - path: pkg/golinters linters: - dupl + # Deprecated configuration options. + - path: pkg/commands/run.go + linters: [staticcheck] + text: "SA1019: c.cfg.Run.ShowStats is deprecated: use Output.ShowStats instead." + - path: pkg/commands/config.go + text: "SA1019: cfg.Run.UseDefaultSkipDirs is deprecated: use Issues.UseDefaultExcludeDirs instead." + + # Deprecated linter options. - path: pkg/golinters/errcheck.go linters: [staticcheck] text: "SA1019: errCfg.Exclude is deprecated: use ExcludeFunctions instead" - path: pkg/commands/run.go linters: [staticcheck] text: "SA1019: lsc.Errcheck.Exclude is deprecated: use ExcludeFunctions instead" - - path: pkg/commands/run.go - linters: [staticcheck] - text: "SA1019: c.cfg.Run.ShowStats is deprecated: use Output.ShowStats instead." - path: pkg/golinters/govet.go - text: "SA1019: cfg.CheckShadowing is deprecated: the linter should be enabled inside `Enable`." - - path: pkg/commands/config.go - text: "SA1019: cfg.Run.UseDefaultSkipDirs is deprecated: use Issues.UseDefaultExcludeDirs instead." - + linters: [staticcheck] + text: "SA1019: cfg.CheckShadowing is deprecated: the linter should be enabled inside Enable." - path: pkg/golinters/godot.go linters: [staticcheck] - text: "SA1019: settings.CheckAll is deprecated: use `Scope` instead" + text: "SA1019: settings.CheckAll is deprecated: use Scope instead" + - path: pkg/golinters/gci.go + linters: [staticcheck] + text: "SA1019: settings.LocalPrefixes is deprecated: use Sections instead." + - path: pkg/golinters/gomnd.go + linters: [staticcheck] + text: "SA1019: settings.Settings is deprecated: use root level settings instead." + # Related to `run.go`, it cannot be removed. - path: pkg/golinters/gofumpt.go linters: [staticcheck] text: "SA1019: settings.LangVersion is deprecated: use the global `run.go` instead." @@ -183,6 +193,7 @@ issues: linters: [staticcheck] text: "SA1019: (.+).(GoVersion|LangVersion) is deprecated: use the global `run.go` instead." + # Based on existing code, the modifications should be limited to make maintenance easier. - path: pkg/golinters/unused.go linters: [gocritic] text: "rangeValCopy: each iteration copies 160 bytes \\(consider pointers or indexing\\)" From c9824a65ff8820a6d19edd408715f21c8a9120e5 Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Sun, 24 Mar 2024 11:44:56 +0100 Subject: [PATCH 4/8] fix: handle deprecations before the Go version setting --- pkg/config/loader.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/config/loader.go b/pkg/config/loader.go index 125d85b542b4..fbca33beff3b 100644 --- a/pkg/config/loader.go +++ b/pkg/config/loader.go @@ -59,13 +59,13 @@ func (l *Loader) Load() error { l.applyStringSliceHack() - l.handleGoVersion() - err = l.handleDeprecation() if err != nil { return err } + l.handleGoVersion() + err = l.handleEnableOnlyOption() if err != nil { return err From df3261634036444950a8ff25e030d71acfd4aec8 Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Sun, 24 Mar 2024 14:23:30 +0100 Subject: [PATCH 5/8] fix: less ambiguous message --- pkg/config/loader.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pkg/config/loader.go b/pkg/config/loader.go index fbca33beff3b..2ae8c0d8000b 100644 --- a/pkg/config/loader.go +++ b/pkg/config/loader.go @@ -325,29 +325,29 @@ func (l *Loader) handleDeprecation() error { // Deprecated since v1.57.0, // but it was unofficially deprecated since v1.19 (2019) (https://github.com/golangci/golangci-lint/pull/697). if l.cfg.LintersSettings.Govet.CheckShadowing { - l.warn("The configuration option `govet.check-shadowing` is deprecated. " + + l.warn("The configuration option `linters.govet.check-shadowing` is deprecated. " + "Please enable `shadow` instead, if you are not using `enable-all`.") } // Deprecated since v1.42.0. if l.cfg.LintersSettings.Errcheck.Exclude != "" { - l.warn("The configuration option `errcheck.exclude` is deprecated, please use `errcheck.exclude-functions`.") + l.warn("The configuration option `linters.errcheck.exclude` is deprecated, please use `linters.errcheck.exclude-functions`.") } // Deprecated since v1.44.0. if l.cfg.LintersSettings.Gci.LocalPrefixes != "" { - l.warn("The configuration option `gci.local-prefixes` is deprecated, please use `prefix()` inside `gci.sections`.") + l.warn("The configuration option `linters.gci.local-prefixes` is deprecated, please use `prefix()` inside `linters.gci.sections`.") } // Deprecated since v1.33.0. if l.cfg.LintersSettings.Godot.CheckAll { - l.warn("The configuration option `godot.check-all` is deprecated, please use `godot.scope: all`.") + l.warn("The configuration option `linters.godot.check-all` is deprecated, please use `linters.godot.scope: all`.") } // Deprecated since v1.44.0. if len(l.cfg.LintersSettings.Gomnd.Settings) > 0 { - l.warn("The configuration option `gomnd.settings` is deprecated. " + - "Please use the options `gomnd.checks`,`gomnd.ignored-numbers`,`gomnd.ignored-files`,`gomnd.ignored-functions`.") + l.warn("The configuration option `linters.gomnd.settings` is deprecated. Please use the options " + + "`linters.gomnd.checks`,`linters.gomnd.ignored-numbers`,`linters.gomnd.ignored-files`,`linters.gomnd.ignored-functions`.") } return nil From bebae27a062b0bf39e6ac6db8a74a112d4909c3e Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Sun, 24 Mar 2024 14:24:06 +0100 Subject: [PATCH 6/8] fix: invalid condition --- pkg/config/loader.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/config/loader.go b/pkg/config/loader.go index 2ae8c0d8000b..43b9a3df7f1b 100644 --- a/pkg/config/loader.go +++ b/pkg/config/loader.go @@ -277,7 +277,7 @@ func (l *Loader) handleGoVersion() { if l.cfg.LintersSettings.Gosimple.GoVersion == "" { l.cfg.LintersSettings.Gosimple.GoVersion = trimmedGoVersion } - if l.cfg.LintersSettings.Stylecheck.GoVersion != "" { + if l.cfg.LintersSettings.Stylecheck.GoVersion == "" { l.cfg.LintersSettings.Stylecheck.GoVersion = trimmedGoVersion } } From b277ca3a31e69ad6fbd8179a665fe1fa0d3d0bdf Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Sun, 24 Mar 2024 11:53:44 +0100 Subject: [PATCH 7/8] chore: handle more deprecated linter options --- pkg/config/loader.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/pkg/config/loader.go b/pkg/config/loader.go index 43b9a3df7f1b..cf189df3d1e6 100644 --- a/pkg/config/loader.go +++ b/pkg/config/loader.go @@ -350,6 +350,26 @@ func (l *Loader) handleDeprecation() error { "`linters.gomnd.checks`,`linters.gomnd.ignored-numbers`,`linters.gomnd.ignored-files`,`linters.gomnd.ignored-functions`.") } + // Deprecated since v1.47.0 + if l.cfg.LintersSettings.Gofumpt.LangVersion != "" { + l.warn("The configuration option `linters.gofumpt.lang-version` is deprecated, please use global `run.go`.") + } + + // Deprecated since v1.47.0 + if l.cfg.LintersSettings.Staticcheck.GoVersion != "" { + l.warn("The configuration option `linters.staticcheck.go` is deprecated, please use global `run.go`.") + } + + // Deprecated since v1.47.0 + if l.cfg.LintersSettings.Gosimple.GoVersion != "" { + l.warn("The configuration option `linters.gosimple.go` is deprecated, please use global `run.go`.") + } + + // Deprecated since v1.47.0 + if l.cfg.LintersSettings.Stylecheck.GoVersion != "" { + l.warn("The configuration option `linters.stylecheck.go` is deprecated, please use global `run.go`.") + } + return nil } From d531bd64160b7e57c3bcb52d286bb3a05a0df100 Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Sun, 24 Mar 2024 11:56:21 +0100 Subject: [PATCH 8/8] chore: refactor deprecation handling --- pkg/config/loader.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pkg/config/loader.go b/pkg/config/loader.go index cf189df3d1e6..141137c21ca7 100644 --- a/pkg/config/loader.go +++ b/pkg/config/loader.go @@ -322,6 +322,12 @@ func (l *Loader) handleDeprecation() error { l.cfg.Output.Formats = f } + l.handleLinterOptionDeprecations() + + return nil +} + +func (l *Loader) handleLinterOptionDeprecations() { // Deprecated since v1.57.0, // but it was unofficially deprecated since v1.19 (2019) (https://github.com/golangci/golangci-lint/pull/697). if l.cfg.LintersSettings.Govet.CheckShadowing { @@ -369,8 +375,6 @@ func (l *Loader) handleDeprecation() error { if l.cfg.LintersSettings.Stylecheck.GoVersion != "" { l.warn("The configuration option `linters.stylecheck.go` is deprecated, please use global `run.go`.") } - - return nil } func (l *Loader) handleEnableOnlyOption() error {