govet: add a warning about the deprecation of check-shadowing (#4535)

This commit is contained in:
Ludovic Fernandez 2024-03-19 14:27:02 +01:00 committed by GitHub
parent cba35e1d53
commit 3dbe882839
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 47 additions and 43 deletions

View File

@ -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
@ -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

View File

@ -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]

View File

@ -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",

View File

@ -599,13 +599,16 @@ type GosmopolitanSettings struct {
type GovetSettings struct {
Go string `mapstructure:"-"`
CheckShadowing bool `mapstructure:"check-shadowing"`
Settings map[string]map[string]any
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 {

View File

@ -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
}

View File

@ -1,3 +1,4 @@
linters-settings:
govet:
check-shadowing: true
enable:
- shadow