Skip to content

Enable govet and additional correctness linters in golangci-lint - #1631

Open
randomizedcoder wants to merge 2 commits into
prometheus:masterfrom
randomizedcoder:ci-static-analysis
Open

Enable govet and additional correctness linters in golangci-lint#1631
randomizedcoder wants to merge 2 commits into
prometheus:masterfrom
randomizedcoder:ci-static-analysis

Conversation

@randomizedcoder

Copy link
Copy Markdown
Contributor

Follow-up to #1624. As noted there — "I think I will followup with some
additional linters in our golangci-lint config" — here is a proposed set.

Why

The config runs only misspell, revive, sloglint and staticcheck.
govet is not enabled, and go test's built-in vet subset skips the
composites and unreachable analyzers — which is exactly why the findings
fixed in #1624 were not caught by CI. (Verified: reintroducing those issues
makes this config flag both unreachable and composites.)

What

Enable govet (with the composites analyzer) plus a curated, low-noise
correctness set: copyloopvar, durationcheck, ineffassign, makezero,
unconvert, wastedassign. The wastedassign (main) and unconvert
(http_test) findings these surface are fixed in the first commit.

go build, go test ./..., and golangci-lint run (pinned v2.11.4) all pass.

Happy to trim/extend the set to your preference. A follow-up will add nilerr
(it depends on a separate dropped-error fix, #1629).

🤖 Generated with Claude Code

randomizedcoder and others added 2 commits July 20, 2026 09:16
Flagged by the linters enabled in the following commit:
- main: drop a wasted new(prober.Result) allocation that is overwritten in
  both branches of the following if/else (wastedassign).
- prober/http_test: remove unnecessary []byte(msg) conversions, msg is
  already a []byte (unconvert).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Signed-off-by: randomizedcoder <dave.seddon.ca@gmail.com>
Follow-up to prometheus#1624. The config ran only misspell, revive, sloglint and
staticcheck. govet was not enabled, and go test's built-in vet subset skips
the composites and unreachable analyzers — which is why prometheus#1624's findings
were not caught by CI (verified: reintroducing them makes this config flag
both unreachable and composites).

Enable govet (with the composites analyzer) plus a curated, low-noise
correctness set: copyloopvar, durationcheck, ineffassign, makezero,
unconvert and wastedassign. The unconvert/wastedassign findings are fixed in
the preceding commit.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Signed-off-by: randomizedcoder <dave.seddon.ca@gmail.com>

@SuperQ SuperQ left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm not a fan of enabling linters for the sake of enabling them. Especially if an LLM just does it with no thought or reasoning behind it.

@randomizedcoder

Copy link
Copy Markdown
Contributor Author

@SuperQ

Nobody wants false positives

In this case, it seems like they are not false positives

#1626
#1629

Please correct me if I'm mistaken

@randomizedcoder

Copy link
Copy Markdown
Contributor Author

@SuperQ

Sorry - I want to apologize

With this PR. I was hoping to help contribute, and so this PR goes to an extreme from the static analysis

We definitely don't need to go this far and it's just a suggestion

Happy to adjust the level up/down based on feedback

SuperQ pushed a commit to prometheus/exporter-toolkit that referenced this pull request Jul 23, 2026
* web: avoid aliasing cert.DNSNames when building the SAN list

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>

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

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>

---------

Signed-off-by: randomizedcoder dave.seddon.ca@gmail.com <dave.seddon.ca@gmail.com>
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.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.

2 participants