diff --git a/.golangci.yml b/.golangci.yml index 6d7cf0033..78273fdcd 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -38,6 +38,7 @@ linters: - grouper # An analyzer to analyze expression groups. [fast: true, auto-fix: false] - importas # Enforces consistent import aliases [fast: false, auto-fix: false] - ineffassign # Detects when assignments to existing variables are not used [fast: true, auto-fix: false] + - intrange # intrange is a linter to find places where for loops could make use of an integer range. [fast: true, auto-fix: false] - ireturn # Accept Interfaces, Return Concrete Types [fast: false, auto-fix: false] - loggercheck # (logrlint): Checks key value pairs for common logger libraries (kitlog,klog,logr,zap). [fast: false, auto-fix: false] - makezero # Finds slice declarations with non-zero initial length [fast: false, auto-fix: false] diff --git a/internal/cdf/locality.go b/internal/cdf/locality.go index fd8de8b1f..eb181f941 100644 --- a/internal/cdf/locality.go +++ b/internal/cdf/locality.go @@ -34,7 +34,7 @@ func expandListKeys(key string, diff *schema.ResourceDiff) []string { keys := make([]string, 0, listLength) - for i := 0; i < listLength; i++ { + for i := range listLength { addr[index] = strconv.FormatInt(int64(i), 10) keys = append(keys, strings.Join(addr, ".")) } diff --git a/internal/types/string_test.go b/internal/types/string_test.go index 013cccc04..c8b74c062 100644 --- a/internal/types/string_test.go +++ b/internal/types/string_test.go @@ -26,7 +26,7 @@ func TestStringHashcode_positiveIndex(t *testing.T) { func TestStringHashcode(t *testing.T) { v := "hello, world" expected := types.StringHashcode(v) - for i := 0; i < 100; i++ { + for range 100 { actual := types.StringHashcode(v) if actual != expected { t.Fatalf("bad: %#v\n\t%#v", actual, expected) diff --git a/internal/workerpool/workerpool.go b/internal/workerpool/workerpool.go index 2eaa616e8..ffd76c172 100644 --- a/internal/workerpool/workerpool.go +++ b/internal/workerpool/workerpool.go @@ -18,7 +18,7 @@ func NewWorkerPool(size int) *WorkerPool { tasksToRun: make(chan Task, size), } - for i := 0; i < size; i++ { + for range size { go p.worker() } diff --git a/internal/workerpool/workerpool_test.go b/internal/workerpool/workerpool_test.go index f4fc5ce5c..2d018d754 100644 --- a/internal/workerpool/workerpool_test.go +++ b/internal/workerpool/workerpool_test.go @@ -59,7 +59,7 @@ func TestWorkerPoolWaitTimeMultiple(t *testing.T) { pool := workerpool.NewWorkerPool(5) iterations := 20 - for i := 0; i < iterations; i++ { + for i := range iterations { copyOfI := i pool.AddTask(func() error { @@ -77,7 +77,7 @@ func TestWorkerPoolWaitTimeMultiple(t *testing.T) { assert.Len(t, errs, iterations/2) - for i := 0; i < iterations; i++ { + for i := range iterations { if i%2 == 0 { found := false for _, err := range errs {