Skip to content

lint: enable govet (all) and a set of correctness linters#420

Open
randomizedcoder wants to merge 2 commits into
prometheus:masterfrom
randomizedcoder:lint-enable-correctness-linters
Open

lint: enable govet (all) and a set of correctness linters#420
randomizedcoder wants to merge 2 commits into
prometheus:masterfrom
randomizedcoder:lint-enable-correctness-linters

Conversation

@randomizedcoder

Copy link
Copy Markdown

Hi 👋 — over in blackbox_exporter we recently landed prometheus/blackbox_exporter#1631 to enable a few more linters, and it occurred to us the same low-noise additions might help here too, so we thought we would try to help by proposing them for exporter-toolkit as well.

Why

The current .golangci.yml runs misspell, modernize, revive (plus the golangci-lint v2 defaults). govet runs only its default analyzer subset, so a few correctness checks (composites, unreachable, copylocks, etc.) are not enforced in CI.

What

Enable govet with enable-all (minus fieldalignment, which is churn-heavy, and shadow, which is idiomatic and used throughout this codebase) plus a curated, low-noise correctness set: copyloopvar, durationcheck, gocritic, makezero, unconvert, wastedassign.

These surfaced exactly one finding — gocritic's appendAssign on append(cert.DNSNames, cert.EmailAddresses...) in VerifyPeerCertificate, where appending to cert.DNSNames can mutate its backing array. That is fixed in the first commit with slices.Concat; after it, golangci-lint run ./... is clean and go build / go test ./... pass.

No golangci-lint version bump is needed — every linter above is available in the pinned version (Makefile.common untouched).

Happy to trim or extend the set to your preference. As a follow-up we would also like to propose adding ReadHeaderTimeout to the http.Server in bootstrap/ (a Slowloris hardening, matching prometheus/blackbox_exporter#1626).

🤖 Generated with Claude Code

randomizedcoder and others added 2 commits July 20, 2026 14:17
gocritic's appendAssign check flags append(cert.DNSNames, cert.EmailAddresses...):
appending to cert.DNSNames mutates its backing array when it has spare
capacity, which could surprise a caller still holding the certificate.
slices.Concat always allocates a fresh slice, which is the intent here.
No functional change; slices is already imported.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Signed-off-by: randomizedcoder dave.seddon.ca@gmail.com <dave.seddon.ca@gmail.com>
Mirrors prometheus/blackbox_exporter#1631. Enables copyloopvar,
durationcheck, gocritic, makezero, unconvert, and wastedassign, plus
govet enable-all (minus fieldalignment and shadow, which are noisy /
idiomatic in this codebase). These are low-noise correctness checks;
after the preceding appendAssign fix there are no findings on the tree.

golangci-lint run ./... is clean, and go build / go test ./... pass.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Signed-off-by: randomizedcoder dave.seddon.ca@gmail.com <dave.seddon.ca@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant