Skip to content

Conversation

@YoshihitoAso
Copy link
Member

This pull request primarily removes unnecessary variable reassignments in range loops throughout the codebase, which were previously used to avoid closure capture issues in goroutines and subtests. These changes simplify the code and rely on Go's improved handling of range variable capture since Go 1.22.

Additionally, a new linter is enabled to help catch potential issues with loop variables in the future.

Linter configuration

  • Enabled the copyloopvar linter in .golangci.yml to help detect incorrect usage of loop variables in closures.

Code cleanup and simplification

  • Removed redundant reassignments of range variables (e.g., var := var) in test files and goroutine closures.

Eliminates redundant reassignments of loop variables for closure capture in test and protocol code. This cleanup is possible due to Go 1.22+ fixing closure capture semantics, making these reassignments obsolete and improving code clarity.
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This pull request removes unnecessary variable reassignments in range loops that were previously used to avoid closure capture issues in goroutines and subtests. With Go 1.22's improved handling of range variable capture, these reassignments are no longer needed.

  • Removes redundant var := var reassignments in test files and goroutine closures
  • Enables the copyloopvar linter to catch potential loop variable issues
  • Simplifies code by relying on Go's native range variable handling

Reviewed Changes

Copilot reviewed 19 out of 19 changed files in this pull request and generated no comments.

Show a summary per file
File Description
.golangci.yml Enables the copyloopvar linter
tests/state_test.go Removes subtest variable reassignment in range loop
rpc/client_test.go Removes index variable reassignment in goroutine
p2p/peer.go Removes proto variable reassignment in goroutine
p2p/nodestate/nodestate.go Removes callback variable reassignment
p2p/discover/v5wire/encoding_test.go Removes test variable reassignment in subtest
node/node_test.go Removes test variable reassignment in subtest
node/api_test.go Removes test variable reassignment in parallel subtest
les/commons.go Removes version variable reassignment in protocol creation
les/api_test.go Removes client variables reassignment in goroutine
eth/tracers/tracers_test.go Removes file variable reassignment in parallel subtest
eth/protocols/snap/handler.go Removes version variable reassignment
eth/protocols/eth/handler.go Removes version variable reassignment
eth/handler_eth_test.go Removes sink and channel variable reassignments in goroutines
eth/fetcher/block_fetcher.go Removes hashes variable reassignment in goroutine
eth/downloader/downloader.go Removes function variable reassignment in goroutine
cmd/geth/accountcmd_test.go Removes test variable reassignment in parallel subtest
accounts/abi/unpack_test.go Removes test case variable reassignment in subtest
accounts/abi/event_test.go Removes test case variable reassignment in subtest

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@YoshihitoAso YoshihitoAso moved this to In Progress in ibet-Network v2.6 Sep 22, 2025
@YoshihitoAso YoshihitoAso marked this pull request as ready for review September 22, 2025 02:25
@YoshihitoAso YoshihitoAso merged commit 8450958 into dev-2.6 Sep 22, 2025
5 checks passed
@github-project-automation github-project-automation bot moved this from In Progress to Done in ibet-Network v2.6 Sep 22, 2025
@YoshihitoAso YoshihitoAso deleted the lint-copyloopvar branch September 22, 2025 02:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants