Skip to content

lint: reactivate several disabled linters#10872

Open
erickcestari wants to merge 6 commits into
lightningnetwork:masterfrom
erickcestari:enable-copyloopvar-linter
Open

lint: reactivate several disabled linters#10872
erickcestari wants to merge 6 commits into
lightningnetwork:masterfrom
erickcestari:enable-copyloopvar-linter

Conversation

@erickcestari
Copy link
Copy Markdown
Collaborator

@erickcestari erickcestari commented Jun 3, 2026

This PR enables five previously-disabled linters and fixes the violations they surface. It also corrects a mislabeled section of .golangci.yml where a block of active linters was wrongly commented as "Deprecated linters".

Each linter is enabled in its own commit, with code fixes landing before the linter is switched on, so CI stays green at every commit. Code changes are also split into separate test-file and non-test-file commits.

Linters enabled:

  • copyloopvar: redundant x := x loop-variable copies, unnecessary since Go 1.22 per-iteration scoping (161 files).
  • wastedassign: dead stores assigned but never read (25 sites). This surfaced a real missing error check in routing/router_test.go, where err from New() was never asserted.
  • bodyclose: unclosed HTTP response bodies (0 existing issues).
  • rowserrcheck: unchecked sql.Rows.Err() (0 existing issues).
  • sqlclosecheck: unclosed sql.Rows / sql.Stmt (0 existing issues).

Linters left disabled, now with accurate comments instead of the wrong "deprecated" label:

  • contextcheck: requires threading context.Context through many existing signatures, including test harnesses.
  • tparallel: requires adding t.Parallel() to many existing subtests, which can surface shared-state races.
  • unparam: sizeable backlog of unused parameters to clean up first.
  • nilerr: too noisy here; nearly all reports are intentional documented error-swallowing or false positives.
  • noctx: only flags a couple of interface methods and a test helper with no context to thread through.

#10858 (comment)

@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request modernizes the codebase by leveraging the per-iteration loop variable scoping introduced in Go 1.22. By enabling the copyloopvar linter, we ensure that redundant variable shadowing is caught automatically, and we have proactively cleaned up existing instances throughout the project to maintain cleaner, more idiomatic code.

Highlights

  • Linter Configuration: Enabled the copyloopvar linter in .golangci.yml to enforce modern Go loop variable scoping practices.
  • Code Cleanup: Removed redundant loop variable copies (e.g., test := test) across the entire codebase, as they are no longer necessary since Go 1.22.
New Features

🧠 You can now enable Memory (public preview) to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@github-actions github-actions Bot added the severity-critical Requires expert review - security/consensus critical label Jun 3, 2026
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 3, 2026

🔴 PR Severity: CRITICAL

Path-based classification | 16 non-test files | 41 lines changed

