Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[27.x backport] Fix linting issues in preparation of Go and GolangCI-lint update #5372

Merged
merged 4 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cli/command/manifest/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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": ""},
}
Expand Down
4 changes: 2 additions & 2 deletions cli/command/service/remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
2 changes: 1 addition & 1 deletion cli/command/service/scale.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions cli/command/stack/swarm/remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion cli/command/system/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion cli/command/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 13 additions & 13 deletions cli/required.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,16 @@ 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(
"%q requires at least %d %s.\nSee '%s --help'.\n\nUsage: %s\n\n%s",
cmd.CommandPath(),
min,
pluralize("argument", min),
minArgs,
pluralize("argument", minArgs),
cmd.CommandPath(),
cmd.UseLine(),
cmd.Short,
Expand All @@ -45,16 +45,16 @@ func RequiresMinArgs(min int) cobra.PositionalArgs {
}

// 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(
"%q requires at most %d %s.\nSee '%s --help'.\n\nUsage: %s\n\n%s",
cmd.CommandPath(),
max,
pluralize("argument", max),
maxArgs,
pluralize("argument", maxArgs),
cmd.CommandPath(),
cmd.UseLine(),
cmd.Short,
Expand All @@ -63,17 +63,17 @@ func RequiresMaxArgs(max int) cobra.PositionalArgs {
}

// 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(
"%q requires at least %d and at most %d %s.\nSee '%s --help'.\n\nUsage: %s\n\n%s",
cmd.CommandPath(),
min,
max,
pluralize("argument", max),
minArgs,
maxArgs,
pluralize("argument", maxArgs),
cmd.CommandPath(),
cmd.UseLine(),
cmd.Short,
Expand Down
2 changes: 1 addition & 1 deletion e2e/global/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Loading