From cc1d7b7ac97cbc1d82a8ed3c5a4a311483dd0c61 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Mon, 26 Aug 2024 13:44:42 +0200 Subject: [PATCH 1/4] cli/command/system: remove redundant nil-check (gosimple) cli/command/system/info.go:375:5: S1009: should omit nil check; len() for []github.com/docker/docker/api/types/system.NetworkAddressPool is defined as zero (gosimple) if info.DefaultAddressPools != nil && len(info.DefaultAddressPools) > 0 { ^ Signed-off-by: Sebastiaan van Stijn --- cli/command/system/info.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/command/system/info.go b/cli/command/system/info.go index aaf597cf89..742e8df50b 100644 --- a/cli/command/system/info.go +++ b/cli/command/system/info.go @@ -372,7 +372,7 @@ func prettyPrintServerInfo(streams command.Streams, info *dockerInfo) []error { fprintln(output, " Product License:", info.ProductLicense) } - if info.DefaultAddressPools != nil && len(info.DefaultAddressPools) > 0 { + if len(info.DefaultAddressPools) > 0 { fprintln(output, " Default Address Pools:") for _, pool := range info.DefaultAddressPools { fprintf(output, " Base: %s, Size: %d\n", pool.Base, pool.Size) From f101f07a7b3c163d78dab95f2340be60cfcd5076 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Mon, 26 Aug 2024 13:52:49 +0200 Subject: [PATCH 2/4] cli/command: fix n-constant format string in call (govet) cli/command/utils.go:225:29: printf: non-constant format string in call to github.com/pkg/errors.Wrapf (govet) return errors.Wrapf(err, fmt.Sprintf("invalid output path: %q must be a directory or a regular file", path)) ^ cli/command/manifest/cmd.go:21:33: printf: non-constant format string in call to fmt.Fprintf (govet) fmt.Fprintf(dockerCli.Err(), "\n"+cmd.UsageString()) ^ cli/command/service/remove.go:45:24: printf: non-constant format string in call to github.com/pkg/errors.Errorf (govet) return errors.Errorf(strings.Join(errs, "\n")) ^ cli/command/service/scale.go:93:23: printf: non-constant format string in call to github.com/pkg/errors.Errorf (govet) return errors.Errorf(strings.Join(errs, "\n")) ^ cli/command/stack/swarm/remove.go:74:24: printf: non-constant format string in call to github.com/pkg/errors.Errorf (govet) return errors.Errorf(strings.Join(errs, "\n")) ^ Signed-off-by: Sebastiaan van Stijn --- cli/command/manifest/cmd.go | 2 +- cli/command/service/remove.go | 4 ++-- cli/command/service/scale.go | 2 +- cli/command/stack/swarm/remove.go | 4 ++-- cli/command/utils.go | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/cli/command/manifest/cmd.go b/cli/command/manifest/cmd.go index a914ef6dbb..939f02b7bc 100644 --- a/cli/command/manifest/cmd.go +++ b/cli/command/manifest/cmd.go @@ -18,7 +18,7 @@ func NewManifestCommand(dockerCli command.Cli) *cobra.Command { Long: manifestDescription, Args: cli.NoArgs, Run: func(cmd *cobra.Command, args []string) { - fmt.Fprintf(dockerCli.Err(), "\n"+cmd.UsageString()) + _, _ = fmt.Fprint(dockerCli.Err(), "\n"+cmd.UsageString()) }, Annotations: map[string]string{"experimentalCLI": ""}, } diff --git a/cli/command/service/remove.go b/cli/command/service/remove.go index c6e938e13b..efbd5f9ad0 100644 --- a/cli/command/service/remove.go +++ b/cli/command/service/remove.go @@ -39,10 +39,10 @@ func runRemove(ctx context.Context, dockerCli command.Cli, sids []string) error errs = append(errs, err.Error()) continue } - fmt.Fprintf(dockerCli.Out(), "%s\n", sid) + _, _ = fmt.Fprintf(dockerCli.Out(), "%s\n", sid) } if len(errs) > 0 { - return errors.Errorf(strings.Join(errs, "\n")) + return errors.New(strings.Join(errs, "\n")) } return nil } diff --git a/cli/command/service/scale.go b/cli/command/service/scale.go index fd86304989..688a3ff2d0 100644 --- a/cli/command/service/scale.go +++ b/cli/command/service/scale.go @@ -90,7 +90,7 @@ func runScale(ctx context.Context, dockerCli command.Cli, options *scaleOptions, if len(errs) == 0 { return nil } - return errors.Errorf(strings.Join(errs, "\n")) + return errors.New(strings.Join(errs, "\n")) } func runServiceScale(ctx context.Context, dockerCli command.Cli, serviceID string, scale uint64) error { diff --git a/cli/command/stack/swarm/remove.go b/cli/command/stack/swarm/remove.go index cde317fe0a..5641ea24bd 100644 --- a/cli/command/stack/swarm/remove.go +++ b/cli/command/stack/swarm/remove.go @@ -48,7 +48,7 @@ func RunRemove(ctx context.Context, dockerCli command.Cli, opts options.Remove) } if len(services)+len(networks)+len(secrets)+len(configs) == 0 { - fmt.Fprintf(dockerCli.Err(), "Nothing found in stack: %s\n", namespace) + _, _ = fmt.Fprintf(dockerCli.Err(), "Nothing found in stack: %s\n", namespace) continue } @@ -71,7 +71,7 @@ func RunRemove(ctx context.Context, dockerCli command.Cli, opts options.Remove) } if len(errs) > 0 { - return errors.Errorf(strings.Join(errs, "\n")) + return errors.New(strings.Join(errs, "\n")) } return nil } diff --git a/cli/command/utils.go b/cli/command/utils.go index b206db8edd..1cf4d199de 100644 --- a/cli/command/utils.go +++ b/cli/command/utils.go @@ -222,7 +222,7 @@ func ValidateOutputPath(path string) error { } if err := ValidateOutputPathFileMode(fileInfo.Mode()); err != nil { - return errors.Wrapf(err, fmt.Sprintf("invalid output path: %q must be a directory or a regular file", path)) + return errors.Wrapf(err, "invalid output path: %q must be a directory or a regular file", path) } } return nil From 9c87891278389dec9af8faac751a35bf4931f7c6 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Mon, 26 Aug 2024 13:54:05 +0200 Subject: [PATCH 3/4] e2e/global: fix n-constant format string in call (govet) e2e/global/cli_test.go:217:28: printf: non-constant format string in call to gotest.tools/v3/poll.Continue (govet) return poll.Continue(err.Error()) ^ Signed-off-by: Sebastiaan van Stijn --- e2e/global/cli_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/e2e/global/cli_test.go b/e2e/global/cli_test.go index 91d507eb70..21b964d40b 100644 --- a/e2e/global/cli_test.go +++ b/e2e/global/cli_test.go @@ -214,7 +214,7 @@ func TestPromptExitCode(t *testing.T) { default: if err := bufioWriter.Flush(); err != nil { - return poll.Continue(err.Error()) + return poll.Continue("%v", err) } if strings.Contains(buf.String(), "[y/N]") { return poll.Success() From c4a55df7c040a4490c10f1aa5f4cfcef7dccfc1d Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Mon, 26 Aug 2024 13:55:28 +0200 Subject: [PATCH 4/4] cli: rename args that collided with builtins (predeclard) cli/required.go:33:22: param min has same name as predeclared identifier (predeclared) func RequiresMinArgs(min int) cobra.PositionalArgs { ^ cli/required.go:50:22: param max has same name as predeclared identifier (predeclared) func RequiresMaxArgs(max int) cobra.PositionalArgs { ^ cli/required.go:67:24: param min has same name as predeclared identifier (predeclared) func RequiresRangeArgs(min int, max int) cobra.PositionalArgs { ^ Signed-off-by: Sebastiaan van Stijn --- cli/required.go | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/cli/required.go b/cli/required.go index 8d01887d0f..6455e8867e 100644 --- a/cli/required.go +++ b/cli/required.go @@ -30,52 +30,52 @@ func NoArgs(cmd *cobra.Command, args []string) error { } // RequiresMinArgs returns an error if there is not at least min args -func RequiresMinArgs(min int) cobra.PositionalArgs { +func RequiresMinArgs(minArgs int) cobra.PositionalArgs { return func(cmd *cobra.Command, args []string) error { - if len(args) >= min { + if len(args) >= minArgs { return nil } return errors.Errorf( "%[1]s: '%[2]s' requires at least %[3]d %[4]s\n\nUsage: %[5]s\n\nSee '%[2]s --help' for more information", binName(cmd), cmd.CommandPath(), - min, - pluralize("argument", min), + minArgs, + pluralize("argument", minArgs), cmd.UseLine(), ) } } // RequiresMaxArgs returns an error if there is not at most max args -func RequiresMaxArgs(max int) cobra.PositionalArgs { +func RequiresMaxArgs(maxArgs int) cobra.PositionalArgs { return func(cmd *cobra.Command, args []string) error { - if len(args) <= max { + if len(args) <= maxArgs { return nil } return errors.Errorf( "%[1]s: '%[2]s' requires at most %[3]d %[4]s\n\nUsage: %[5]s\n\nSRun '%[2]s --help' for more information", binName(cmd), cmd.CommandPath(), - max, - pluralize("argument", max), + maxArgs, + pluralize("argument", maxArgs), cmd.UseLine(), ) } } // RequiresRangeArgs returns an error if there is not at least min args and at most max args -func RequiresRangeArgs(min int, max int) cobra.PositionalArgs { +func RequiresRangeArgs(minArgs int, maxArgs int) cobra.PositionalArgs { return func(cmd *cobra.Command, args []string) error { - if len(args) >= min && len(args) <= max { + if len(args) >= minArgs && len(args) <= maxArgs { return nil } return errors.Errorf( "%[1]s: '%[2]s' requires at least %[3]d and at most %[4]d %[5]s\n\nUsage: %[6]s\n\nRun '%[2]s --help' for more information", binName(cmd), cmd.CommandPath(), - min, - max, - pluralize("argument", max), + minArgs, + maxArgs, + pluralize("argument", maxArgs), cmd.UseLine(), ) }