Skip to content

Commit 6631156

Browse files
committed
refactor: fix modernize lint issues
Signed-off-by: Oleksandr Redko <oleksandr.red+github@gmail.com>
1 parent e21b634 commit 6631156

File tree

11 files changed

+17
-19
lines changed

11 files changed

+17
-19
lines changed

.golangci.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ linters:
1919
- ineffassign
2020
- intrange
2121
- misspell
22+
- modernize
2223
- nakedret
2324
- noctx
2425
- nolintlint
@@ -71,6 +72,10 @@ linters:
7172
ifElseChain:
7273
# Min number of if-else blocks that makes the warning trigger.
7374
minThreshold: 3
75+
modernize:
76+
disable:
77+
- omitzero
78+
- stringsbuilder
7479
perfsprint:
7580
int-conversion: false
7681
err-error: false

cmd/limactl/editflags/editflags.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,7 @@ func ParsePortForward(spec string) (hostPort, guestPort string, isStatic bool, e
137137

138138
if len(parts) == 2 {
139139
staticPart := strings.TrimSpace(parts[1])
140-
if strings.HasPrefix(staticPart, "static=") {
141-
staticValue := strings.TrimPrefix(staticPart, "static=")
140+
if staticValue, ok := strings.CutPrefix(staticPart, "static="); ok {
142141
isStatic, err = strconv.ParseBool(staticValue)
143142
if err != nil {
144143
return "", "", false, fmt.Errorf("invalid value for static parameter: %q", staticValue)

cmd/limactl/gendoc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ func escapeMarkdown(text string) string {
105105
lines := strings.Split(text, "\n")
106106
for i := range lines {
107107
// Need to escape backticks first, before adding more
108-
for _, c := range strings.Split("\\`*_[]()#+-.|", "") {
108+
for c := range strings.SplitSeq("\\`*_[]()#+-.|", "") {
109109
lines[i] = strings.ReplaceAll(lines[i], c, "\\"+c)
110110
}
111111
if i < len(lines)-1 {

cmd/limactl/list.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ import (
2525

2626
func fieldNames() []string {
2727
names := []string{}
28-
var data store.FormatData
29-
t := reflect.TypeOf(data)
28+
t := reflect.TypeFor[store.FormatData]()
3029
for i := range t.NumField() {
3130
f := t.Field(i)
3231
if f.Anonymous {

pkg/cidata/cidata.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ func GenerateISO9660(ctx context.Context, drv driver.Driver, instDir, name strin
475475

476476
func getCert(content string) Cert {
477477
lines := []string{}
478-
for _, line := range strings.Split(content, "\n") {
478+
for line := range strings.SplitSeq(content, "\n") {
479479
if line == "" {
480480
continue
481481
}
@@ -490,7 +490,7 @@ func getBootCmds(p []limatype.Provision) []BootCmds {
490490
for _, f := range p {
491491
if f.Mode == limatype.ProvisionModeBoot {
492492
lines := []string{}
493-
for _, line := range strings.Split(*f.Script, "\n") {
493+
for line := range strings.SplitSeq(*f.Script, "\n") {
494494
if line == "" {
495495
continue
496496
}

pkg/downloader/downloader.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -437,8 +437,7 @@ func canonicalLocalPath(s string) (string, error) {
437437
if !IsLocal(s) {
438438
return "", fmt.Errorf("got non-local path: %q", s)
439439
}
440-
if strings.HasPrefix(s, "file://") {
441-
res := strings.TrimPrefix(s, "file://")
440+
if res, ok := strings.CutPrefix(s, "file://"); ok {
442441
if !filepath.IsAbs(res) {
443442
return "", fmt.Errorf("got non-absolute path %q", res)
444443
}

pkg/driver/krunkit/krunkit_driver_darwin_arm64.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ func (l *LimaKrunkitDriver) Start(ctx context.Context) (chan error, error) {
9191
}
9292

9393
pidPath := filepath.Join(l.Instance.Dir, filenames.PIDFile(*l.Instance.Config.VMType))
94-
if err := os.WriteFile(pidPath, []byte(fmt.Sprintf("%d\n", krunkitCmd.Process.Pid)), 0o644); err != nil {
94+
if err := os.WriteFile(pidPath, fmt.Appendf(nil, "%d\n", krunkitCmd.Process.Pid), 0o644); err != nil {
9595
logrus.WithError(err).Warn("Failed to write PID file")
9696
}
9797

pkg/editutil/editutil.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func fileWarning(filename string) string {
2727
s := "# WARNING: " + filename + " includes the following settings,\n"
2828
s += "# which are applied before applying this YAML:\n"
2929
s += "# -----------\n"
30-
for _, line := range strings.Split(strings.TrimSuffix(string(b), "\n"), "\n") {
30+
for line := range strings.SplitSeq(strings.TrimSuffix(string(b), "\n"), "\n") {
3131
s += "#"
3232
if line != "" {
3333
s += " " + line

pkg/hostagent/hostagent.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,8 +1063,7 @@ func (a *HostAgent) watchCloudInitProgress(ctx context.Context) {
10631063

10641064
finalCmd := exec.CommandContext(ctx, a.sshConfig.Binary(), finalArgs...)
10651065
if finalOutput, err := finalCmd.Output(); err == nil {
1066-
lines := strings.Split(string(finalOutput), "\n")
1067-
for _, line := range lines {
1066+
for line := range strings.SplitSeq(string(finalOutput), "\n") {
10681067
if strings.TrimSpace(line) != "" {
10691068
if !cloudInitFinished {
10701069
cloudInitFinished = isCloudInitFinished(line)

pkg/limatmpl/embed.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -599,10 +599,7 @@ func binaryString(s string) string {
599599
builder.Grow(len(encoded) + lineCount)
600600

601601
for i := 0; i < len(encoded); i += base64ChunkLength {
602-
end := i + base64ChunkLength
603-
if end > len(encoded) {
604-
end = len(encoded)
605-
}
602+
end := min(i+base64ChunkLength, len(encoded))
606603
builder.WriteString(encoded[i:end])
607604
builder.WriteByte('\n')
608605
}

0 commit comments

Comments
 (0)