Skip to content

Commit 140fd90

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

File tree

8 files changed

+39
-29
lines changed

8 files changed

+39
-29
lines changed

core/cobra_utils_test.go

Lines changed: 5 additions & 4 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,16 @@ 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+
var builder strings.Builder
8990
for i, arg := range rawArgs {
90-
res += arg
91+
builder.WriteString(arg)
9192
if i != len(rawArgs)-1 {
92-
res += " "
93+
builder.WriteString(" ")
9394
}
9495
}
9596

96-
return res, nil
97+
return builder.String(), nil
9798
},
9899
},
99100
&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: 7 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,20 @@ 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+
builder.WriteString(fmt.Sprintf("> %s\n", choice))
6062
} else {
61-
s += choice + "\n"
63+
builder.WriteString(choice + "\n")
6264
}
6365
}
6466

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

67-
return s
69+
return builder.String()
6870
}
6971

7072
// 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+
var builder strings.Builder
31+
builder.WriteString(prefix)
3032
for k, v := range args {
31-
cmd += fmt.Sprintf(" %s=%s", k, v)
33+
builder.WriteString(fmt.Sprintf(" %s=%s", k, v))
3234
}
3335

34-
return cmd
36+
return builder.String()
3537
}
3638

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

internal/namespaces/instance/v1/custom_security_group.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -314,12 +314,17 @@ 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+
var hintBuilder strings.Builder
318+
hintBuilder.WriteString(
319+
"Attach all these instances to another security-group before deleting this one:",
320+
)
318321
for _, s := range sg.SecurityGroup.Servers {
319-
hint += "\nscw instance server update " + s.ID + " security-group.id=$NEW_SECURITY_GROUP_ID"
322+
hintBuilder.WriteString(
323+
"\nscw instance server update " + s.ID + " security-group.id=$NEW_SECURITY_GROUP_ID",
324+
)
320325
}
321326

322-
newError.Hint = hint
327+
newError.Hint = hintBuilder.String()
323328

324329
return nil, newError
325330
}

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+
var builder strings.Builder
18+
builder.WriteString(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+
builder.WriteString(fmt.Sprintf(`Host %s
2327
User %s
2428
`,
2529
host.name(),
26-
host.user())
30+
host.user()))
2731
}
2832

29-
return bastionConfig
33+
return builder.String()
3034
}
3135

3236
func (b BastionHost) name() string {

0 commit comments

Comments
 (0)