- #6641
-
#6641
Replies: 2 comments
|
The usage of the discussion template is not optional. |
0 replies
|
Oh, I'm a 🐢 |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Proposal
I would like to propose adding
blankassignas a built-in golangci-lint linter.Repository: https://github.com/skosovsky/blankassign
License: MIT
Current tag:
v0.1.0Analyzer type:
go/analysis.AnalyzerLinter name:
blankassignConfiguration:
linters.settings.blankassign.ignoregolangci-lint v2 support: module plugin support already exists
Motivation
blankassignis intended to catch a small but increasingly common cleanup failure mode: values are explicitly assigned to_only to silence the compiler instead of being handled, removed, or wired into the real logic.This pattern is easy to introduce during iterative development, especially when code is generated, refactored, or modified by coding agents. An agent may resolve an “unused variable” compiler error by adding
_ = value, or leave a temporary stub behind while making a larger change. The code then compiles, but the underlying issue is hidden.These assignments are hard to find in review because they look syntactically harmless and are often surrounded by otherwise valid changes. In practice, they usually mean one of three things:
blankassignmakes this intent explicit by reporting only direct single blank assignments such as_ = ctx,_ = result, or_ = compute(). It intentionally avoids idiomatic Go uses of the blank identifier, such as_, ok :=,_, err :=,range, blank imports, and interface assertions.What it reports
Example diagnostics:
What it does not report
Why existing linters do not fully cover this
This is adjacent to existing linters, but the policy is different:
errcheckhandles unchecked errors;dogsledhandles too many blank identifiers in assignments;ineffassignandwastedassignhandle ineffective assignments;unusedhandles unused declarations.blankassignfocuses only on explicit single_ = valueassignments that are commonly used as silencing stubs.False-positive policy
The rule is intentionally narrow:
ast.AssignStmt;token.ASSIGN;len(Lhs) == 1;Lhs[0] == "_".The optional
ignoresetting suppresses diagnostics only when the RHS is a simple identifier with a matching name.Open compliance notes
I am aware of the new-linter checklist and would clean up any repository-level requirements before opening a PR if maintainers are interested. Two known points:
go 1.24.0; I can release av0.1.1tag withgo 1.22.0before the PR if required;init()for plugin registration. If the checklist requirement “must not contain init()” applies repository-wide rather than only to the analyzer package imported by golangci-lint, I can split or remove that adapter before submitting the PR.Would you be open to accepting
blankassignas a built-in golangci-lint linter if I prepare a PR with integration tests and configuration support?All reactions