Skip to content

Commit

Permalink
govet: add a warning about the deprecation of check-shadowing (#4535)
Browse files Browse the repository at this point in the history
  • Loading branch information
ldez authored Mar 19, 2024
1 parent cba35e1 commit 3dbe882
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 43 deletions.
64 changes: 30 additions & 34 deletions .golangci.next.reference.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1074,40 +1074,6 @@ linters-settings:
- Katakana

govet:
# Report about shadowed variables.
# Default: false
check-shadowing: true

# Settings per analyzer.
settings:
# Analyzer name, run `go tool vet help` to see all analyzers.
printf:
# Comma-separated list of print function names to check (in addition to default, see `go tool vet help printf`).
# Default: []
funcs:
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Infof
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Warnf
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Errorf
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf
shadow:
# Whether to be strict about shadowing; can be noisy.
# Default: false
strict: true
unusedresult:
# Comma-separated list of functions whose results must be used
# (in addition to default:
# context.WithCancel, context.WithDeadline, context.WithTimeout, context.WithValue, errors.New, fmt.Errorf,
# fmt.Sprint, fmt.Sprintf, sort.Reverse
# ).
# Default: []
funcs:
- pkg.MyFunc
# Comma-separated list of names of methods of type func() string whose results must be used
# (in addition to default Error,String)
# Default: []
stringmethods:
- MyMethod

# Disable all analyzers.
# Default: false
disable-all: true
Expand Down Expand Up @@ -1214,6 +1180,36 @@ linters-settings:
- unusedresult
- unusedwrite

# Settings per analyzer.
settings:
# Analyzer name, run `go tool vet help` to see all analyzers.
printf:
# Comma-separated list of print function names to check (in addition to default, see `go tool vet help printf`).
# Default: []
funcs:
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Infof
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Warnf
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Errorf
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf
shadow:
# Whether to be strict about shadowing; can be noisy.
# Default: false
strict: true
unusedresult:
# Comma-separated list of functions whose results must be used
# (in addition to default:
# context.WithCancel, context.WithDeadline, context.WithTimeout, context.WithValue, errors.New, fmt.Errorf,
# fmt.Sprint, fmt.Sprintf, sort.Reverse
# ).
# Default: []
funcs:
- pkg.MyFunc
# Comma-separated list of names of methods of type func() string whose results must be used
# (in addition to default Error,String)
# Default: []
stringmethods:
- MyMethod

grouper:
# Require the use of a single global 'const' declaration only.
# Default: false
Expand Down
2 changes: 2 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ issues:
- 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: settings.CheckShadowing is deprecated: the linter should be enabled inside `Enable`."

- path: pkg/golinters/gofumpt.go
linters: [staticcheck]
Expand Down
5 changes: 0 additions & 5 deletions jsonschema/golangci.next.jsonschema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1661,11 +1661,6 @@
"type": "object",
"additionalProperties": false,
"properties": {
"check-shadowing": {
"description": "Report shadowed variables.",
"type": "boolean",
"default": true
},
"settings": {
"description": "Settings per analyzer. Map of analyzer name to specific settings.\nRun `go tool vet help` to find out more.",
"type": "object",
Expand Down
9 changes: 6 additions & 3 deletions pkg/config/linters_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -598,14 +598,17 @@ type GosmopolitanSettings struct {
}

type GovetSettings struct {
Go string `mapstructure:"-"`
CheckShadowing bool `mapstructure:"check-shadowing"`
Settings map[string]map[string]any
Go string `mapstructure:"-"`

Enable []string
Disable []string
EnableAll bool `mapstructure:"enable-all"`
DisableAll bool `mapstructure:"disable-all"`

Settings map[string]map[string]any

// Deprecated: the linter should be enabled inside `Enable`.
CheckShadowing bool `mapstructure:"check-shadowing"`
}

func (cfg *GovetSettings) Validate() error {
Expand Down
7 changes: 7 additions & 0 deletions pkg/config/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,13 @@ func (l *Loader) handleDeprecation() error {
l.cfg.Output.Formats = f
}

// 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. " +
"Please enable `shadow` instead, if you are not using `enable-all`.")
}

return nil
}

Expand Down
3 changes: 2 additions & 1 deletion test/testdata/configs/govet.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
linters-settings:
govet:
check-shadowing: true
enable:
- shadow

0 comments on commit 3dbe882

Please sign in to comment.