Find, verify, and analyze leaked credentials
Go credentialsdevsecopsdynamic-analysisprecommitscanningsecretsecret-managementsecretssecuritysecurity-toolstrufflehogverification
golangci-lint: replace exportloopref with copyloopvar and remove the copy of the 'for' variables (#3591)
Bob Idle409beeb18b4e
diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.ymlindex 09f00b37e..215c1bfc6 100644--- a/.github/workflows/lint.yml+++ b/.github/workflows/lint.yml@@ -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: truediff --git a/Makefile b/Makefileindex 43e9a58ab..a74a4f7f7 100644--- a/Makefile+++ b/Makefile@@ -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 10mtest-failing:CGO_ENABLED=0 go test -timeout=5m $(shell go list ./... | grep -v /vendor/) | grep FAILdiff --git a/pkg/buffers/buffer/buffer_test.go b/pkg/buffers/buffer/buffer_test.goindex bbf4987e2..f25189890 100644--- a/pkg/buffers/buffer/buffer_test.go+++ b/pkg/buffers/buffer/buffer_test.go@@ -63,7 +63,6 @@ func TestBufferWrite(t *testing.T) {}for _, tc := range tests {- tc := tct.Run(tc.name, func(t *testing.T) {t.Parallel()buf := &Buffer{Buffer: bytes.NewBuffer(make([]byte, 0, tc.initialCapacity))}diff --git a/pkg/buffers/pool/pool_test.go b/pkg/buffers/pool/pool_test.goindex 3fb85a028..e322cb707 100644--- a/pkg/buffers/pool/pool_test.go+++ b/pkg/buffers/pool/pool_test.go@@ -25,7 +25,6 @@ func TestNewBufferPool(t *testing.T) {}for _, tc := range tests {- tc := tct.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 := tct.Run(tc.name, func(t *testing.T) {t.Parallel()pool := NewBufferPool(defaultBufferSize)diff --git a/pkg/common/http_test.go b/pkg/common/http_test.goindex cc1711b42..d405583b6 100644--- a/pkg/common/http_test.go+++ b/pkg/common/http_test.go@@ -64,7 +64,6 @@ func TestRetryableHTTPClientCheckRetry(t *testing.T) {}for _, tc := range testCases {- tc := tct.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 := tct.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 := tct.Run(tc.name, func(t *testing.T) {t.Parallel()diff --git a/pkg/custom_detectors/custom_detectors.go b/pkg/custom_detectors/custom_detectors.goindex 96b72fa1d..2403661a2 100644--- a/pkg/custom_detectors/custom_detectors.go+++ b/pkg/custom_detectors/custom_detectors.go@@ -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 := matchg.Go(func() error {return c.createResults(ctx, match, verify, resultsCh)})diff --git a/pkg/detectors/multi_part_credential_provider_test.go b/pkg/detectors/multi_part_credential_provider_test.goindex ddc9cb045..a27ce141b 100644--- a/pkg/detectors/multi_part_credential_provider_test.go+++ b/pkg/detectors/multi_part_credential_provider_test.go@@ -25,7 +25,6 @@ func TestMultiPartCredentialProviders(t *testing.T) {}for _, tc := range testCases {- tc := tct.Run(tc.name, func(t *testing.T) {t.Parallel()diff --git a/pkg/engine/ahocorasick/ahocorasickcore_test.go b/pkg/engine/ahocorasick/ahocorasickcore_test.goindex f2950dd1c..c33954a7d 100644--- a/pkg/engine/ahocorasick/ahocorasickcore_test.go+++ b/pkg/engine/ahocorasick/ahocorasickcore_test.go@@ -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...)diff --git a/pkg/sources/circleci/circleci.go b/pkg/sources/circleci/circleci.goindex 11325a979..d89b4b231 100644--- a/pkg/sources/circleci/circleci.go+++ b/pkg/sources/circleci/circleci.go@@ -91,7 +91,6 @@ func (s *Source) Chunks(ctx context.Context, chunksChan chan *sources.Chunk, _ .scanErrs := sources.NewScanErrors()for _, proj := range projects {- proj := projs.jobPool.Go(func() error {builds, err := s.buildsForProject(ctx, proj)if err != nil {diff --git a/pkg/sources/gcs/gcs.go b/pkg/sources/gcs/gcs.goindex 7e9a05ced..f23c4f9ee 100644--- a/pkg/sources/gcs/gcs.go+++ b/pkg/sources/gcs/gcs.go@@ -265,7 +265,6 @@ func (s *Source) Chunks(ctx context.Context, chunksChan chan *sources.Chunk, _ .var wg sync.WaitGroupfor obj := range objectCh {- obj := objo, ok := obj.(object)if !ok {ctx.Logger().Error(fmt.Errorf("unexpected object type: %T", obj), "GCS source unexpected object type", "name", s.name)diff --git a/pkg/sources/gcs/gcs_manager.go b/pkg/sources/gcs/gcs_manager.goindex fcbf5a709..33ede589d 100644--- a/pkg/sources/gcs/gcs_manager.go+++ b/pkg/sources/gcs/gcs_manager.go@@ -397,7 +397,6 @@ func (g *gcsManager) enumerate(ctx context.Context, bkts []bucket) (*attributes,}(time.Now())for _, bkt := range bkts {- bkt := bktg.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 := bucketg.workerPool.Go(func() error {objCh, errCh := g.listBucketObjects(ctx, &bucket)for {diff --git a/pkg/sources/github/github.go b/pkg/sources/github/github.goindex 4e2fac186..680a7b42f 100644--- a/pkg/sources/github/github.go+++ b/pkg/sources/github/github.go@@ -629,7 +629,6 @@ func (s *Source) scan(ctx context.Context, reporter sources.ChunkReporter) errors.repos = reposToScanfor i, repoURL := range s.repos {- i, repoURL := i, repoURLs.jobPool.Go(func() error {if common.IsDone(ctx) {return nildiff --git a/pkg/sources/gitlab/gitlab.go b/pkg/sources/gitlab/gitlab.goindex 27c48add8..7eec5f86d 100644--- a/pkg/sources/gitlab/gitlab.go+++ b/pkg/sources/gitlab/gitlab.go@@ -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 := repos.jobPool.Go(func() error {logger := ctx.Logger().WithValues("repo", repoURL)if common.IsDone(ctx) {diff --git a/pkg/sources/huggingface/huggingface.go b/pkg/sources/huggingface/huggingface.goindex 135673eb9..462f33df6 100644--- a/pkg/sources/huggingface/huggingface.go+++ b/pkg/sources/huggingface/huggingface.go@@ -520,7 +520,6 @@ func (s *Source) scanRepos(ctx context.Context, chunksChan chan *sources.Chunk,}for i, repoURL := range repos {- i, repoURL := i, repoURLs.jobPool.Go(func() error {if common.IsDone(ctx) {return nildiff --git a/pkg/sources/source_manager.go b/pkg/sources/source_manager.goindex f3afe74ec..29ac4ce56 100644--- a/pkg/sources/source_manager.go+++ b/pkg/sources/source_manager.go@@ -352,7 +352,6 @@ func (s *SourceManager) runWithUnits(ctx context.Context, source SourceUnitEnumCunitPool.SetLimit(s.concurrentUnits)}for unit := range unitReporter.unitCh {- unit := unitchunkReporter := &mgrChunkReporter{unit: unit,chunkCh: make(chan *Chunk, defaultChannelSize),diff --git a/pkg/writers/buffer_writer/bufferwriter_test.go b/pkg/writers/buffer_writer/bufferwriter_test.goindex fd6ce69aa..5ef9bccd5 100644--- a/pkg/writers/buffer_writer/bufferwriter_test.go+++ b/pkg/writers/buffer_writer/bufferwriter_test.go@@ -36,7 +36,6 @@ func TestBufferWriterWrite(t *testing.T) {}for _, tc := range tests {- tc := tct.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 := tct.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 := tct.Run(tc.name, func(t *testing.T) {t.Parallel()writer := New()diff --git a/pkg/writers/buffered_file_writer/bufferedfilewriter_test.go b/pkg/writers/buffered_file_writer/bufferedfilewriter_test.goindex 3f4fad534..193c398f2 100644--- a/pkg/writers/buffered_file_writer/bufferedfilewriter_test.go+++ b/pkg/writers/buffered_file_writer/bufferedfilewriter_test.go@@ -30,7 +30,6 @@ func TestBufferedFileWriterNewThreshold(t *testing.T) {}for _, tc := range tests {- tc := tct.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 := tct.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 := tct.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 := tct.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()