Skip to content

Commit 0b89297

Browse files
committed
fix: resolve preexisting lint issues (govet buildtag, perfsprint concat-loop)
1 parent 704ebe3 commit 0b89297

File tree

8 files changed

+39
-34
lines changed

8 files changed

+39
-34
lines changed

core/cobra_utils_test.go

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"errors"
66
"reflect"
7+
"strings"
78
"testing"
89
"time"
910

@@ -84,16 +85,8 @@ func testGetCommands() *core.Commands {
8485
ArgsType: reflect.TypeOf(args.RawArgs{}),
8586
AllowAnonymousClient: true,
8687
Run: func(_ context.Context, argsI any) (i any, e error) {
87-
res := ""
8888
rawArgs := *argsI.(*args.RawArgs)
89-
for i, arg := range rawArgs {
90-
res += arg
91-
if i != len(rawArgs)-1 {
92-
res += " "
93-
}
94-
}
95-
96-
return res, nil
89+
return strings.Join(rawArgs, " "), nil
9790
},
9891
},
9992
&core.Command{

internal/gotty/resize_windows.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
//go:build windows
2-
// +build windows
32

43
package gotty
54

internal/interactive/list.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"errors"
99
"fmt"
1010
"os"
11+
"strings"
1112

1213
tea "github.com/charmbracelet/bubbletea"
1314
)
@@ -52,19 +53,21 @@ func (m *ListPrompt) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
5253
}
5354

5455
func (m *ListPrompt) View() string {
55-
s := m.Prompt + "\n\n"
56+
var builder strings.Builder
57+
builder.WriteString(m.Prompt + "\n\n")
5658

5759
for i, choice := range m.Choices {
5860
if m.cursor == i {
59-
s += fmt.Sprintf("> %s\n", choice)
61+
fmt.Fprintf(&builder, "> %s\n", choice)
6062
} else {
61-
s += choice + "\n"
63+
builder.WriteString(choice)
64+
builder.WriteByte('\n')
6265
}
6366
}
6467

65-
s += "\nPress enter or space for select.\n"
68+
builder.WriteString("\nPress enter or space for select.\n")
6669

67-
return s
70+
return builder.String()
6871
}
6972

7073
// Execute start the prompt and return the selected index

internal/interactive/print.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,5 @@ func RemoveIndent(str string) string {
7272
}
7373

7474
func makeStr(char string, length int) string {
75-
str := ""
76-
for range length {
77-
str += char
78-
}
79-
80-
return str
75+
return strings.Repeat(char, length)
8176
}

internal/namespaces/autocomplete/autocomplete.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,15 +455,17 @@ func TrimText(str string) string {
455455
for i, line := range lines {
456456
if !foundFirstNonEmptyLine {
457457
if len(line) > 0 {
458+
var builder strings.Builder
458459
for _, c := range line {
459460
if c == ' ' || c == '\t' {
460-
strToRemove += string(c)
461+
builder.WriteRune(c)
461462

462463
continue
463464
}
464465

465466
break
466467
}
468+
strToRemove = builder.String()
467469
foundFirstNonEmptyLine = true
468470
}
469471
}

internal/namespaces/init/init_test.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55
"path"
66
"regexp"
7+
"strings"
78
"testing"
89

910
"github.com/scaleway/scaleway-cli/v2/core"
@@ -26,12 +27,13 @@ func checkConfig(
2627
}
2728

2829
func appendArgs(prefix string, args map[string]string) string {
29-
cmd := prefix
30+
parts := make([]string, 0, len(args)+1)
31+
parts = append(parts, prefix)
3032
for k, v := range args {
31-
cmd += fmt.Sprintf(" %s=%s", k, v)
33+
parts = append(parts, fmt.Sprintf("%s=%s", k, v))
3234
}
3335

34-
return cmd
36+
return strings.Join(parts, " ")
3537
}
3638

3739
func beforeFuncSaveConfig(config *scw.Config) core.BeforeFunc {

internal/namespaces/instance/v1/custom_security_group.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -314,12 +314,19 @@ func securityGroupDeleteBuilder(c *core.Command) *core.Command {
314314
}
315315

316316
// Create detail message.
317-
hint := "Attach all these instances to another security-group before deleting this one:"
317+
lines := make([]string, 0, len(sg.SecurityGroup.Servers)+1)
318+
lines = append(
319+
lines,
320+
"Attach all these instances to another security-group before deleting this one:",
321+
)
318322
for _, s := range sg.SecurityGroup.Servers {
319-
hint += "\nscw instance server update " + s.ID + " security-group.id=$NEW_SECURITY_GROUP_ID"
323+
lines = append(
324+
lines,
325+
"scw instance server update "+s.ID+" security-group.id=$NEW_SECURITY_GROUP_ID",
326+
)
320327
}
321328

322-
newError.Hint = hint
329+
newError.Hint = strings.Join(lines, "\n")
323330

324331
return nil, newError
325332
}

internal/sshconfig/bastion_host.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package sshconfig
22

3-
import "fmt"
3+
import (
4+
"fmt"
5+
"strings"
6+
)
47

58
type BastionHost struct {
69
Name string
@@ -11,22 +14,23 @@ type BastionHost struct {
1114
}
1215

1316
func (b BastionHost) Config() string {
14-
bastionConfig := fmt.Sprintf(`Host %s
17+
parts := make([]string, 0, len(b.Hosts)+1)
18+
parts = append(parts, fmt.Sprintf(`Host %s
1519
ProxyJump bastion@%s
1620
`,
1721
b.name(),
18-
b.address())
22+
b.address()))
1923

2024
for _, host := range b.Hosts {
2125
host.Name = fmt.Sprintf("%s.%s", host.Name, b.Name)
22-
bastionConfig += fmt.Sprintf(`Host %s
26+
parts = append(parts, fmt.Sprintf(`Host %s
2327
User %s
2428
`,
2529
host.name(),
26-
host.user())
30+
host.user()))
2731
}
2832

29-
return bastionConfig
33+
return strings.Join(parts, "")
3034
}
3135

3236
func (b BastionHost) name() string {

0 commit comments

Comments
 (0)