Skip to content

Commit 8e9aec6

Browse files
committed
golangci-lint: revive: enable import-shadowing
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
1 parent 391668f commit 8e9aec6

53 files changed

Lines changed: 482 additions & 479 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.golangci.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,13 @@ linters-settings:
5555
command: nakedret
5656
pattern: ^(?P<path>.*?\\.go):(?P<line>\\d+)\\s*(?P<message>.*)$
5757

58+
revive:
59+
rules:
60+
# https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#import-shadowing
61+
- name: import-shadowing
62+
severity: warning
63+
disabled: false
64+
5865
issues:
5966
# The default exclusion rules are a bit too permissive, so copying the relevant ones below
6067
exclude-use-default: false

cli/command/cli.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ func (cli *DockerCli) CurrentContext() string {
394394
// occur when trying to use it.
395395
//
396396
// Refer to [DockerCli.CurrentContext] above for further details.
397-
func resolveContextName(opts *cliflags.ClientOptions, config *configfile.ConfigFile) string {
397+
func resolveContextName(opts *cliflags.ClientOptions, cfg *configfile.ConfigFile) string {
398398
if opts != nil && opts.Context != "" {
399399
return opts.Context
400400
}
@@ -407,9 +407,9 @@ func resolveContextName(opts *cliflags.ClientOptions, config *configfile.ConfigF
407407
if ctxName := os.Getenv(EnvOverrideContext); ctxName != "" {
408408
return ctxName
409409
}
410-
if config != nil && config.CurrentContext != "" {
410+
if cfg != nil && cfg.CurrentContext != "" {
411411
// We don't validate if this context exists: errors may occur when trying to use it.
412-
return config.CurrentContext
412+
return cfg.CurrentContext
413413
}
414414
return DefaultContextName
415415
}

cli/command/container/attach.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ type AttachOptions struct {
2424
DetachKeys string
2525
}
2626

27-
func inspectContainerAndCheckState(ctx context.Context, cli client.APIClient, args string) (*types.ContainerJSON, error) {
28-
c, err := cli.ContainerInspect(ctx, args)
27+
func inspectContainerAndCheckState(ctx context.Context, apiClient client.APIClient, args string) (*types.ContainerJSON, error) {
28+
c, err := apiClient.ContainerInspect(ctx, args)
2929
if err != nil {
3030
return nil, err
3131
}
@@ -45,21 +45,21 @@ func inspectContainerAndCheckState(ctx context.Context, cli client.APIClient, ar
4545
// NewAttachCommand creates a new cobra.Command for `docker attach`
4646
func NewAttachCommand(dockerCli command.Cli) *cobra.Command {
4747
var opts AttachOptions
48-
var container string
48+
var ctr string
4949

5050
cmd := &cobra.Command{
5151
Use: "attach [OPTIONS] CONTAINER",
5252
Short: "Attach local standard input, output, and error streams to a running container",
5353
Args: cli.ExactArgs(1),
5454
RunE: func(cmd *cobra.Command, args []string) error {
55-
container = args[0]
56-
return RunAttach(context.Background(), dockerCli, container, &opts)
55+
ctr = args[0]
56+
return RunAttach(context.Background(), dockerCli, ctr, &opts)
5757
},
5858
Annotations: map[string]string{
5959
"aliases": "docker container attach, docker attach",
6060
},
61-
ValidArgsFunction: completion.ContainerNames(dockerCli, false, func(container types.Container) bool {
62-
return container.State != "paused"
61+
ValidArgsFunction: completion.ContainerNames(dockerCli, false, func(ctr types.Container) bool {
62+
return ctr.State != "paused"
6363
}),
6464
}
6565

@@ -71,8 +71,8 @@ func NewAttachCommand(dockerCli command.Cli) *cobra.Command {
7171
}
7272

7373
// RunAttach executes an `attach` command
74-
func RunAttach(ctx context.Context, dockerCli command.Cli, target string, opts *AttachOptions) error {
75-
apiClient := dockerCli.Client()
74+
func RunAttach(ctx context.Context, dockerCLI command.Cli, target string, opts *AttachOptions) error {
75+
apiClient := dockerCLI.Client()
7676

7777
// request channel to wait for client
7878
resultC, errC := apiClient.ContainerWait(ctx, target, "")
@@ -82,11 +82,11 @@ func RunAttach(ctx context.Context, dockerCli command.Cli, target string, opts *
8282
return err
8383
}
8484

85-
if err := dockerCli.In().CheckTty(!opts.NoStdin, c.Config.Tty); err != nil {
85+
if err := dockerCLI.In().CheckTty(!opts.NoStdin, c.Config.Tty); err != nil {
8686
return err
8787
}
8888

89-
detachKeys := dockerCli.ConfigFile().DetachKeys
89+
detachKeys := dockerCLI.ConfigFile().DetachKeys
9090
if opts.DetachKeys != "" {
9191
detachKeys = opts.DetachKeys
9292
}
@@ -101,7 +101,7 @@ func RunAttach(ctx context.Context, dockerCli command.Cli, target string, opts *
101101

102102
var in io.ReadCloser
103103
if options.Stdin {
104-
in = dockerCli.In()
104+
in = dockerCLI.In()
105105
}
106106

107107
if opts.Proxy && !c.Config.Tty {
@@ -129,15 +129,15 @@ func RunAttach(ctx context.Context, dockerCli command.Cli, target string, opts *
129129
return err
130130
}
131131

132-
if c.Config.Tty && dockerCli.Out().IsTerminal() {
133-
resizeTTY(ctx, dockerCli, target)
132+
if c.Config.Tty && dockerCLI.Out().IsTerminal() {
133+
resizeTTY(ctx, dockerCLI, target)
134134
}
135135

136136
streamer := hijackedIOStreamer{
137-
streams: dockerCli,
137+
streams: dockerCLI,
138138
inputStream: in,
139-
outputStream: dockerCli.Out(),
140-
errorStream: dockerCli.Err(),
139+
outputStream: dockerCLI.Out(),
140+
errorStream: dockerCLI.Err(),
141141
resp: resp,
142142
tty: c.Config.Tty,
143143
detachKeys: options.DetachKeys,

cli/command/container/client_test.go

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,24 @@ type fakeClient struct {
1616
client.Client
1717
inspectFunc func(string) (types.ContainerJSON, error)
1818
execInspectFunc func(execID string) (types.ContainerExecInspect, error)
19-
execCreateFunc func(container string, config types.ExecConfig) (types.IDResponse, error)
19+
execCreateFunc func(containerID string, config types.ExecConfig) (types.IDResponse, error)
2020
createContainerFunc func(config *container.Config,
2121
hostConfig *container.HostConfig,
2222
networkingConfig *network.NetworkingConfig,
2323
platform *specs.Platform,
2424
containerName string) (container.CreateResponse, error)
25-
containerStartFunc func(container string, options container.StartOptions) error
25+
containerStartFunc func(containerID string, options container.StartOptions) error
2626
imageCreateFunc func(parentReference string, options types.ImageCreateOptions) (io.ReadCloser, error)
2727
infoFunc func() (system.Info, error)
28-
containerStatPathFunc func(container, path string) (types.ContainerPathStat, error)
29-
containerCopyFromFunc func(container, srcPath string) (io.ReadCloser, types.ContainerPathStat, error)
28+
containerStatPathFunc func(containerID, path string) (types.ContainerPathStat, error)
29+
containerCopyFromFunc func(containerID, srcPath string) (io.ReadCloser, types.ContainerPathStat, error)
3030
logFunc func(string, container.LogsOptions) (io.ReadCloser, error)
3131
waitFunc func(string) (<-chan container.WaitResponse, <-chan error)
3232
containerListFunc func(container.ListOptions) ([]types.Container, error)
3333
containerExportFunc func(string) (io.ReadCloser, error)
3434
containerExecResizeFunc func(id string, options container.ResizeOptions) error
35-
containerRemoveFunc func(ctx context.Context, container string, options container.RemoveOptions) error
36-
containerKillFunc func(ctx context.Context, container, signal string) error
35+
containerRemoveFunc func(ctx context.Context, containerID string, options container.RemoveOptions) error
36+
containerKillFunc func(ctx context.Context, containerID, signal string) error
3737
Version string
3838
}
3939

@@ -51,9 +51,9 @@ func (f *fakeClient) ContainerInspect(_ context.Context, containerID string) (ty
5151
return types.ContainerJSON{}, nil
5252
}
5353

54-
func (f *fakeClient) ContainerExecCreate(_ context.Context, container string, config types.ExecConfig) (types.IDResponse, error) {
54+
func (f *fakeClient) ContainerExecCreate(_ context.Context, containerID string, config types.ExecConfig) (types.IDResponse, error) {
5555
if f.execCreateFunc != nil {
56-
return f.execCreateFunc(container, config)
56+
return f.execCreateFunc(containerID, config)
5757
}
5858
return types.IDResponse{}, nil
5959
}
@@ -83,9 +83,9 @@ func (f *fakeClient) ContainerCreate(
8383
return container.CreateResponse{}, nil
8484
}
8585

86-
func (f *fakeClient) ContainerRemove(ctx context.Context, container string, options container.RemoveOptions) error {
86+
func (f *fakeClient) ContainerRemove(ctx context.Context, containerID string, options container.RemoveOptions) error {
8787
if f.containerRemoveFunc != nil {
88-
return f.containerRemoveFunc(ctx, container, options)
88+
return f.containerRemoveFunc(ctx, containerID, options)
8989
}
9090
return nil
9191
}
@@ -104,23 +104,23 @@ func (f *fakeClient) Info(_ context.Context) (system.Info, error) {
104104
return system.Info{}, nil
105105
}
106106

107-
func (f *fakeClient) ContainerStatPath(_ context.Context, container, path string) (types.ContainerPathStat, error) {
107+
func (f *fakeClient) ContainerStatPath(_ context.Context, containerID, path string) (types.ContainerPathStat, error) {
108108
if f.containerStatPathFunc != nil {
109-
return f.containerStatPathFunc(container, path)
109+
return f.containerStatPathFunc(containerID, path)
110110
}
111111
return types.ContainerPathStat{}, nil
112112
}
113113

114-
func (f *fakeClient) CopyFromContainer(_ context.Context, container, srcPath string) (io.ReadCloser, types.ContainerPathStat, error) {
114+
func (f *fakeClient) CopyFromContainer(_ context.Context, containerID, srcPath string) (io.ReadCloser, types.ContainerPathStat, error) {
115115
if f.containerCopyFromFunc != nil {
116-
return f.containerCopyFromFunc(container, srcPath)
116+
return f.containerCopyFromFunc(containerID, srcPath)
117117
}
118118
return nil, types.ContainerPathStat{}, nil
119119
}
120120

121-
func (f *fakeClient) ContainerLogs(_ context.Context, container string, options container.LogsOptions) (io.ReadCloser, error) {
121+
func (f *fakeClient) ContainerLogs(_ context.Context, containerID string, options container.LogsOptions) (io.ReadCloser, error) {
122122
if f.logFunc != nil {
123-
return f.logFunc(container, options)
123+
return f.logFunc(containerID, options)
124124
}
125125
return nil, nil
126126
}
@@ -129,23 +129,23 @@ func (f *fakeClient) ClientVersion() string {
129129
return f.Version
130130
}
131131

132-
func (f *fakeClient) ContainerWait(_ context.Context, container string, _ container.WaitCondition) (<-chan container.WaitResponse, <-chan error) {
132+
func (f *fakeClient) ContainerWait(_ context.Context, containerID string, _ container.WaitCondition) (<-chan container.WaitResponse, <-chan error) {
133133
if f.waitFunc != nil {
134-
return f.waitFunc(container)
134+
return f.waitFunc(containerID)
135135
}
136136
return nil, nil
137137
}
138138

139-
func (f *fakeClient) ContainerStart(_ context.Context, container string, options container.StartOptions) error {
139+
func (f *fakeClient) ContainerStart(_ context.Context, containerID string, options container.StartOptions) error {
140140
if f.containerStartFunc != nil {
141-
return f.containerStartFunc(container, options)
141+
return f.containerStartFunc(containerID, options)
142142
}
143143
return nil
144144
}
145145

146-
func (f *fakeClient) ContainerExport(_ context.Context, container string) (io.ReadCloser, error) {
146+
func (f *fakeClient) ContainerExport(_ context.Context, containerID string) (io.ReadCloser, error) {
147147
if f.containerExportFunc != nil {
148-
return f.containerExportFunc(container)
148+
return f.containerExportFunc(containerID)
149149
}
150150
return nil, nil
151151
}
@@ -157,9 +157,9 @@ func (f *fakeClient) ContainerExecResize(_ context.Context, id string, options c
157157
return nil
158158
}
159159

160-
func (f *fakeClient) ContainerKill(ctx context.Context, container, signal string) error {
160+
func (f *fakeClient) ContainerKill(ctx context.Context, containerID, signal string) error {
161161
if f.containerKillFunc != nil {
162-
return f.containerKillFunc(ctx, container, signal)
162+
return f.containerKillFunc(ctx, containerID, signal)
163163
}
164164
return nil
165165
}

cli/command/container/create.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -113,23 +113,23 @@ func runCreate(dockerCli command.Cli, flags *pflag.FlagSet, options *createOptio
113113
}
114114

115115
// FIXME(thaJeztah): this is the only code-path that uses APIClient.ImageCreate. Rewrite this to use the regular "pull" code (or vice-versa).
116-
func pullImage(ctx context.Context, dockerCli command.Cli, image string, opts *createOptions) error {
117-
encodedAuth, err := command.RetrieveAuthTokenFromImage(dockerCli.ConfigFile(), image)
116+
func pullImage(ctx context.Context, dockerCli command.Cli, img string, options *createOptions) error {
117+
encodedAuth, err := command.RetrieveAuthTokenFromImage(dockerCli.ConfigFile(), img)
118118
if err != nil {
119119
return err
120120
}
121121

122-
responseBody, err := dockerCli.Client().ImageCreate(ctx, image, types.ImageCreateOptions{
122+
responseBody, err := dockerCli.Client().ImageCreate(ctx, img, types.ImageCreateOptions{
123123
RegistryAuth: encodedAuth,
124-
Platform: opts.platform,
124+
Platform: options.platform,
125125
})
126126
if err != nil {
127127
return err
128128
}
129129
defer responseBody.Close()
130130

131131
out := dockerCli.Err()
132-
if opts.quiet {
132+
if options.quiet {
133133
out = io.Discard
134134
}
135135
return jsonmessage.DisplayJSONMessagesToStream(responseBody, streams.NewOut(out), nil)
@@ -185,7 +185,7 @@ func newCIDFile(path string) (*cidFile, error) {
185185
}
186186

187187
//nolint:gocyclo
188-
func createContainer(ctx context.Context, dockerCli command.Cli, containerCfg *containerConfig, opts *createOptions) (containerID string, err error) {
188+
func createContainer(ctx context.Context, dockerCli command.Cli, containerCfg *containerConfig, options *createOptions) (containerID string, err error) {
189189
config := containerCfg.Config
190190
hostConfig := containerCfg.HostConfig
191191
networkingConfig := containerCfg.NetworkingConfig
@@ -211,7 +211,7 @@ func createContainer(ctx context.Context, dockerCli command.Cli, containerCfg *c
211211
if named, ok := ref.(reference.Named); ok {
212212
namedRef = reference.TagNameOnly(named)
213213

214-
if taggedRef, ok := namedRef.(reference.NamedTagged); ok && !opts.untrusted {
214+
if taggedRef, ok := namedRef.(reference.NamedTagged); ok && !options.untrusted {
215215
var err error
216216
trustedRef, err = image.TrustedReference(ctx, dockerCli, taggedRef)
217217
if err != nil {
@@ -222,7 +222,7 @@ func createContainer(ctx context.Context, dockerCli command.Cli, containerCfg *c
222222
}
223223

224224
pullAndTagImage := func() error {
225-
if err := pullImage(ctx, dockerCli, config.Image, opts); err != nil {
225+
if err := pullImage(ctx, dockerCli, config.Image, options); err != nil {
226226
return err
227227
}
228228
if taggedRef, ok := namedRef.(reference.NamedTagged); ok && trustedRef != nil {
@@ -236,27 +236,27 @@ func createContainer(ctx context.Context, dockerCli command.Cli, containerCfg *c
236236
// create. It will produce an error if you try to set a platform on older API
237237
// versions, so check the API version here to maintain backwards
238238
// compatibility for CLI users.
239-
if opts.platform != "" && versions.GreaterThanOrEqualTo(dockerCli.Client().ClientVersion(), "1.41") {
240-
p, err := platforms.Parse(opts.platform)
239+
if options.platform != "" && versions.GreaterThanOrEqualTo(dockerCli.Client().ClientVersion(), "1.41") {
240+
p, err := platforms.Parse(options.platform)
241241
if err != nil {
242242
return "", errors.Wrap(err, "error parsing specified platform")
243243
}
244244
platform = &p
245245
}
246246

247-
if opts.pull == PullImageAlways {
247+
if options.pull == PullImageAlways {
248248
if err := pullAndTagImage(); err != nil {
249249
return "", err
250250
}
251251
}
252252

253253
hostConfig.ConsoleSize[0], hostConfig.ConsoleSize[1] = dockerCli.Out().GetTtySize()
254254

255-
response, err := dockerCli.Client().ContainerCreate(ctx, config, hostConfig, networkingConfig, platform, opts.name)
255+
response, err := dockerCli.Client().ContainerCreate(ctx, config, hostConfig, networkingConfig, platform, options.name)
256256
if err != nil {
257257
// Pull image if it does not exist locally and we have the PullImageMissing option. Default behavior.
258-
if errdefs.IsNotFound(err) && namedRef != nil && opts.pull == PullImageMissing {
259-
if !opts.quiet {
258+
if errdefs.IsNotFound(err) && namedRef != nil && options.pull == PullImageMissing {
259+
if !options.quiet {
260260
// we don't want to write to stdout anything apart from container.ID
261261
fmt.Fprintf(dockerCli.Err(), "Unable to find image '%s' locally\n", reference.FamiliarString(namedRef))
262262
}
@@ -266,7 +266,7 @@ func createContainer(ctx context.Context, dockerCli command.Cli, containerCfg *c
266266
}
267267

268268
var retryErr error
269-
response, retryErr = dockerCli.Client().ContainerCreate(ctx, config, hostConfig, networkingConfig, platform, opts.name)
269+
response, retryErr = dockerCli.Client().ContainerCreate(ctx, config, hostConfig, networkingConfig, platform, options.name)
270270
if retryErr != nil {
271271
return "", retryErr
272272
}

0 commit comments

Comments
 (0)