Skip to content

Commit 9fc247e

Browse files
authored
Merge pull request #6626 from thaJeztah/fix_perfsprint
fix perfsprint (concat-loop) linting
2 parents 924ed09 + f8d0365 commit 9fc247e

File tree

5 files changed

+30
-21
lines changed

5 files changed

+30
-21
lines changed

cli/cobra.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,11 +250,12 @@ func commandAliases(cmd *cobra.Command) string {
250250
if cmd.HasParent() {
251251
parentPath = cmd.Parent().CommandPath() + " "
252252
}
253-
aliases := cmd.CommandPath()
253+
var aliases strings.Builder
254+
aliases.WriteString(cmd.CommandPath())
254255
for _, alias := range cmd.Aliases {
255-
aliases += ", " + parentPath + alias
256+
aliases.WriteString(", " + parentPath + alias)
256257
}
257-
return aliases
258+
return aliases.String()
258259
}
259260

260261
func topCommands(cmd *cobra.Command) []*cobra.Command {

cli/command/container/prune.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"errors"
66
"fmt"
7+
"strings"
78

89
"github.com/docker/cli/cli"
910
"github.com/docker/cli/cli/command"
@@ -61,7 +62,7 @@ func newPruneCommand(dockerCLI command.Cli) *cobra.Command {
6162
const warning = `WARNING! This will remove all stopped containers.
6263
Are you sure you want to continue?`
6364

64-
func runPrune(ctx context.Context, dockerCli command.Cli, options pruneOptions) (spaceReclaimed uint64, output string, err error) {
65+
func runPrune(ctx context.Context, dockerCli command.Cli, options pruneOptions) (spaceReclaimed uint64, output string, _ error) {
6566
pruneFilters := command.PruneFilters(dockerCli, options.filter.Value())
6667

6768
if !options.force {
@@ -81,15 +82,16 @@ func runPrune(ctx context.Context, dockerCli command.Cli, options pruneOptions)
8182
return 0, "", err
8283
}
8384

85+
var out strings.Builder
8486
if len(res.Report.ContainersDeleted) > 0 {
85-
output = "Deleted Containers:\n"
87+
out.WriteString("Deleted Containers:\n")
8688
for _, id := range res.Report.ContainersDeleted {
87-
output += id + "\n"
89+
out.WriteString(id + "\n")
8890
}
8991
spaceReclaimed = res.Report.SpaceReclaimed
9092
}
9193

92-
return spaceReclaimed, output, nil
94+
return spaceReclaimed, out.String(), nil
9395
}
9496

9597
type cancelledErr struct{ error }

cli/command/image/tree.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -297,15 +297,15 @@ func printImageTree(outs command.Streams, view treeView) {
297297
}(),
298298
Color: &tui.ColorNone,
299299
DetailsValue: func(d *imageDetails) string {
300-
var out string
300+
var b strings.Builder
301301
for _, chip := range possibleChips {
302302
if chip.check(d) {
303-
out += chip.String(isTerm)
303+
b.WriteString(chip.String(isTerm))
304304
} else {
305-
out += chipPlaceholder.String(isTerm)
305+
b.WriteString(chipPlaceholder.String(isTerm))
306306
}
307307
}
308-
return out
308+
return b.String()
309309
},
310310
},
311311
}
@@ -368,12 +368,14 @@ func adjustColumns(width uint, columns []imgColumn, images []topImage) []imgColu
368368
func generateLegend(out tui.Output, width uint) string {
369369
var legend string
370370
legend += out.Sprint(tui.InfoHeader)
371+
var legendSb371 strings.Builder
371372
for idx, chip := range allChips {
372-
legend += " " + out.Sprint(chip) + " " + chip.desc
373+
legendSb371.WriteString(" " + out.Sprint(chip) + " " + chip.desc)
373374
if idx < len(allChips)-1 {
374-
legend += " |"
375+
legendSb371.WriteString(" |")
375376
}
376377
}
378+
legend += legendSb371.String()
377379

378380
r := int(width) - tui.Width(legend)
379381
if r < 0 {

cli/command/network/prune.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"errors"
66
"fmt"
7+
"strings"
78

89
"github.com/docker/cli/cli"
910
"github.com/docker/cli/cli/command"
@@ -58,7 +59,7 @@ func newPruneCommand(dockerCLI command.Cli) *cobra.Command {
5859
const warning = `WARNING! This will remove all custom networks not used by at least one container.
5960
Are you sure you want to continue?`
6061

61-
func runPrune(ctx context.Context, dockerCli command.Cli, options pruneOptions) (output string, err error) {
62+
func runPrune(ctx context.Context, dockerCli command.Cli, options pruneOptions) (output string, _ error) {
6263
pruneFilters := command.PruneFilters(dockerCli, options.filter.Value())
6364

6465
if !options.force {
@@ -78,14 +79,15 @@ func runPrune(ctx context.Context, dockerCli command.Cli, options pruneOptions)
7879
return "", err
7980
}
8081

82+
var out strings.Builder
8183
if len(res.Report.NetworksDeleted) > 0 {
82-
output = "Deleted Networks:\n"
84+
out.WriteString("Deleted Networks:\n")
8385
for _, id := range res.Report.NetworksDeleted {
84-
output += id + "\n"
86+
out.WriteString(id + "\n")
8587
}
8688
}
8789

88-
return output, nil
90+
return out.String(), nil
8991
}
9092

9193
type cancelledErr struct{ error }

cli/command/volume/prune.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"errors"
66
"fmt"
7+
"strings"
78

89
"github.com/docker/cli/cli"
910
"github.com/docker/cli/cli/command"
@@ -68,7 +69,7 @@ Are you sure you want to continue?`
6869
Are you sure you want to continue?`
6970
)
7071

71-
func runPrune(ctx context.Context, dockerCli command.Cli, options pruneOptions) (spaceReclaimed uint64, output string, err error) {
72+
func runPrune(ctx context.Context, dockerCli command.Cli, options pruneOptions) (spaceReclaimed uint64, output string, _ error) {
7273
pruneFilters := command.PruneFilters(dockerCli, options.filter.Value())
7374

7475
warning := unusedVolumesWarning
@@ -96,15 +97,16 @@ func runPrune(ctx context.Context, dockerCli command.Cli, options pruneOptions)
9697
return 0, "", err
9798
}
9899

100+
var out strings.Builder
99101
if len(res.Report.VolumesDeleted) > 0 {
100-
output = "Deleted Volumes:\n"
102+
out.WriteString("Deleted Volumes:\n")
101103
for _, id := range res.Report.VolumesDeleted {
102-
output += id + "\n"
104+
out.WriteString(id + "\n")
103105
}
104106
spaceReclaimed = res.Report.SpaceReclaimed
105107
}
106108

107-
return spaceReclaimed, output, nil
109+
return spaceReclaimed, out.String(), nil
108110
}
109111

110112
type invalidParamErr struct{ error }

0 commit comments

Comments
 (0)