Skip to content
Latchkey

Go staticcheck / golangci-lint failures - Fix in CI

staticcheck and golangci-lint gate CI on lint findings. A failure is either a genuine issue in the code or drift between the linter version/config used locally and in CI.

What this error means

A lint step fails listing findings like SA4006: value never used or errcheck: error return not checked, or it errors loading config. Local runs may pass when a different linter version or .golangci.yml is in effect.

go
pkg/handler.go:42:2: SA4006: this value of err is never used (staticcheck)
pkg/store.go:18:9: Error return value is not checked (errcheck)

Diagnose it: toolchain, tags, or platform?

Go build failures that only appear in CI usually come from a different toolchain version, different build tags, or cross-compilation defaults that differ from your machine.

Terminal
go version
go env GOOS GOARCH CGO_ENABLED GOFLAGS GOTOOLCHAIN

# build exactly what CI builds, verbosely
go build -v ./... 2>&1 | tail -40

# CGO is the usual difference: on by default locally, often off in a slim CI image
CGO_ENABLED=0 go build ./...

Common causes

Genuine lint findings

The linter caught real issues - unused values, unchecked errors, or shadowed variables.

Linter version or config drift

CI runs a different linter version or .golangci.yml than local, so the rule set differs.

How to fix it

Fix the findings

  1. Address each reported issue, then re-run the linter to confirm a clean pass.
Terminal
golangci-lint run ./...

Pin the linter version in CI

  1. Pin a fixed golangci-lint version so local and CI use the same rule set.
.github/workflows/ci.yml
- uses: golangci/golangci-lint-action@v6
  with:
    version: v1.59.1

How to prevent it

  • Pin the linter version in CI and document it for local use.
  • Commit a single .golangci.yml as the source of truth.
  • Run the linter locally before pushing.

Frequently asked questions

What causes Go staticcheck / golangci-lint failures?
There are 2 common causes: genuine lint findings and linter version or config drift. The linter caught real issues - unused values, unchecked errors, or shadowed variables.
How do I fix Go staticcheck / golangci-lint failures?
There are 2 fixes depending on which cause you have: fix the findings and pin the linter version in ci. Work through them in order, since the first is the most common.
What does Go staticcheck / golangci-lint failures actually mean?
A lint step fails listing findings like SA4006: value never used or errcheck: error return not checked, or it errors loading config.
How do I stop Go staticcheck / golangci-lint failures happening again?
Pin the linter version in CI and document it for local use. The prevention section lists 3 changes that keep it from recurring.

Related guides

References

Not every red build is your code. Latchkey repairs the ones that are not, on the runner. Start free → 30-day trial · No credit card