Skip to content

Commit 3dbe882

Browse files
authored
govet: add a warning about the deprecation of check-shadowing (#4535)
1 parent cba35e1 commit 3dbe882

File tree

6 files changed

+47
-43
lines changed

6 files changed

+47
-43
lines changed

.golangci.next.reference.yml

+30-34
Original file line numberDiff line numberDiff line change
@@ -1074,40 +1074,6 @@ linters-settings:
10741074
- Katakana
10751075

10761076
govet:
1077-
# Report about shadowed variables.
1078-
# Default: false
1079-
check-shadowing: true
1080-
1081-
# Settings per analyzer.
1082-
settings:
1083-
# Analyzer name, run `go tool vet help` to see all analyzers.
1084-
printf:
1085-
# Comma-separated list of print function names to check (in addition to default, see `go tool vet help printf`).
1086-
# Default: []
1087-
funcs:
1088-
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Infof
1089-
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Warnf
1090-
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Errorf
1091-
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf
1092-
shadow:
1093-
# Whether to be strict about shadowing; can be noisy.
1094-
# Default: false
1095-
strict: true
1096-
unusedresult:
1097-
# Comma-separated list of functions whose results must be used
1098-
# (in addition to default:
1099-
# context.WithCancel, context.WithDeadline, context.WithTimeout, context.WithValue, errors.New, fmt.Errorf,
1100-
# fmt.Sprint, fmt.Sprintf, sort.Reverse
1101-
# ).
1102-
# Default: []
1103-
funcs:
1104-
- pkg.MyFunc
1105-
# Comma-separated list of names of methods of type func() string whose results must be used
1106-
# (in addition to default Error,String)
1107-
# Default: []
1108-
stringmethods:
1109-
- MyMethod
1110-
11111077
# Disable all analyzers.
11121078
# Default: false
11131079
disable-all: true
@@ -1214,6 +1180,36 @@ linters-settings:
12141180
- unusedresult
12151181
- unusedwrite
12161182

1183+
# Settings per analyzer.
1184+
settings:
1185+
# Analyzer name, run `go tool vet help` to see all analyzers.
1186+
printf:
1187+
# Comma-separated list of print function names to check (in addition to default, see `go tool vet help printf`).
1188+
# Default: []
1189+
funcs:
1190+
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Infof
1191+
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Warnf
1192+
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Errorf
1193+
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf
1194+
shadow:
1195+
# Whether to be strict about shadowing; can be noisy.
1196+
# Default: false
1197+
strict: true
1198+
unusedresult:
1199+
# Comma-separated list of functions whose results must be used
1200+
# (in addition to default:
1201+
# context.WithCancel, context.WithDeadline, context.WithTimeout, context.WithValue, errors.New, fmt.Errorf,
1202+
# fmt.Sprint, fmt.Sprintf, sort.Reverse
1203+
# ).
1204+
# Default: []
1205+
funcs:
1206+
- pkg.MyFunc
1207+
# Comma-separated list of names of methods of type func() string whose results must be used
1208+
# (in addition to default Error,String)
1209+
# Default: []
1210+
stringmethods:
1211+
- MyMethod
1212+
12171213
grouper:
12181214
# Require the use of a single global 'const' declaration only.
12191215
# Default: false

.golangci.yml

+2
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@ issues:
155155
- path: pkg/commands/run.go
156156
linters: [staticcheck]
157157
text: "SA1019: c.cfg.Run.ShowStats is deprecated: use Output.ShowStats instead."
158+
- path: pkg/golinters/govet.go
159+
text: "SA1019: settings.CheckShadowing is deprecated: the linter should be enabled inside `Enable`."
158160

159161
- path: pkg/golinters/gofumpt.go
160162
linters: [staticcheck]

jsonschema/golangci.next.jsonschema.json

-5
Original file line numberDiff line numberDiff line change
@@ -1661,11 +1661,6 @@
16611661
"type": "object",
16621662
"additionalProperties": false,
16631663
"properties": {
1664-
"check-shadowing": {
1665-
"description": "Report shadowed variables.",
1666-
"type": "boolean",
1667-
"default": true
1668-
},
16691664
"settings": {
16701665
"description": "Settings per analyzer. Map of analyzer name to specific settings.\nRun `go tool vet help` to find out more.",
16711666
"type": "object",

pkg/config/linters_settings.go

+6-3
Original file line numberDiff line numberDiff line change
@@ -598,14 +598,17 @@ type GosmopolitanSettings struct {
598598
}
599599

600600
type GovetSettings struct {
601-
Go string `mapstructure:"-"`
602-
CheckShadowing bool `mapstructure:"check-shadowing"`
603-
Settings map[string]map[string]any
601+
Go string `mapstructure:"-"`
604602

605603
Enable []string
606604
Disable []string
607605
EnableAll bool `mapstructure:"enable-all"`
608606
DisableAll bool `mapstructure:"disable-all"`
607+
608+
Settings map[string]map[string]any
609+
610+
// Deprecated: the linter should be enabled inside `Enable`.
611+
CheckShadowing bool `mapstructure:"check-shadowing"`
609612
}
610613

611614
func (cfg *GovetSettings) Validate() error {

pkg/config/loader.go

+7
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,13 @@ func (l *Loader) handleDeprecation() error {
322322
l.cfg.Output.Formats = f
323323
}
324324

325+
// Deprecated since v1.57.0,
326+
// but it was unofficially deprecated since v1.19 (2019) (https://github.com/golangci/golangci-lint/pull/697).
327+
if l.cfg.LintersSettings.Govet.CheckShadowing {
328+
l.warn("The configuration option `govet.check-shadowing` is deprecated. " +
329+
"Please enable `shadow` instead, if you are not using `enable-all`.")
330+
}
331+
325332
return nil
326333
}
327334

test/testdata/configs/govet.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
linters-settings:
22
govet:
3-
check-shadowing: true
3+
enable:
4+
- shadow

0 commit comments

Comments
 (0)