From a64c0a0fde9ef9cbcd5ce98472c3e4920505952c Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Thu, 20 Aug 2026 15:01:28 +0100 Subject: [PATCH] build: modernize with "go fix -rangeint": use range over int --- backend/azureblob/arrowlist/arrow.go | 2 +- backend/azureblob/arrowlist/arrow_test.go | 2 +- backend/iclouddrive/api/photos.go | 2 +- backend/iclouddrive/api/photos_test.go | 4 ++-- backend/sftp/sftp_internal_test.go | 8 ++++---- backend/zoho/folderlist_test.go | 8 ++++---- fs/log/slog_test.go | 16 ++++++++-------- vfs/vfscache/item_test.go | 2 +- 8 files changed, 22 insertions(+), 22 deletions(-) diff --git a/backend/azureblob/arrowlist/arrow.go b/backend/azureblob/arrowlist/arrow.go index 4e8c185ed..e4e788553 100644 --- a/backend/azureblob/arrowlist/arrow.go +++ b/backend/azureblob/arrowlist/arrow.go @@ -157,7 +157,7 @@ func parseArrowStream(body io.Reader) ([]*container.BlobItem, *string, error) { rec := reader.RecordBatch() rows := int(rec.NumRows()) - for row := 0; row < rows; row++ { + for row := range rows { item := &container.BlobItem{ Properties: &container.BlobProperties{}, } diff --git a/backend/azureblob/arrowlist/arrow_test.go b/backend/azureblob/arrowlist/arrow_test.go index d1995b2b1..9c0c24f5d 100644 --- a/backend/azureblob/arrowlist/arrow_test.go +++ b/backend/azureblob/arrowlist/arrow_test.go @@ -198,7 +198,7 @@ func TestHandleFlatListResponse_MultiRecordBatch(t *testing.T) { // First batch: 2 rows builder := arrowArray.NewRecordBuilder(alloc, schema) - for i := 0; i < 2; i++ { + for range 2 { builder.Field(0).(*arrowArray.StringBuilder).Append("batch1_blob") for j := 1; j < 11; j++ { builder.Field(j).AppendNull() diff --git a/backend/iclouddrive/api/photos.go b/backend/iclouddrive/api/photos.go index f88a5c8ad..79feae537 100644 --- a/backend/iclouddrive/api/photos.go +++ b/backend/iclouddrive/api/photos.go @@ -2031,7 +2031,7 @@ func (album *Album) fetchPhotosParallel(ctx context.Context, totalPhotos int64) sem := make(chan struct{}, workers) var wg sync.WaitGroup - for i := 0; i < numPartitions; i++ { + for i := range numPartitions { wg.Add(1) go func(idx int) { defer wg.Done() diff --git a/backend/iclouddrive/api/photos_test.go b/backend/iclouddrive/api/photos_test.go index c451a2e75..070680b19 100644 --- a/backend/iclouddrive/api/photos_test.go +++ b/backend/iclouddrive/api/photos_test.go @@ -1191,7 +1191,7 @@ func TestFlushCaches_NoPendingDeltaRace(t *testing.T) { done := make(chan struct{}) go func() { defer close(done) - for i := 0; i < 100; i++ { + for range 100 { lib.deltaMu.Lock() lib.pendingDelta = &deltaPayload{ records: []json.RawMessage{json.RawMessage(`{"recordName":"m1","recordType":"CPLMaster"}`)}, @@ -1201,7 +1201,7 @@ func TestFlushCaches_NoPendingDeltaRace(t *testing.T) { lib.applyPendingDelta(context.Background()) } }() - for i := 0; i < 100; i++ { + for range 100 { ps.FlushCaches() // Re-add the library since FlushCaches clears it ps.mu.Lock() diff --git a/backend/sftp/sftp_internal_test.go b/backend/sftp/sftp_internal_test.go index 9dd8ae360..26306c29c 100644 --- a/backend/sftp/sftp_internal_test.go +++ b/backend/sftp/sftp_internal_test.go @@ -428,7 +428,7 @@ func TestHostKeyCallbackRefusesAtCap(t *testing.T) { opt: Options{PinHostKey: true}, hostKeys: map[string][][]byte{}, } - for i := 0; i < maxHostKeys; i++ { + for i := range maxHostKeys { algo := fmt.Sprintf("test-algo-%d", i) f.hostKeys[algo] = [][]byte{{byte(i)}} } @@ -480,7 +480,7 @@ func TestHostKeyCallbackPinHostKeyRace(t *testing.T) { const N = 16 pendings := make([]*pendingKey, N) wg.Add(N) - for i := 0; i < N; i++ { + for i := range N { go func(i int) { defer wg.Done() cb := f.hostKeyCallback(&pendings[i]) @@ -489,7 +489,7 @@ func TestHostKeyCallbackPinHostKeyRace(t *testing.T) { }(i) } wg.Wait() - for i := 0; i < N; i++ { + for i := range N { require.NotNil(t, pendings[i], "dial %d should have stashed its own key", i) assert.Equal(t, keyBytes, pendings[i].marshalled) } @@ -631,7 +631,7 @@ func TestCommitHostKeyConcurrent(t *testing.T) { keys := makeTestKeys(t, N) var wg sync.WaitGroup wg.Add(N) - for i := 0; i < N; i++ { + for i := range N { go func(i int) { defer wg.Done() f.commitHostKey(&pendingKey{ diff --git a/backend/zoho/folderlist_test.go b/backend/zoho/folderlist_test.go index 1ee5d71a5..35f5dfafe 100644 --- a/backend/zoho/folderlist_test.go +++ b/backend/zoho/folderlist_test.go @@ -103,7 +103,7 @@ func TestFolderWindowLimiterShape(t *testing.T) { } // Window 1: the first burst grants pass immediately... - for i := 0; i < defaultListFolderBurst; i++ { + for i := range defaultListFolderBurst { assert.Equal(t, base, reserve(base), "burst grant %d passes immediately", i+1) } // ...then the paced phase spends the rest of the budget one interval apart @@ -149,14 +149,14 @@ func TestFolderWindowLimiterIdleResume(t *testing.T) { var grants []time.Time g := base // Spend window 1's full budget greedily. - for i := 0; i < defaultListFolderLimit; i++ { + for range defaultListFolderLimit { g = lim.reserve(g) grants = append(grants, g) } // Resume mid-window-2 after an idle gap and hammer across the 2->3 // boundary: a fresh burst fires on resume and again at the boundary. g = base.Add(window + window/2) - for i := 0; i < defaultListFolderLimit; i++ { + for range defaultListFolderLimit { g = lim.reserve(g) grants = append(grants, g) } @@ -187,7 +187,7 @@ func TestFolderWindowLimiterClamps(t *testing.T) { // burst >= limit clamps to limit-1, leaving one paced token per window. lim = newFs(5, 99).folderListLimiter("Y") - for i := 0; i < 4; i++ { + for i := range 4 { assert.Equal(t, base, lim.reserve(base), "clamped burst grant %d", i+1) } assert.Equal(t, base.Add(window), lim.reserve(base), "5th grant rolls into the next window") diff --git a/fs/log/slog_test.go b/fs/log/slog_test.go index e12a2debc..07d32be06 100644 --- a/fs/log/slog_test.go +++ b/fs/log/slog_test.go @@ -287,11 +287,11 @@ func TestOutputHandlerConcurrency(t *testing.T) { var wg sync.WaitGroup // Goroutines calling Handle (text format) - for i := 0; i < goroutines; i++ { + for range goroutines { wg.Add(1) go func() { defer wg.Done() - for j := 0; j < iterations; j++ { + for range iterations { r := slog.NewRecord(t0, slog.LevelInfo, "concurrent text", 0) r.AddAttrs(slog.String("object", "obj")) _ = h.Handle(ctx, r) @@ -300,11 +300,11 @@ func TestOutputHandlerConcurrency(t *testing.T) { } // Goroutines calling setFormat (switching between text and JSON) - for i := 0; i < 2; i++ { + for range 2 { wg.Add(1) go func() { defer wg.Done() - for j := 0; j < iterations; j++ { + for j := range iterations { if j%2 == 0 { h.setFormat(logFormatDate | logFormatTime) } else { @@ -318,7 +318,7 @@ func TestOutputHandlerConcurrency(t *testing.T) { wg.Add(1) go func() { defer wg.Done() - for j := 0; j < iterations; j++ { + for range iterations { h.setFormatFlags(logFormatPid | logFormatMicroseconds) h.clearFormatFlags(logFormatPid | logFormatMicroseconds) } @@ -328,7 +328,7 @@ func TestOutputHandlerConcurrency(t *testing.T) { wg.Add(1) go func() { defer wg.Done() - for j := 0; j < iterations; j++ { + for j := range iterations { if j%2 == 0 { h.SetLevel(slog.LevelDebug) } else { @@ -342,7 +342,7 @@ func TestOutputHandlerConcurrency(t *testing.T) { go func() { defer wg.Done() noop := func(_ slog.Level, _ string) {} - for j := 0; j < iterations; j++ { + for range iterations { h.SetOutput(noop) h.ResetOutput() } @@ -352,7 +352,7 @@ func TestOutputHandlerConcurrency(t *testing.T) { wg.Add(1) go func() { defer wg.Done() - for j := 0; j < iterations; j++ { + for range iterations { _ = h.WithAttrs(nil) _ = h.WithGroup("g") } diff --git a/vfs/vfscache/item_test.go b/vfs/vfscache/item_test.go index 0d7415b17..bf75a819b 100644 --- a/vfs/vfscache/item_test.go +++ b/vfs/vfscache/item_test.go @@ -769,7 +769,7 @@ func TestItemHandleCachingReopenDuringGraceClose(t *testing.T) { buf := make([]byte, 1) const iterations = 50 - for i := 0; i < iterations; i++ { + for i := range iterations { // Open, read (to create a downloader) and close so a grace // timer is pending with the fd and downloaders still alive. require.NoError(t, item.Open(obj))