Repository navigation
fix(linters): unwrap parentheses in bufferresetbeforereuse and panic-in-library-code - #76740
Conversation
|
✅ 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.
|
|
✅ 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.
|
|
✅ PR Code Quality Reviewer completed the code quality review.
|
|
🧠 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.
|
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are reported for the parenthesis-handling updates to the buffer reuse and library panic linters.
No open issues 🎉
What changed in this PR
Continues the parenthesis-handling fixes in gh-aw’s custom Go linters, making buffer reuse checks and library panic checks recognize equivalent parenthesized expressions.
Changes:
- Unwrap buffer method callees and receivers so parentheses do not hide reuse or resets.
- Recognize parenthesized panic calls while preserving
BUG:andsync.Onceexemptions. - Add regression fixtures for both linters.
| File | Description |
|---|---|
pkg/linters/panic-in-library-code/testdata/src/panicinlibrarycode/panicinlibrarycode.go |
Adds parenthesized panic and exemption fixtures. |
pkg/linters/panic-in-library-code/panic-in-library-code.go |
Unwraps callees and parenthesized string-prefix expressions. |
pkg/linters/bufferresetbeforereuse/testdata/src/a/a.go |
Adds parenthesized reuse and reset fixtures. |
pkg/linters/bufferresetbeforereuse/bufferresetbeforereuse.go |
Unwraps method callees and buffer receivers before matching. |
Review effort: Balanced (auto)
There was a problem hiding this comment.
Review complete: no actionable correctness, performance, or security issues found in the changed lines. The specialist pass completed; its findings were non-actionable (validation advice and test-coverage suggestions rather than defects).
🔎 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 /tdd and /diagnosing-bugs. The fix is correct for the forms it targets, and the regression fixtures fail on the pre-fix source. One narrow false positive remains, noted inline.
📋 Key Themes & Highlights
Validation I ran
go testpasses for bothbufferresetbeforereuseandpanic-in-library-code. The PR says these could not be run locally, so CI is not the only signal.- With the source hunks reverted and the new fixtures kept, both suites fail. The new fixtures are real regression tests.
gofmt -lreports no issues.
Positive Highlights
- ✅ Using
astutil.UnwrapParenExprmatches the existing pattern intimenowsub,lenstringsplit, andmanualpathconcat. - ✅ The
/tddfixtures cover the parenthesized callee, receiver,Sprintf, andBUG:concatenation forms.
Remaining gap
⚠️ (once.Do)((func(){...}))is still flagged. The parenthesized closure argument hides the sync.Once exemption. See the inline comment for a tested fix and fixture. This is a narrow edge case and can land as a follow-up.
@copilot please address the inline comment.
🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · copilot · routed: haiku55 xhigh · ~5 AIC · ⌖ ~2 AIC · ⊞ 6.6K
Comment /matt to run again
|
|
||
| // ok: parenthesized sync.Once.Do callee. | ||
| func parenthesizedOnceDo() { | ||
| (once.Do)(func() { |
There was a problem hiding this comment.
[/tdd] A parenthesized closure argument is still flagged: (once.Do)((func() {...})) produces a false positive. isInSyncOnceFuncLit only checks the direct parent of the FuncLit, and callArgsContainExpr compares arguments by identity, so the wrapping ParenExpr hides the sync.Once exemption. The linter flags the closure body in a temporary reproduction.
💡 Suggested fix and regression fixture
In pkg/linters/panic-in-library-code/panic-in-library-code.go (outside this diff's hunks), in isInSyncOnceFuncLit and callArgsContainExpr:
parent := encl.Parent()
for {
if _, isParen := parent.Node().(*ast.ParenExpr); !isParen {
break
}
parent = parent.Parent()
}
call, ok := parent.Node().(*ast.CallExpr)func callArgsContainExpr(args []ast.Expr, target ast.Expr) bool {
return slices.ContainsFunc(args, func(arg ast.Expr) bool {
return astutil.UnwrapParenExpr(arg) == target
})
}Add this fixture after parenthesizedOnceDo:
// ok: parenthesized closure argument to sync.Once.Do.
func parenthesizedOnceDoClosureArg() {
(once.Do)((func() {
panic("lazy init failure") // should not be flagged
}))
}I ran both suites with this change and they pass. The existing fixtures do not cover this form.
@copilot please address this.
|
🍳 A little prep to help this PR along! Copilot assignment requested for the following outstanding work:
Keeping the changes focused; human review and CI get the final taste test. No merging or CI triggering. Structured data{
"completed_task": 0,
"head": "704db5800c778b7cdc5e1382d885a7703af9cafd",
"kind": "requested",
"schema_version": "1",
"state": "cc2ca635f1f700e415b8109eef636ca4b9df1a8d924889cb8edec04a979490f6",
"work": [
"4ce4dd407e604d374ecd66edfd2afc18c54e2d0b3733dbac37ac8e9c8834fdba"
],
"workflow": "pr-sous-chef"
}
|
…ffer-panic-r125-f869a6d0a27e607b Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>
Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>
Merged the latest |
|
🎉 This pull request is included in a new release. Release: |
Sergo R125 follow-up to the paren-unwrap series (#75599, #75816, #76123).
Evidence
bufferresetbeforereuse.appendCallEventrequiredcall.Funto be a bare*ast.SelectorExprandsel.Xa bare*ast.Ident.(buf).Reset()and(buf.WriteString)(x)produced no events, so a parenthesized Reset was ignored and parenthesized reuse was missed.panic-in-library-codemissed several parenthesized forms: the(panic)(x)callee,(fmt.Sprintf)("BUG: ..."),(once.Do)(func(){...})andpanic(("BUG: " + x)). TheBUG:and sync.Once exemptions failed, and the callee check was a literal*ast.Identmatch.Change
Use
astutil.UnwrapParenExpron the callee/receiver inappendCallEvent,analyzePanicCalls,isFmtSprintfandselectorExprFromCallFun, and add a*ast.ParenExprcase toextractConstantStringPrefix. New fixtures cover each form.Validation
serena get_diagnostics_for_fileon both changed source files returned no errors or warnings.go testandmake fmtcould NOT be run in this sandbox (Bashgois denied), so the analysistest suites have not been executed locally. Please rely on CI for them.🤖 Generated with [Claude Code]((claude.com/redacted)