golangci-lint: replace exportloopref with copyloopvar and remove the copy of the 'for' variables (#3591)

* fix: replace golangci-lint exportloopref with copyloopvar

* fix: remove copy of the 'for' variables

---------

Co-authored-by: ahrav <[email protected]>
This commit is contained in:
Bob Idle
2024-11-13 12:52:04 -08:00
committed by GitHub
co-authored by ahrav
parent dd74a77de2
commit 409beeb18b
17 changed files with 3 additions and 29 deletions
+1 -1
View File
@@ -28,7 +28,7 @@ jobs:
# working-directory: somedir
# Optional: golangci-lint command line arguments.
args: --enable bodyclose --enable exportloopref --timeout 10m
args: --enable bodyclose --enable copyloopvar --timeout 10m
# Optional: if set to true then the action don't cache or restore ~/go/pkg.
# skip-pkg-cache: true
+1 -1
View File
@@ -22,7 +22,7 @@ check:
go vet $(shell go list ./... | grep -v /vendor/)
lint:
golangci-lint run --enable bodyclose --enable exportloopref --out-format=colored-line-number --timeout 10m
golangci-lint run --enable bodyclose --enable copyloopvar --out-format=colored-line-number --timeout 10m
test-failing:
CGO_ENABLED=0 go test -timeout=5m $(shell go list ./... | grep -v /vendor/) | grep FAIL
-1
View File
@@ -63,7 +63,6 @@ func TestBufferWrite(t *testing.T) {
}
for _, tc := range tests {
tc := tc
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
buf := &Buffer{Buffer: bytes.NewBuffer(make([]byte, 0, tc.initialCapacity))}
-2
View File
@@ -25,7 +25,6 @@ func TestNewBufferPool(t *testing.T) {
}
for _, tc := range tests {
tc := tc
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
pool := NewBufferPool(tc.size)
@@ -62,7 +61,6 @@ func TestBufferPoolGetPut(t *testing.T) {
}
for _, tc := range tests {
tc := tc
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
pool := NewBufferPool(defaultBufferSize)
-3
View File
@@ -64,7 +64,6 @@ func TestRetryableHTTPClientCheckRetry(t *testing.T) {
}
for _, tc := range testCases {
tc := tc
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
var retryCount int
@@ -137,7 +136,6 @@ func TestRetryableHTTPClientMaxRetry(t *testing.T) {
}
for _, tc := range testCases {
tc := tc
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
var retryCount int
@@ -202,7 +200,6 @@ func TestRetryableHTTPClientBackoff(t *testing.T) {
}
for _, tc := range testCases {
tc := tc
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
-1
View File
@@ -91,7 +91,6 @@ func (c *CustomRegexWebhook) FromData(ctx context.Context, verify bool, data []b
// Create result object and test for verification.
resultsCh := make(chan detectors.Result, maxTotalMatches)
for _, match := range matches {
match := match
g.Go(func() error {
return c.createResults(ctx, match, verify, resultsCh)
})
@@ -25,7 +25,6 @@ func TestMultiPartCredentialProviders(t *testing.T) {
}
for _, tc := range testCases {
tc := tc
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
@@ -401,8 +401,6 @@ func TestFindDetectorMatches(t *testing.T) {
}
for _, tc := range testCases {
tc := tc
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
ac := NewAhoCorasickCore(tc.detectors, tc.opts...)
-1
View File
@@ -91,7 +91,6 @@ func (s *Source) Chunks(ctx context.Context, chunksChan chan *sources.Chunk, _ .
scanErrs := sources.NewScanErrors()
for _, proj := range projects {
proj := proj
s.jobPool.Go(func() error {
builds, err := s.buildsForProject(ctx, proj)
if err != nil {
-1
View File
@@ -265,7 +265,6 @@ func (s *Source) Chunks(ctx context.Context, chunksChan chan *sources.Chunk, _ .
var wg sync.WaitGroup
for obj := range objectCh {
obj := obj
o, ok := obj.(object)
if !ok {
ctx.Logger().Error(fmt.Errorf("unexpected object type: %T", obj), "GCS source unexpected object type", "name", s.name)
-2
View File
@@ -397,7 +397,6 @@ func (g *gcsManager) enumerate(ctx context.Context, bkts []bucket) (*attributes,
}(time.Now())
for _, bkt := range bkts {
bkt := bkt
g.workerPool.Go(func() error {
// List all the objects in the bucket and calculate attributes.
g.setupBktHandle(&bkt)
@@ -466,7 +465,6 @@ func (g *gcsManager) ListObjects(ctx context.Context) (chan io.Reader, error) {
gcsErrs := sources.NewScanErrors()
for _, bucket := range g.buckets {
g.numBuckets++
bucket := bucket
g.workerPool.Go(func() error {
objCh, errCh := g.listBucketObjects(ctx, &bucket)
for {
-1
View File
@@ -629,7 +629,6 @@ func (s *Source) scan(ctx context.Context, reporter sources.ChunkReporter) error
s.repos = reposToScan
for i, repoURL := range s.repos {
i, repoURL := i, repoURL
s.jobPool.Go(func() error {
if common.IsDone(ctx) {
return nil
+1 -1
View File
@@ -614,7 +614,7 @@ func (s *Source) scanRepos(ctx context.Context, chunksChan chan *sources.Chunk)
scanErrs := sources.NewScanErrors()
for i, repo := range s.repos {
i, repoURL := i, repo
repoURL := repo
s.jobPool.Go(func() error {
logger := ctx.Logger().WithValues("repo", repoURL)
if common.IsDone(ctx) {
-1
View File
@@ -520,7 +520,6 @@ func (s *Source) scanRepos(ctx context.Context, chunksChan chan *sources.Chunk,
}
for i, repoURL := range repos {
i, repoURL := i, repoURL
s.jobPool.Go(func() error {
if common.IsDone(ctx) {
return nil
-1
View File
@@ -352,7 +352,6 @@ func (s *SourceManager) runWithUnits(ctx context.Context, source SourceUnitEnumC
unitPool.SetLimit(s.concurrentUnits)
}
for unit := range unitReporter.unitCh {
unit := unit
chunkReporter := &mgrChunkReporter{
unit: unit,
chunkCh: make(chan *Chunk, defaultChannelSize),
@@ -36,7 +36,6 @@ func TestBufferWriterWrite(t *testing.T) {
}
for _, tc := range tests {
tc := tc
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
writer := New()
@@ -72,7 +71,6 @@ func TestBufferWriterReadCloser(t *testing.T) {
}
for _, tc := range tests {
tc := tc
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
writer := New()
@@ -136,7 +134,6 @@ func TestBufferWriterString(t *testing.T) {
}
for _, tc := range tests {
tc := tc
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
writer := New()
@@ -30,7 +30,6 @@ func TestBufferedFileWriterNewThreshold(t *testing.T) {
}
for _, tc := range tests {
tc := tc
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
writer := New(tc.options...)
@@ -74,7 +73,6 @@ func TestBufferedFileWriterString(t *testing.T) {
}
for _, tc := range tests {
tc := tc
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
writer := New(WithThreshold(tc.threshold))
@@ -243,7 +241,6 @@ func TestBufferedFileWriterLen(t *testing.T) {
}
for _, tc := range tests {
tc := tc
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
writer := New()
@@ -385,7 +382,6 @@ func TestBufferedFileWriterClose(t *testing.T) {
}
for _, tc := range tests {
tc := tc
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
writer := New(WithThreshold(threshold))
@@ -566,8 +562,6 @@ func TestBufferedFileWriter_ReadFrom(t *testing.T) {
}
for _, tc := range tests {
tc := tc
t.Run(tc.name, func(t *testing.T) {
t.Parallel()