Skip to content

fix(linters): unwrap parenthesized callees and labeled range loops - #77043

Merged
pelikhan merged 2 commits into
mainfrom
sergo/paren-label-linters-r126-4cb58455d095f7c6
Nov 12, 2026
Merged

pelikhan merged 2 commits into
mainfrom
sergo/paren-label-linters-r126-4cb58455d095f7c6

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

Summary

Closes the last unchecked call.Fun sites from the parenthesized-callee audit (R123–R125) and fixes a labeled-loop gap in slicemakezerolength.

Evidence

Linter Location Gap
goroutineresourceleak goroutine_loop.go hasWaitGroupMethod, waitGroupMethodKeys call.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.
bytesbufferstring matchBufBytesArg inner.Fun.(*ast.SelectorExpr) was unchecked, so string((buf.Bytes)()) was missed.
slicemakezerolength analyzeBlock stmt.(*ast.RangeStmt) skipped outer: for range ..., and appendsOneElement did not unwrap (append)(...) even though the make callee was already unwrapped.

Changes

  • Use astutil.UnwrapParenExpr on the callee at the three sites above.
  • Add a local unlabeledStmt helper in slicemakezerolength (same shape as the one in bufioscannererunchecked).
  • Fixtures added: goroutineInLoopWithParenWaitGroup, BadParenBytesCallee (source + golden), badLabeledRange, badParenAppendCallee.

Validation

  • Serena (gopls) diagnostics: no errors on the three changed source files or the new slicemakezerolength fixture.
  • Not run: go test, gofmt and make are 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.
  • Edits keep the surrounding tab formatting, but make fmt was not run either.

Notes

  • badLabeledRange uses a trailing goto outer so the label is used and the fixture compiles.
  • Not in scope: appendoneelement / appendbytestring match append by name only (no universe-object check), so a shadowing local append could false-positive. Worth a follow-up.

🤖 Generated with [Claude Code]((claude.com/redacted)

Generated by 🤖 Sergo - Serena Go Expert · claude · routed: sonnet55 high · ~63 AIC · ⌖ ~2 AIC · ⊞ 4.7K · ◷

  • expires on Nov 18, 2026, 7:52 PM UTC-08:00

@github-actions github-actions Bot added cookie Issue Monster Loves Cookies! sergo labels Nov 12, 2026
@pelikhan
pelikhan marked this pull request as ready for review November 12, 2026 12:52
Copilot AI dynamic review requested due to automatic review settings November 12, 2026 12:52
@github-actions

github-actions Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor Author

✅ PR Code Quality Reviewer completed the code quality review.

🔎 Code quality review by PR Code Quality Reviewer

@github-actions

github-actions Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor Author

✅ PR Specification Reviewer completed successfully!

PR Specification Reviewer

Outcome: reported_no_action

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.

Generated from PR Specification Reviewer · gpt56 · ~2 AIC · ⌖ ~1 AIC · ⊞ 1.6K · ◷

Generated by PR Specification Reviewer for #77043

@github-actions

github-actions Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor Author

✅ Test Quality Sentinel completed test quality analysis.

Test Quality Sentinel

Outcome: reported_no_action

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.

Generated from Test Quality Sentinel · routed: haiku55 xhigh · ~2 AIC · ⌖ ~2 AIC · ⊞ 7.2K · ◷

🧪 Test quality analysis by Test Quality Sentinel

@github-actions

github-actions Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor Author

✅ Ponytail Reviewer completed successfully!

Generated by Ponytail Reviewer for #77043

@github-actions

github-actions Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor Author

✅ 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: reported_no_action

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.

Generated from Design Decision Gate 🏗️ · routed: haiku55 xhigh · ~1 AIC · ⌖ ~2 AIC · ⊞ 8.5K · ◷

🏗️ ADR gate enforced by Design Decision Gate 🏗️

@github-actions

github-actions Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor Author

🧠 Matt Pocock Skills Reviewer has completed the skills-based review. ✅

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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-in append.
  • 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)

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What this change does: It makes three linters recognize parenthesized calls and labeled range loops. The new fixtures cover those forms.

Should fix:

  1. 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 {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 test passes for bytesbufferstring, goroutineresourceleak, slicemakezerolength, and bufioscannererunchecked. The PR description says tests were not run, so this is new evidence.
  • go vet is clean on the three changed packages, and gofmt reports no diffs.
  • Regression check: with the UnwrapParenExpr and unlabeledStmt changes reverted in a temporary worktree, all three new fixtures fail (BadParenBytesCallee, goroutineInLoopWithParenWaitGroup, badLabeledRange and badParenAppendCallee). So each fixture reproduces the original gap.

Key Themes

  • Duplicated helper: unlabeledStmt now exists in two packages with the same body. See the inline comment on slicemakezerolength.go.
  • Negative coverage: the labeled-loop fixture only covers the positive case. See the inline comment on the testdata file.

Positive Highlights

  • ✅ Reusing astutil.UnwrapParenExpr rather 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 outer trick 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 {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[/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) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[/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.

@pelikhan
pelikhan merged commit 1b7036a into main Nov 12, 2026
139 checks passed
@pelikhan
pelikhan deleted the sergo/paren-label-linters-r126-4cb58455d095f7c6 branch November 12, 2026 13:18
@github-actions

Copy link
Copy Markdown
Contributor Author

🎉 This pull request is included in a new release.

Release: v1.2.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cookie Issue Monster Loves Cookies! sergo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants