Skip to content

Commit 835d510

Browse files
committed
modernize: stringsseq
go install golang.org/x/tools/go/analysis/passes/modernize/cmd/modernize@latest modernize -stringsseq -fix ./... Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
1 parent dd73e2d commit 835d510

6 files changed

Lines changed: 23 additions & 9 deletions

File tree

cli-plugins/manager/hooks.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// FIXME(thaJeztah): remove once we are a module; the go:build directive prevents go from downgrading language version to go1.16:
2+
//go:build go1.24
3+
14
package manager
25

36
import (
@@ -141,8 +144,7 @@ func pluginMatch(pluginCfg map[string]string, subCmd string) (string, bool) {
141144
return "", false
142145
}
143146

144-
commands := strings.Split(configuredPluginHooks, ",")
145-
for _, hookCmd := range commands {
147+
for hookCmd := range strings.SplitSeq(configuredPluginHooks, ",") {
146148
if hookMatch(hookCmd, subCmd) {
147149
return hookCmd, true
148150
}

cli/command/container/opts.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -902,7 +902,7 @@ func convertToStandardNotation(ports []string) ([]string, error) {
902902
for _, publish := range ports {
903903
if strings.Contains(publish, "=") {
904904
params := map[string]string{"protocol": "tcp"}
905-
for _, param := range strings.Split(publish, ",") {
905+
for param := range strings.SplitSeq(publish, ",") {
906906
k, v, ok := strings.Cut(param, "=")
907907
if !ok || k == "" {
908908
return optsList, fmt.Errorf("invalid publish opts format (should be name=value but got '%s')", param)

cli/command/container/stats.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// FIXME(thaJeztah): remove once we are a module; the go:build directive prevents go from downgrading language version to go1.16:
2+
//go:build go1.24
3+
14
package container
25

36
import (
@@ -337,7 +340,7 @@ func RunStats(ctx context.Context, dockerCLI command.Cli, options *StatsOptions)
337340
return err
338341
}
339342

340-
for _, line := range strings.Split(statsTextBuffer.String(), "\n") {
343+
for line := range strings.SplitSeq(statsTextBuffer.String(), "\n") {
341344
// In case the new text is shorter than the one we are writing over,
342345
// we'll append the "erase line" escape sequence to clear the remaining text.
343346
_, _ = fmt.Fprintln(&statsTextBuffer, line, "\033[K")

cli/command/volume/create.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// FIXME(thaJeztah): remove once we are a module; the go:build directive prevents go from downgrading language version to go1.16:
2+
//go:build go1.24
3+
14
package volume
25

36
import (
@@ -166,7 +169,7 @@ func runCreate(ctx context.Context, dockerCli command.Cli, options createOptions
166169
// each topology takes the form segment=value,segment=value
167170
// comma-separated list of equal separated maps
168171
segments := map[string]string{}
169-
for _, segment := range strings.Split(top, ",") {
172+
for segment := range strings.SplitSeq(top, ",") {
170173
// TODO(dperny): validate topology syntax
171174
k, v, _ := strings.Cut(segment, "=")
172175
segments[k] = v
@@ -181,7 +184,7 @@ func runCreate(ctx context.Context, dockerCli command.Cli, options createOptions
181184
// each topology takes the form segment=value,segment=value
182185
// comma-separated list of equal separated maps
183186
segments := map[string]string{}
184-
for _, segment := range strings.Split(top, ",") {
187+
for segment := range strings.SplitSeq(top, ",") {
185188
// TODO(dperny): validate topology syntax
186189
k, v, _ := strings.Cut(segment, "=")
187190
segments[k] = v

internal/test/strings.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// FIXME(thaJeztah): remove once we are a module; the go:build directive prevents go from downgrading language version to go1.16:
2+
//go:build go1.24
3+
14
package test
25

36
import (
@@ -15,12 +18,12 @@ func CompareMultipleValues(t *testing.T, value, expected string) {
1518
// be guaranteed to have the same order as our expected value
1619
// We'll create maps and use reflect.DeepEquals to check instead:
1720
entriesMap := make(map[string]string)
18-
for _, entry := range strings.Split(value, ",") {
21+
for entry := range strings.SplitSeq(value, ",") {
1922
k, v, _ := strings.Cut(entry, "=")
2023
entriesMap[k] = v
2124
}
2225
expMap := make(map[string]string)
23-
for _, exp := range strings.Split(expected, ",") {
26+
for exp := range strings.SplitSeq(expected, ",") {
2427
k, v, _ := strings.Cut(exp, "=")
2528
expMap[k] = v
2629
}

internal/volumespec/volumespec.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// FIXME(thaJeztah): remove once we are a module; the go:build directive prevents go from downgrading language version to go1.16:
2+
//go:build go1.24
3+
14
package volumespec
25

36
import (
@@ -67,7 +70,7 @@ func populateFieldFromBuffer(char rune, buffer []rune, volume *VolumeConfig) err
6770
case char == ':':
6871
return errors.New("too many colons")
6972
}
70-
for _, option := range strings.Split(strBuffer, ",") {
73+
for option := range strings.SplitSeq(strBuffer, ",") {
7174
switch option {
7275
case "ro":
7376
volume.ReadOnly = true

0 commit comments

Comments
 (0)