Repository navigation
[sergo] linters: verify append/len resolve to the builtin (appendbytestring, lenstringzero) - #77329
Conversation
|
✅ Design Decision Gate 🏗️ completed the design decision gate check. See the comment below for the result and any generated ADR draft. Design Decision Gate 🏗️Outcome: The agent completed and reported no action. A no-op output alone does not verify that all required work was completed or that publication was possible. Agent messages are omitted from this comment. The category uses structured run status, not interpretation of agent prose.
|
|
✅ Test Quality Sentinel completed test quality analysis. Test Quality SentinelOutcome: The agent completed and reported no action. A no-op output alone does not verify that all required work was completed or that publication was possible. Agent messages are omitted from this comment. The category uses structured run status, not interpretation of agent prose.
|
|
✅ PR Specification Reviewer completed successfully! PR Specification ReviewerOutcome: The agent completed and reported no action. A no-op output alone does not verify that all required work was completed or that publication was possible. Agent messages are omitted from this comment. The category uses structured run status, not interpretation of agent prose.
|
|
🧠 Matt Pocock Skills Reviewer has completed the skills-based review. ✅
|
|
✅ Ponytail Reviewer completed successfully! Ponytail ReviewerOutcome: The agent completed and reported no action. A no-op output alone does not verify that all required work was completed or that publication was possible. Agent messages are omitted from this comment. The category uses structured run status, not interpretation of agent prose.
|
|
✅ PR Code Quality Reviewer completed the code quality review. PR Code Quality ReviewerOutcome: The agent completed and reported one or more actions. The no-op output is a completion signal, not a claim that no action was taken. Agent messages are omitted from this comment. The category uses structured run status, not interpretation of agent prose.
|
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are reported for the change addressing linter false positives caused by shadowed Go builtins.
No open issues 🎉
What changed in this PR
This PR fixes false positives in gh-aw’s appendbytestring and lenstringzero linters by verifying that calls resolve to Go builtins rather than shadowed functions. This prevents suggested fixes that change behavior or fail to compile.
Changes:
- Add builtin identity checks using
types.Universe.Lookup. - Apply the
lencheck to direct comparisons and alias tracking. - Add negative fixtures for locally shadowed
appendandlen.
| File | Description |
|---|---|
pkg/linters/lenstringzero/testdata/src/lenstringzero/shadowed_len.go |
Adds negative fixtures for direct and aliased shadowed len calls. |
pkg/linters/lenstringzero/lenstringzero.go |
Requires builtin identity when matching len calls. |
pkg/linters/appendbytestring/testdata/src/appendbytestring/shadowed_append.go |
Adds a negative fixture for shadowed append. |
pkg/linters/appendbytestring/appendbytestring.go |
Skips calls that do not resolve to builtin append. |
Review effort: Balanced (dynamic)
|
🎉 This pull request is included in a new release. Release: |
Summary
appendbytestringandlenstringzeroidentified the builtinsappend/lenby identifier name only. A locally shadowed or user-definedappend/lenwas treated as the builtin, so the linters reported false positives and attached suggested fixes that change semantics or do not compile.appendoneelementandslicemakezerolengthalready guard against this with atypes.Universe.Lookupcheck; these two did not.Evidence
pkg/linters/appendbytestring/appendbytestring.go:50-51matchedident.Name != "append"with no object check. Withappend := func(dst []byte, src ...byte) []byte {...},append(b, []byte(s)...)was flagged and "fixed" toappend(b, s...), which does not compile (string spread is only valid for the builtin).pkg/linters/lenstringzero/lenstringzero.go:221-228(isLenCall) matchedident.Name == "len"only. With a shadowedlen := func(x string) int,len(s) == 0was rewritten tos == "", changing behavior. The same helper feedslenStringArg, so the alias path (n := len(s); n == 0) was affected too.Name (==|!=) "append|len|make|delete|...") acrosspkg/showed the other sites already resolve throughtypes.Universeor*types.Builtin.Changes
appendbytestring: addpass.TypesInfo.ObjectOf(ident) != types.Universe.Lookup("append")guard.lenstringzero:isLenCallnow takespassand requires the identifier to resolve totypes.Universe.Lookup("len"); the three call sites are updated.appendbytestring/testdata/src/appendbytestring/shadowed_append.go,lenstringzero/testdata/src/lenstringzero/shadowed_len.go(direct and alias forms). They contain no// wantlines, so they assert no diagnostics.Validation
.gofiles: 0 errors (only pre-existing-style "unused function/parameter" hints on the fixtures).go testandgofmtwere NOT run: the sandbox deniedgo/gofmtBash commands in this run.analysistest.RunWithSuggestedFixesfor both packages should be run in CI. The edits are small and mirror the existingappendoneelementguard, and no existing fixture shadowsappend/len, so existing expectations should be unchanged.🤖 Generated with [Claude Code]((claude.com/redacted)