Skip to content

Commit

Permalink
fix: display warnings on deprecated linter options (#4568)
Browse files Browse the repository at this point in the history
  • Loading branch information
ldez committed Mar 24, 2024
1 parent 9ec57c8 commit 66ec75e
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 29 deletions.
29 changes: 20 additions & 9 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -143,36 +143,46 @@ 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:
- dupl
- 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."
Expand All @@ -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\\)"
Expand Down
26 changes: 15 additions & 11 deletions pkg/config/linters_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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"`
}

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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"`
}

Expand Down Expand Up @@ -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 {
Expand Down
55 changes: 50 additions & 5 deletions pkg/config/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
}
Expand Down Expand Up @@ -322,14 +322,59 @@ 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 {
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`.")
}

return nil
// Deprecated since v1.42.0.
if l.cfg.LintersSettings.Errcheck.Exclude != "" {
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 `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 `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 `linters.gomnd.settings` is deprecated. Please use the options " +
"`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`.")
}
}

func (l *Loader) handleEnableOnlyOption() error {
Expand Down
6 changes: 3 additions & 3 deletions pkg/config/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@ 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.
SkipDirs []string `mapstructure:"skip-dirs"`
// 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"`
}
Expand Down
1 change: 0 additions & 1 deletion pkg/golinters/godot.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 66ec75e

Please sign in to comment.