You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add deadcode CI check and remove unreachable functions (#4974)
## Why
The CLI is not meant as a library and as such any function not reachable
from `main()` is dead code. The existing `unused` linter skips exported
functions by default (it assumes external consumers might use them),
leaving a gap. `deadcode` from `golang.org/x/tools` does whole-program
reachability analysis and catches these.
## Changes
Added `deadcode` as a CI check via `make checks`. A Python wrapper
script (`tools/check_deadcode.py`) runs `deadcode -test ./...` and
supports two suppression mechanisms:
1. **Directory exclusions** for directories where everything is a false
positive (e.g. `libs/gorules/`, which contains lint rule definitions
loaded by golangci-lint's ruleguard engine, not through Go's call
graph).
2. **Inline comments** (`//deadcode:allow <reason>`) above a function,
matching the `//nolint:` pattern. The wrapper walks backward from the
reported func line, stopping at a blank line, so the allow comment is
found whether it sits immediately above the function or above a
doc-comment block.
The wrapper is needed because raw `deadcode` has no suppression
mechanism. It reports every unreachable function with no way to exclude
known false positives (code loaded via reflection, plugin systems, or
code generators). Without the wrapper, the only options would be to
either accept noisy output that developers learn to ignore, or not run
the check at all. The wrapper keeps the check strict (zero tolerance, CI
fails on any finding) while giving developers two escape hatches for
legitimate exceptions.
Both mechanisms are documented in the script itself.
Removed 40 dead functions across 23 files found in the initial run.
Preserved `DisabledTestNoDuplicatedAnnotations` with `//deadcode:allow`
since the `Disabled` prefix was a deliberate "park for later" marker
from the original author.
## Test plan
- [x] `make deadcode` passes clean ("No dead code found.")
- [x] `make checks` passes (includes deadcode)
- [x] `make lintfull` passes (0 issues, no unused imports)
- [x] `go build ./...` passes
- [x] Unit tests pass for all affected packages
This pull request was AI-assisted by Isaac.
0 commit comments