🔴 Critical (10 files)
  • `lnwallet/channel.go` - wallet/channel operations (lnwallet/*)
  • `lnwallet/btcwallet/btcwallet.go` - wallet operations (lnwallet/*)
  • `contractcourt/channel_arbitrator.go` - on-chain dispute resolution (contractcourt/*)
  • `contractcourt/breach_arbitrator.go` - breach handling (contractcourt/*)
  • `contractcourt/briefcase.go` - on-chain state (contractcourt/*)
  • `contractcourt/chain_arbitrator.go` - chain arbitration (contractcourt/*)
  • `contractcourt/taproot_briefcase.go` - taproot on-chain state (contractcourt/*)
  • `channeldb/height_hint.go` - channel state persistence (channeldb/*)
  • `channeldb/invoices.go` - channel state persistence (channeldb/*)
  • `funding/batch.go` - channel funding workflow (funding/*)
🟠 High (5 files)
  • `chainntnfs/mempool.go` - chain notifications (chainntnfs/*)
  • `discovery/gossiper.go` - gossip protocol (discovery/*)
  • `invoices/invoiceregistry.go` - invoice management (invoices/*)
  • `lnrpc/devrpc/dev_server.go` - RPC server (lnrpc/*)
  • `lnrpc/walletrpc/walletkit_server.go` - RPC server (lnrpc/*)
🟢 Low (1 file)
  • `.golangci.yml` - CI/linter configuration

Analysis

This PR enables the `copyloopvar` linter and removes redundant loop variable shadow copies (e.g., `x := x`) that were needed before Go 1.22 but are now unnecessary since loop variables are scoped per-iteration. The change is purely mechanical — no logic is altered, only boilerplate removed.

Despite the low-risk nature of the change, the severity is CRITICAL because the highest-severity files touched include core packages such as `lnwallet/`, `contractcourt/`, `channeldb/`, and `funding/`. Per classification rules, the highest-severity file determines the PR severity.

No severity bump was applied: 16 non-test/non-generated files (< 20 threshold) and 41 lines changed (< 500 threshold).


To override, add a `severity-override-{critical,high,medium,low}` label.
<!-- pr-severity-bot -->

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request removes obsolete loop variable rebindings across numerous test and production files, aligning with Go's modern loop semantics, and disables the copyloopvar linter. The review feedback correctly identifies several obsolete comments explaining the removed rebinding logic that should be cleaned up to maintain code clarity.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

I am having trouble creating individual review comments. Click here to see my feedback.

invoices/invoiceregistry.go (512)

medium

Since the loop variable rebinding (addEvent := addEvent) has been removed, the comment explaining why the variable is being rebound is now obsolete and should be removed to keep the codebase clean and accurate.

References
  1. Comments must explain the intention and context of the code accurately. Obsolete comments explaining removed logic should be cleaned up. (link)

invoices/invoiceregistry.go (526)

medium

Since the loop variable rebinding (settleEvent := settleEvent) has been removed, the comment explaining why the variable is being rebound is now obsolete and should be removed.

References
  1. Comments must explain the intention and context of the code accurately. Obsolete comments explaining removed logic should be cleaned up. (link)

lnrpc/walletrpc/walletkit_server_test.go (46-47)

medium

Since the loop variable redeclarations have been removed, the comment explaining why they are being redeclared is now obsolete and should be removed.

References
  1. Comments must explain the intention and context of the code accurately. Obsolete comments explaining removed logic should be cleaned up. (link)

@ziggie1984
Copy link
Copy Markdown
Collaborator

ziggie1984 commented Jun 3, 2026

maybe check all the switched off linters maybe we can reactivate more ?

@ziggie1984
Copy link
Copy Markdown
Collaborator

also could you separate test files and the other files in different commits ?

@erickcestari
Copy link
Copy Markdown
Collaborator Author

maybe check all the switched off linters maybe we can reactivate more ?

True, I'll check for others linters.

@erickcestari erickcestari force-pushed the enable-copyloopvar-linter branch from c82db41 to 0f9c709 Compare June 3, 2026 18:32
Since Go 1.22 loop variables are scoped per-iteration, so the
`x := x` / `a, b := a, b` copies inside range/for loops are no longer
needed. This removes the existing redundant copies in test files.
…test files

Since Go 1.22 loop variables are scoped per-iteration, so the
`x := x` / `a, b := a, b` copies inside range/for loops are no longer
needed. This enables the `copyloopvar` linter so these are caught
automatically and removes the existing redundant copies in non-test
files.
@erickcestari erickcestari force-pushed the enable-copyloopvar-linter branch from 0f9c709 to 90fbe48 Compare June 3, 2026 18:32
@github-actions github-actions Bot added severity-critical Requires expert review - security/consensus critical and removed severity-critical Requires expert review - security/consensus critical labels Jun 3, 2026
@erickcestari erickcestari changed the title lint: enable copyloopvar and remove redundant loop var copies lint: reactivate several disabled linters Jun 3, 2026
@erickcestari
Copy link
Copy Markdown
Collaborator Author

Done @ziggie1984

@erickcestari erickcestari force-pushed the enable-copyloopvar-linter branch from 90fbe48 to 3f677e6 Compare June 3, 2026 19:46
@github-actions github-actions Bot added severity-critical Requires expert review - security/consensus critical and removed severity-critical Requires expert review - security/consensus critical labels Jun 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no-changelog severity-critical Requires expert review - security/consensus critical

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants