Skip to content

Commit 2d61f70

Browse files
committed
golangci-lint: govet: enable shadow check
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
1 parent 606cbd6 commit 2d61f70

9 files changed

Lines changed: 81 additions & 74 deletions

File tree

.golangci.yml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ linters-settings:
4242
gocyclo:
4343
min-complexity: 16
4444
govet:
45-
check-shadowing: false
45+
check-shadowing: true
46+
settings:
47+
shadow:
48+
strict: true
4649
lll:
4750
line-length: 200
4851
nakedret:
@@ -128,6 +131,12 @@ issues:
128131
- errcheck
129132
- gosec
130133

134+
# Allow "err" and "ok" vars to shadow existing declarations, otherwise we get too many false positives.
135+
- text: '^shadow: declaration of "(err|ok)" shadows declaration'
136+
linters:
137+
- govet
138+
139+
131140
# Maximum issues count per one linter. Set to 0 to disable. Default is 50.
132141
max-issues-per-linter: 0
133142

cli/command/container/opts_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ func TestParseWithVolumes(t *testing.T) {
198198
t.Fatalf("Error parsing volume flags, %q should not mount-bind anything. Received %v", tryit, hostConfig.Binds)
199199
} else if _, exists := config.Volumes[arr[0]]; !exists {
200200
t.Fatalf("Error parsing volume flags, %s is missing from volumes. Received %v", arr[0], config.Volumes)
201-
} else if _, exists := config.Volumes[arr[1]]; !exists {
201+
} else if _, exists := config.Volumes[arr[1]]; !exists { //nolint:govet // ignore shadow-check
202202
t.Fatalf("Error parsing volume flags, %s is missing from volumes. Received %v", arr[1], config.Volumes)
203203
}
204204

cli/command/manifest/push.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,13 @@ func runPush(dockerCli command.Cli, opts pushOpts) error {
7777
return errors.Errorf("%s not found", targetRef)
7878
}
7979

80-
pushRequest, err := buildPushRequest(manifests, targetRef, opts.insecure)
80+
req, err := buildPushRequest(manifests, targetRef, opts.insecure)
8181
if err != nil {
8282
return err
8383
}
8484

8585
ctx := context.Background()
86-
if err := pushList(ctx, dockerCli, pushRequest); err != nil {
86+
if err := pushList(ctx, dockerCli, req); err != nil {
8787
return err
8888
}
8989
if opts.purge {

cli/command/manifest/push_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,17 @@ func TestManifestPushErrors(t *testing.T) {
4949
}
5050

5151
func TestManifestPush(t *testing.T) {
52-
store := store.NewStore(t.TempDir())
52+
manifestStore := store.NewStore(t.TempDir())
5353

5454
registry := newFakeRegistryClient()
5555

5656
cli := test.NewFakeCli(nil)
57-
cli.SetManifestStore(store)
57+
cli.SetManifestStore(manifestStore)
5858
cli.SetRegistryClient(registry)
5959

6060
namedRef := ref(t, "alpine:3.0")
6161
imageManifest := fullImageManifest(t, namedRef)
62-
err := store.Save(ref(t, "list:v1"), namedRef, imageManifest)
62+
err := manifestStore.Save(ref(t, "list:v1"), namedRef, imageManifest)
6363
assert.NilError(t, err)
6464

6565
cmd := newPushListCommand(cli)

cli/command/service/progress/progress_test.go

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func TestReplicatedProgressUpdaterOneReplica(t *testing.T) {
7070
}
7171

7272
p := &mockProgress{}
73-
updaterTester := updaterTester{
73+
ut := updaterTester{
7474
t: t,
7575
updater: &replicatedProgressUpdater{
7676
progressOut: p,
@@ -82,7 +82,7 @@ func TestReplicatedProgressUpdaterOneReplica(t *testing.T) {
8282

8383
tasks := []swarm.Task{}
8484

85-
updaterTester.testUpdater(tasks, false,
85+
ut.testUpdater(tasks, false,
8686
[]progress.Progress{
8787
{ID: "overall progress", Action: "0 out of 1 tasks"},
8888
{ID: "1/1", Action: " "},
@@ -97,14 +97,14 @@ func TestReplicatedProgressUpdaterOneReplica(t *testing.T) {
9797
DesiredState: swarm.TaskStateShutdown,
9898
Status: swarm.TaskStatus{State: swarm.TaskStateNew},
9999
})
100-
updaterTester.testUpdater(tasks, false,
100+
ut.testUpdater(tasks, false,
101101
[]progress.Progress{
102102
{ID: "overall progress", Action: "0 out of 1 tasks"},
103103
})
104104

105105
// Task with valid DesiredState and State updates progress bar
106106
tasks[0].DesiredState = swarm.TaskStateRunning
107-
updaterTester.testUpdater(tasks, false,
107+
ut.testUpdater(tasks, false,
108108
[]progress.Progress{
109109
{ID: "1/1", Action: "new ", Current: 1, Total: 9, HideCounts: true},
110110
{ID: "overall progress", Action: "0 out of 1 tasks"},
@@ -113,7 +113,7 @@ func TestReplicatedProgressUpdaterOneReplica(t *testing.T) {
113113
// If the task exposes an error, we should show that instead of the
114114
// progress bar.
115115
tasks[0].Status.Err = "something is wrong"
116-
updaterTester.testUpdater(tasks, false,
116+
ut.testUpdater(tasks, false,
117117
[]progress.Progress{
118118
{ID: "1/1", Action: "something is wrong"},
119119
{ID: "overall progress", Action: "0 out of 1 tasks"},
@@ -122,7 +122,7 @@ func TestReplicatedProgressUpdaterOneReplica(t *testing.T) {
122122
// When the task reaches running, update should return true
123123
tasks[0].Status.Err = ""
124124
tasks[0].Status.State = swarm.TaskStateRunning
125-
updaterTester.testUpdater(tasks, true,
125+
ut.testUpdater(tasks, true,
126126
[]progress.Progress{
127127
{ID: "1/1", Action: "running ", Current: 9, Total: 9, HideCounts: true},
128128
{ID: "overall progress", Action: "1 out of 1 tasks"},
@@ -131,7 +131,7 @@ func TestReplicatedProgressUpdaterOneReplica(t *testing.T) {
131131
// If the task fails, update should return false again
132132
tasks[0].Status.Err = "task failed"
133133
tasks[0].Status.State = swarm.TaskStateFailed
134-
updaterTester.testUpdater(tasks, false,
134+
ut.testUpdater(tasks, false,
135135
[]progress.Progress{
136136
{ID: "1/1", Action: "task failed"},
137137
{ID: "overall progress", Action: "0 out of 1 tasks"},
@@ -147,7 +147,7 @@ func TestReplicatedProgressUpdaterOneReplica(t *testing.T) {
147147
DesiredState: swarm.TaskStateRunning,
148148
Status: swarm.TaskStatus{State: swarm.TaskStateRunning},
149149
})
150-
updaterTester.testUpdater(tasks, true,
150+
ut.testUpdater(tasks, true,
151151
[]progress.Progress{
152152
{ID: "1/1", Action: "running ", Current: 9, Total: 9, HideCounts: true},
153153
{ID: "overall progress", Action: "1 out of 1 tasks"},
@@ -162,7 +162,7 @@ func TestReplicatedProgressUpdaterOneReplica(t *testing.T) {
162162
DesiredState: swarm.TaskStateRunning,
163163
Status: swarm.TaskStatus{State: swarm.TaskStatePreparing},
164164
})
165-
updaterTester.testUpdater(tasks, false,
165+
ut.testUpdater(tasks, false,
166166
[]progress.Progress{
167167
{ID: "1/1", Action: "preparing", Current: 6, Total: 9, HideCounts: true},
168168
{ID: "overall progress", Action: "0 out of 1 tasks"},
@@ -183,7 +183,7 @@ func TestReplicatedProgressUpdaterManyReplicas(t *testing.T) {
183183
}
184184

185185
p := &mockProgress{}
186-
updaterTester := updaterTester{
186+
ut := updaterTester{
187187
t: t,
188188
updater: &replicatedProgressUpdater{
189189
progressOut: p,
@@ -196,7 +196,7 @@ func TestReplicatedProgressUpdaterManyReplicas(t *testing.T) {
196196
tasks := []swarm.Task{}
197197

198198
// No per-task progress bars because there are too many replicas
199-
updaterTester.testUpdater(tasks, false,
199+
ut.testUpdater(tasks, false,
200200
[]progress.Progress{
201201
{ID: "overall progress", Action: fmt.Sprintf("0 out of %d tasks", replicas)},
202202
{ID: "overall progress", Action: fmt.Sprintf("0 out of %d tasks", replicas)},
@@ -215,13 +215,13 @@ func TestReplicatedProgressUpdaterManyReplicas(t *testing.T) {
215215
if i%2 == 1 {
216216
tasks[i].NodeID = "b"
217217
}
218-
updaterTester.testUpdater(tasks, false,
218+
ut.testUpdater(tasks, false,
219219
[]progress.Progress{
220220
{ID: "overall progress", Action: fmt.Sprintf("%d out of %d tasks", i, replicas)},
221221
})
222222

223223
tasks[i].Status.State = swarm.TaskStateRunning
224-
updaterTester.testUpdater(tasks, uint64(i) == replicas-1,
224+
ut.testUpdater(tasks, uint64(i) == replicas-1,
225225
[]progress.Progress{
226226
{ID: "overall progress", Action: fmt.Sprintf("%d out of %d tasks", i+1, replicas)},
227227
})
@@ -238,7 +238,7 @@ func TestGlobalProgressUpdaterOneNode(t *testing.T) {
238238
}
239239

240240
p := &mockProgress{}
241-
updaterTester := updaterTester{
241+
ut := updaterTester{
242242
t: t,
243243
updater: &globalProgressUpdater{
244244
progressOut: p,
@@ -250,7 +250,7 @@ func TestGlobalProgressUpdaterOneNode(t *testing.T) {
250250

251251
tasks := []swarm.Task{}
252252

253-
updaterTester.testUpdater(tasks, false,
253+
ut.testUpdater(tasks, false,
254254
[]progress.Progress{
255255
{ID: "overall progress", Action: "waiting for new tasks"},
256256
})
@@ -263,15 +263,15 @@ func TestGlobalProgressUpdaterOneNode(t *testing.T) {
263263
DesiredState: swarm.TaskStateShutdown,
264264
Status: swarm.TaskStatus{State: swarm.TaskStateNew},
265265
})
266-
updaterTester.testUpdater(tasks, false,
266+
ut.testUpdater(tasks, false,
267267
[]progress.Progress{
268268
{ID: "overall progress", Action: "0 out of 1 tasks"},
269269
{ID: "overall progress", Action: "0 out of 1 tasks"},
270270
})
271271

272272
// Task with valid DesiredState and State updates progress bar
273273
tasks[0].DesiredState = swarm.TaskStateRunning
274-
updaterTester.testUpdater(tasks, false,
274+
ut.testUpdater(tasks, false,
275275
[]progress.Progress{
276276
{ID: "a", Action: "new ", Current: 1, Total: 9, HideCounts: true},
277277
{ID: "overall progress", Action: "0 out of 1 tasks"},
@@ -280,7 +280,7 @@ func TestGlobalProgressUpdaterOneNode(t *testing.T) {
280280
// If the task exposes an error, we should show that instead of the
281281
// progress bar.
282282
tasks[0].Status.Err = "something is wrong"
283-
updaterTester.testUpdater(tasks, false,
283+
ut.testUpdater(tasks, false,
284284
[]progress.Progress{
285285
{ID: "a", Action: "something is wrong"},
286286
{ID: "overall progress", Action: "0 out of 1 tasks"},
@@ -289,7 +289,7 @@ func TestGlobalProgressUpdaterOneNode(t *testing.T) {
289289
// When the task reaches running, update should return true
290290
tasks[0].Status.Err = ""
291291
tasks[0].Status.State = swarm.TaskStateRunning
292-
updaterTester.testUpdater(tasks, true,
292+
ut.testUpdater(tasks, true,
293293
[]progress.Progress{
294294
{ID: "a", Action: "running ", Current: 9, Total: 9, HideCounts: true},
295295
{ID: "overall progress", Action: "1 out of 1 tasks"},
@@ -298,7 +298,7 @@ func TestGlobalProgressUpdaterOneNode(t *testing.T) {
298298
// If the task fails, update should return false again
299299
tasks[0].Status.Err = "task failed"
300300
tasks[0].Status.State = swarm.TaskStateFailed
301-
updaterTester.testUpdater(tasks, false,
301+
ut.testUpdater(tasks, false,
302302
[]progress.Progress{
303303
{ID: "a", Action: "task failed"},
304304
{ID: "overall progress", Action: "0 out of 1 tasks"},
@@ -314,7 +314,7 @@ func TestGlobalProgressUpdaterOneNode(t *testing.T) {
314314
DesiredState: swarm.TaskStateRunning,
315315
Status: swarm.TaskStatus{State: swarm.TaskStateRunning},
316316
})
317-
updaterTester.testUpdater(tasks, true,
317+
ut.testUpdater(tasks, true,
318318
[]progress.Progress{
319319
{ID: "a", Action: "running ", Current: 9, Total: 9, HideCounts: true},
320320
{ID: "overall progress", Action: "1 out of 1 tasks"},
@@ -329,7 +329,7 @@ func TestGlobalProgressUpdaterOneNode(t *testing.T) {
329329
DesiredState: swarm.TaskStateRunning,
330330
Status: swarm.TaskStatus{State: swarm.TaskStatePreparing},
331331
})
332-
updaterTester.testUpdater(tasks, false,
332+
ut.testUpdater(tasks, false,
333333
[]progress.Progress{
334334
{ID: "a", Action: "preparing", Current: 6, Total: 9, HideCounts: true},
335335
{ID: "overall progress", Action: "0 out of 1 tasks"},
@@ -348,7 +348,7 @@ func TestGlobalProgressUpdaterManyNodes(t *testing.T) {
348348
}
349349

350350
p := &mockProgress{}
351-
updaterTester := updaterTester{
351+
ut := updaterTester{
352352
t: t,
353353
updater: &globalProgressUpdater{
354354
progressOut: p,
@@ -359,12 +359,12 @@ func TestGlobalProgressUpdaterManyNodes(t *testing.T) {
359359
}
360360

361361
for i := 0; i != nodes; i++ {
362-
updaterTester.activeNodes[strconv.Itoa(i)] = struct{}{}
362+
ut.activeNodes[strconv.Itoa(i)] = struct{}{}
363363
}
364364

365365
tasks := []swarm.Task{}
366366

367-
updaterTester.testUpdater(tasks, false,
367+
ut.testUpdater(tasks, false,
368368
[]progress.Progress{
369369
{ID: "overall progress", Action: "waiting for new tasks"},
370370
})
@@ -379,15 +379,15 @@ func TestGlobalProgressUpdaterManyNodes(t *testing.T) {
379379
})
380380
}
381381

382-
updaterTester.testUpdater(tasks, false,
382+
ut.testUpdater(tasks, false,
383383
[]progress.Progress{
384384
{ID: "overall progress", Action: fmt.Sprintf("0 out of %d tasks", nodes)},
385385
{ID: "overall progress", Action: fmt.Sprintf("0 out of %d tasks", nodes)},
386386
})
387387

388388
for i := 0; i != nodes; i++ {
389389
tasks[i].Status.State = swarm.TaskStateRunning
390-
updaterTester.testUpdater(tasks, i == nodes-1,
390+
ut.testUpdater(tasks, i == nodes-1,
391391
[]progress.Progress{
392392
{ID: "overall progress", Action: fmt.Sprintf("%d out of %d tasks", i+1, nodes)},
393393
})

cli/command/system/info.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ type clientInfo struct {
3535
Warnings []string
3636
}
3737

38-
type info struct {
38+
type dockerInfo struct {
3939
// This field should/could be ServerInfo but is anonymous to
4040
// preserve backwards compatibility in the JSON rendering
4141
// which has ServerInfo immediately within the top-level
@@ -48,7 +48,7 @@ type info struct {
4848
ClientErrors []string `json:",omitempty"`
4949
}
5050

51-
func (i *info) clientPlatform() string {
51+
func (i *dockerInfo) clientPlatform() string {
5252
if i.ClientInfo != nil && i.ClientInfo.Platform != nil {
5353
return i.ClientInfo.Platform.Name
5454
}
@@ -78,7 +78,7 @@ func NewInfoCommand(dockerCli command.Cli) *cobra.Command {
7878
}
7979

8080
func runInfo(cmd *cobra.Command, dockerCli command.Cli, opts *infoOptions) error {
81-
info := info{
81+
info := dockerInfo{
8282
ClientInfo: &clientInfo{
8383
// Don't pass a dockerCLI to newClientVersion(), because we currently
8484
// don't include negotiated API version, and want to avoid making an
@@ -129,7 +129,7 @@ var placeHolders = regexp.MustCompile(`\.[a-zA-Z]`)
129129
// If only client-side information is used in the template, we can skip
130130
// connecting to the daemon. This allows (e.g.) to only get cli-plugin
131131
// information, without also making a (potentially expensive) API call.
132-
func needsServerInfo(template string, info info) bool {
132+
func needsServerInfo(template string, info dockerInfo) bool {
133133
if len(template) == 0 || placeHolders.FindString(template) == "" {
134134
// The template is empty, or does not contain formatting fields
135135
// (e.g. `table` or `raw` or `{{ json .}}`). Assume we need server-side
@@ -160,7 +160,7 @@ func needsServerInfo(template string, info info) bool {
160160
return err != nil
161161
}
162162

163-
func prettyPrintInfo(streams command.Streams, info info) error {
163+
func prettyPrintInfo(streams command.Streams, info dockerInfo) error {
164164
// Only append the platform info if it's not empty, to prevent printing a trailing space.
165165
if p := info.clientPlatform(); p != "" {
166166
fprintln(streams.Out(), "Client:", p)
@@ -215,7 +215,7 @@ func prettyPrintClientInfo(streams command.Streams, info clientInfo) {
215215
}
216216

217217
//nolint:gocyclo
218-
func prettyPrintServerInfo(streams command.Streams, info *info) []error {
218+
func prettyPrintServerInfo(streams command.Streams, info *dockerInfo) []error {
219219
var errs []error
220220
output := streams.Out()
221221

@@ -452,7 +452,7 @@ func printSwarmInfo(output io.Writer, info system.Info) {
452452
}
453453
}
454454

455-
func printServerWarnings(stdErr io.Writer, info *info) {
455+
func printServerWarnings(stdErr io.Writer, info *dockerInfo) {
456456
if versions.LessThan(info.ClientInfo.APIVersion, "1.42") {
457457
printSecurityOptionsWarnings(stdErr, *info.Info)
458458
}
@@ -530,7 +530,7 @@ func printServerWarningsLegacy(stdErr io.Writer, info system.Info) {
530530
}
531531
}
532532

533-
func formatInfo(output io.Writer, info info, format string) error {
533+
func formatInfo(output io.Writer, info dockerInfo, format string) error {
534534
if format == formatter.JSONFormatKey {
535535
format = formatter.JSONFormat
536536
}

0 commit comments

Comments
 (0)