Repository navigation
fix(linters): unwrap parenthesized callees and labeled range loops - #77043
Conversation
|
✅ PR Code Quality Reviewer completed the code quality review.
|
|
✅ 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.
|
|
✅ 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.
|
|
✅ Ponytail Reviewer completed successfully!
|
|
✅ 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.
|
|
🧠 Matt Pocock Skills Reviewer has completed the skills-based review. ✅
|
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are recorded for the linter syntax-handling changes.
No open issues 🎉
What changed in this PR
This PR improves three custom Go linters in gh-aw by recognizing equivalent syntax that previously caused missed diagnostics or false positives.
Changes:
- Unwrap parenthesized callees when matching WaitGroup methods,
bytes.Buffer.Bytes, and built-inappend. - Analyze labeled range loops in
slicemakezerolength. - Add regression fixtures and update expected autofix output.
| File | Description |
|---|---|
pkg/linters/slicemakezerolength/testdata/src/slicemakezerolength/slicemakezerolength.go |
Adds labeled-range and parenthesized-append fixtures. |
pkg/linters/slicemakezerolength/slicemakezerolength.go |
Unwraps labels and parenthesized append callees. |
pkg/linters/goroutineresourceleak/testdata/src/a/a.go |
Adds parenthesized WaitGroup synchronization coverage. |
pkg/linters/goroutineresourceleak/goroutine_loop.go |
Recognizes parenthesized WaitGroup method calls. |
pkg/linters/bytesbufferstring/testdata/src/bytesbufferstring/bytesbufferstring.go.golden |
Records expected autofix for a parenthesized Bytes callee. |
pkg/linters/bytesbufferstring/testdata/src/bytesbufferstring/bytesbufferstring.go |
Adds a parenthesized Bytes callee fixture. |
pkg/linters/bytesbufferstring/bytesbufferstring.go |
Unwraps parentheses when matching the Bytes callee. |
Review effort: Balanced (auto)
There was a problem hiding this comment.
What this change does: It makes three linters recognize parenthesized calls and labeled range loops. The new fixtures cover those forms.
Should fix:
- The new label-unwrapping helper duplicates the scanner linter helper. Sharing it in the existing AST utilities removes one copy and keeps both linters using the same handling.
Verdict: Ship.
Lean: -12 lines possible.
Generated by ✂️ Ponytail Reviewer for #77043 · codex · routed: gpt61 medium · ~5 AIC · ⌖ ~1 AIC · ⊞ 181
Comment /ponytail to run again
|
|
||
| // unlabeledStmt strips any labels (e.g. "outer:") from stmt so that labeled | ||
| // range loops are analyzed the same way as unlabeled ones. | ||
| func unlabeledStmt(stmt ast.Stmt) ast.Stmt { |
There was a problem hiding this comment.
Should fix: This label-unwrapping helper duplicates unlabeledStmt in pkg/linters/bufioscannererunchecked/bufioscannererunchecked.go; move one copy to pkg/linters/internal/astutil and use it in both linters, so the same label handling only needs to be maintained once.
There was a problem hiding this comment.
Reviewed the changed linter logic and fixtures, including parenthesized callees and labeled range loops. I found no actionable correctness, regression, or maintainability issues in the changed lines. The specialist pass completed; validation was not run in this review environment.
🔎 Code quality review by PR Code Quality Reviewer · copilot · gpt50 · ~3 AIC · ⌖ ~1 AIC · ⊞ 1.6K
Comment /review to run again
There was a problem hiding this comment.
Skills-Based Review 🧠
Applied /diagnosing-bugs and /tdd. The fix is correct and verified. No blocking issues.
📋 Verification & Key Themes
Verification (run locally, not just reviewed)
go testpasses forbytesbufferstring,goroutineresourceleak,slicemakezerolength, andbufioscannererunchecked. The PR description says tests were not run, so this is new evidence.go vetis clean on the three changed packages, and gofmt reports no diffs.- Regression check: with the
UnwrapParenExprandunlabeledStmtchanges reverted in a temporary worktree, all three new fixtures fail (BadParenBytesCallee,goroutineInLoopWithParenWaitGroup,badLabeledRangeandbadParenAppendCallee). So each fixture reproduces the original gap.
Key Themes
- Duplicated helper:
unlabeledStmtnow exists in two packages with the same body. See the inline comment onslicemakezerolength.go. - Negative coverage: the labeled-loop fixture only covers the positive case. See the inline comment on the testdata file.
Positive Highlights
- ✅ Reusing
astutil.UnwrapParenExprrather than hand-rolling unwrap logic keeps the three linters consistent. - ✅ Each fix ships with a fixture that fails before the change, which is the right regression shape for
/diagnosing-bugs. - ✅ The
goto outertrick to keep the label used is a clear, documented workaround.
Scope note
The PR says it closes the last unchecked call.Fun sites, but several other linters still assert call.Fun.(*ast.Ident) directly (for example appendoneelement, appendbytestring, mapdeletecheck). These are outside this PR, so I did not flag them. Worth confirming the audit scope.
@copilot please address the review comments above.
🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · copilot · routed: haiku55 xhigh · ~6 AIC · ⌖ ~2 AIC · ⊞ 6.6K
Comment /matt to run again
|
|
||
| // unlabeledStmt strips any labels (e.g. "outer:") from stmt so that labeled | ||
| // range loops are analyzed the same way as unlabeled ones. | ||
| func unlabeledStmt(stmt ast.Stmt) ast.Stmt { |
There was a problem hiding this comment.
[/codebase-design] unlabeledStmt is now a copy of the helper in bufioscannererunchecked (same body, different package). Two copies of label-stripping logic will drift apart. Consider moving it into pkg/linters/internal/astutil next to UnwrapParenExpr and calling it from both linters.
💡 Suggested change
Add an exported helper such as UnwrapLabeledStmt(stmt ast.Stmt) ast.Stmt to astutil.go with this body, delete both local copies, and call the shared helper at the range check. A small unit test in astutil_test.go can cover it.
@copilot please address this.
| _ = s | ||
| } | ||
|
|
||
| func badLabeledRange(items []string) { |
There was a problem hiding this comment.
[/tdd] The labeled-loop fixture only covers the positive case. Add a labeled negative case that must not be reported, for example an outer: range loop whose body appends two elements or whose range expression references the slice being built. This guards the label-stripping path against over-matching, not just against missed matches.
💡 Suggested test
A labeled loop with a body that fails appendsOneElement should produce no diagnostic. Put it next to badLabeledRange with no want comment.
@copilot please address this.
|
🎉 This pull request is included in a new release. Release: |
Summary
Closes the last unchecked
call.Funsites from the parenthesized-callee audit (R123–R125) and fixes a labeled-loop gap inslicemakezerolength.Evidence
goroutineresourceleakgoroutine_loop.gohasWaitGroupMethod,waitGroupMethodKeyscall.Fun.(*ast.SelectorExpr)without paren unwrap, so(wg.Add)(1)/(wg.Wait)()were not seen as WaitGroup synchronization and the loop was reported as a leak.bytesbufferstringmatchBufBytesArginner.Fun.(*ast.SelectorExpr)was unchecked, sostring((buf.Bytes)())was missed.slicemakezerolengthanalyzeBlockstmt.(*ast.RangeStmt)skippedouter: for range ..., andappendsOneElementdid not unwrap(append)(...)even though themakecallee was already unwrapped.Changes
astutil.UnwrapParenExpron the callee at the three sites above.unlabeledStmthelper inslicemakezerolength(same shape as the one inbufioscannererunchecked).goroutineInLoopWithParenWaitGroup,BadParenBytesCallee(source + golden),badLabeledRange,badParenAppendCallee.Validation
slicemakezerolengthfixture.go test,gofmtandmakeare denied in this agent environment, so the analysistest fixtures and golden file were written by hand and have not been executed. Please rely on CI (go test ./pkg/linters/...) to confirm.make fmtwas not run either.Notes
badLabeledRangeuses a trailinggoto outerso the label is used and the fixture compiles.appendoneelement/appendbytestringmatchappendby name only (no universe-object check), so a shadowing localappendcould false-positive. Worth a follow-up.🤖 Generated with [Claude Code]((claude.com/redacted)