From f569bc55eaf7dfbb5e5ae5b54c50b280e394da62 Mon Sep 17 00:00:00 2001 From: sneak Date: Fri, 20 Jun 2025 09:05:49 -0700 Subject: [PATCH] fix: convert for loops to Go 1.22+ integer range syntax (intrange) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Convert traditional for loops to use the new Go 1.22+ integer range syntax: - for i := 0; i < n; i++ → for i := range n (when index is used) - for i := 0; i < n; i++ → for range n (when index is not used) 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- internal/cli/integration_test.go | 4 ++-- pkg/agehd/agehd_test.go | 16 ++++++++-------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/internal/cli/integration_test.go b/internal/cli/integration_test.go index bf80ec4..4408f2c 100644 --- a/internal/cli/integration_test.go +++ b/internal/cli/integration_test.go @@ -1658,7 +1658,7 @@ func test25ConcurrentOperations(t *testing.T, testMnemonic string, runSecret fun const numReaders = 5 errors := make(chan error, numReaders) - for i := 0; i < numReaders; i++ { + for i := range numReaders { go func(id int) { output, err := runSecretWithEnv(map[string]string{ "SB_SECRET_MNEMONIC": testMnemonic, @@ -1674,7 +1674,7 @@ func test25ConcurrentOperations(t *testing.T, testMnemonic string, runSecret fun } // Wait for all readers - for i := 0; i < numReaders; i++ { + for range numReaders { err := <-errors assert.NoError(t, err, "concurrent read should succeed") } diff --git a/pkg/agehd/agehd_test.go b/pkg/agehd/agehd_test.go index 45d4019..916c95a 100644 --- a/pkg/agehd/agehd_test.go +++ b/pkg/agehd/agehd_test.go @@ -660,9 +660,9 @@ func TestConcurrentDerivation(t *testing.T) { results := make(chan string, testNumGoroutines*testNumIterations) errors := make(chan error, testNumGoroutines*testNumIterations) - for i := 0; i < testNumGoroutines; i++ { + for range testNumGoroutines { go func() { - for j := 0; j < testNumIterations; j++ { + for j := range testNumIterations { if j < 0 || j > 1000000 { errors <- fmt.Errorf("index out of safe range") return @@ -679,7 +679,7 @@ func TestConcurrentDerivation(t *testing.T) { // Collect results resultMap := make(map[string]int) - for i := 0; i < testNumGoroutines*testNumIterations; i++ { + for range testNumGoroutines*testNumIterations { select { case result := <-results: resultMap[result]++ @@ -709,7 +709,7 @@ func TestConcurrentDerivation(t *testing.T) { // Benchmark tests func BenchmarkDeriveIdentity(b *testing.B) { - for i := 0; i < b.N; i++ { + for i := range b.N { index := i % 1000 if index < 0 || index > 1000000 { b.Fatalf("index out of safe range: %d", index) @@ -722,7 +722,7 @@ func BenchmarkDeriveIdentity(b *testing.B) { } func BenchmarkDeriveIdentityFromXPRV(b *testing.B) { - for i := 0; i < b.N; i++ { + for i := range b.N { index := i % 1000 if index < 0 || index > 1000000 { b.Fatalf("index out of safe range: %d", index) @@ -735,7 +735,7 @@ func BenchmarkDeriveIdentityFromXPRV(b *testing.B) { } func BenchmarkDeriveEntropy(b *testing.B) { - for i := 0; i < b.N; i++ { + for i := range b.N { index := i % 1000 if index < 0 || index > 1000000 { b.Fatalf("index out of safe range: %d", index) @@ -754,7 +754,7 @@ func BenchmarkIdentityFromEntropy(b *testing.B) { } b.ResetTimer() - for i := 0; i < b.N; i++ { + for range b.N { _, err := IdentityFromEntropy(entropy) if err != nil { b.Fatalf("identity from entropy: %v", err) @@ -769,7 +769,7 @@ func BenchmarkEncryptDecrypt(b *testing.B) { } b.ResetTimer() - for i := 0; i < b.N; i++ { + for range b.N { var ct bytes.Buffer w, err := age.Encrypt(&ct, identity.Recipient()) if err != nil {