Skip to content

Commit e8dc2fc

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

8 files changed

Lines changed: 12 additions & 12 deletions

File tree

cli/command/container/run_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ func TestRunPullTermination(t *testing.T) {
247247
go func() {
248248
id := test.RandomID()[:12] // short-ID
249249
progressOutput := streamformatter.NewJSONProgressOutput(server, true)
250-
for i := 0; i < 100; i++ {
250+
for i := range 100 {
251251
select {
252252
case <-ctx.Done():
253253
assert.NilError(t, server.Close(), "failed to close imageCreateFunc server")

cli/command/container/tty.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func initTtySize(ctx context.Context, cli command.Cli, id string, isExec bool, r
6060
if err := rTTYfunc(ctx, cli, id, isExec); err != nil {
6161
go func() {
6262
var err error
63-
for retry := 0; retry < 10; retry++ {
63+
for retry := range 10 {
6464
time.Sleep(time.Duration(retry+1) * 10 * time.Millisecond)
6565
if err = rTTYfunc(ctx, cli, id, isExec); err == nil {
6666
break

cli/command/formatter/tabwriter/tabwriter_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func (b *buffer) Write(buf []byte) (written int, err error) {
2525
m := len(buf)
2626
if n+m <= cap(b.a) {
2727
b.a = b.a[0 : n+m]
28-
for i := 0; i < m; i++ {
28+
for i := range m {
2929
b.a[n+i] = buf[i]
3030
}
3131
} else {
@@ -669,7 +669,7 @@ func BenchmarkTable(b *testing.B) {
669669
for i := 0; i < b.N; i++ {
670670
w := NewWriter(io.Discard, 4, 4, 1, ' ', 0) // no particular reason for these settings
671671
// Write the line h times.
672-
for j := 0; j < h; j++ {
672+
for range h {
673673
w.Write(line)
674674
}
675675
w.Flush()
@@ -681,7 +681,7 @@ func BenchmarkTable(b *testing.B) {
681681
w := NewWriter(io.Discard, 4, 4, 1, ' ', 0) // no particular reason for these settings
682682
for i := 0; i < b.N; i++ {
683683
// Write the line h times.
684-
for j := 0; j < h; j++ {
684+
for range h {
685685
w.Write(line)
686686
}
687687
w.Flush()
@@ -701,7 +701,7 @@ func BenchmarkPyramid(b *testing.B) {
701701
for i := 0; i < b.N; i++ {
702702
w := NewWriter(io.Discard, 4, 4, 1, ' ', 0) // no particular reason for these settings
703703
// Write increasing prefixes of that line.
704-
for j := 0; j < x; j++ {
704+
for j := range x {
705705
w.Write(line[:j*2])
706706
w.Write([]byte{'\n'})
707707
}
@@ -723,7 +723,7 @@ func BenchmarkRagged(b *testing.B) {
723723
for i := 0; i < b.N; i++ {
724724
w := NewWriter(io.Discard, 4, 4, 1, ' ', 0) // no particular reason for these settings
725725
// Write the lines in turn h times.
726-
for j := 0; j < h; j++ {
726+
for j := range h {
727727
w.Write(lines[j%len(lines)])
728728
w.Write([]byte{'\n'})
729729
}

cli/command/idresolver/idresolver_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func TestResolveWithCache(t *testing.T) {
6060
idResolver := New(apiClient, false)
6161

6262
ctx := context.Background()
63-
for i := 0; i < 2; i++ {
63+
for range 2 {
6464
id, err := idResolver.Resolve(ctx, swarm.Node{}, "nodeID")
6565
assert.NilError(t, err)
6666
assert.Check(t, is.Equal("node-foo", id))

cli/command/service/list_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ func generateNodes(t *testing.T, activeNodes uint64) client.NodeListResult {
279279
t.Helper()
280280
nodes := client.NodeListResult{}
281281
var i uint64
282-
for i = 0; i < activeNodes; i++ {
282+
for i = range activeNodes {
283283
nodes.Items = append(nodes.Items, swarm.Node{
284284
ID: fmt.Sprintf("node-ready-%d", i),
285285
Status: swarm.NodeStatus{State: swarm.NodeStateReady},

cli/command/service/progress/progress_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -856,7 +856,7 @@ func TestGlobalJobProgressUpdaterLarge(t *testing.T) {
856856
}
857857

858858
activeNodes := map[string]struct{}{}
859-
for i := 0; i < 50; i++ {
859+
for i := range 50 {
860860
activeNodes[fmt.Sprintf("node%v", i)] = struct{}{}
861861
}
862862

cmd/docker/docker.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ func forceExitAfter3TerminationSignals(ctx context.Context, streams command.Stre
410410
signal.Notify(sig, platformsignals.TerminationSignals...)
411411

412412
// once we have received a total of 3 signals we force exit the cli
413-
for i := 0; i < 2; i++ {
413+
for range 2 {
414414
<-sig
415415
}
416416
_, _ = fmt.Fprint(streams.Err(), "\ngot 3 SIGTERM/SIGINTs, forcefully exiting\n")

internal/jsonstream/display_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func TestDisplay(t *testing.T) {
2525
go func() {
2626
id := test.RandomID()[:12] // short-ID
2727
progressOutput := streamformatter.NewJSONProgressOutput(server, true)
28-
for i := 0; i < 100; i++ {
28+
for i := range 100 {
2929
select {
3030
case <-ctx.Done():
3131
assert.NilError(t, server.Close(), "failed to close jsonmessage server")

0 commit comments

Comments
 (0)