Repository navigation
fix(linters): unwrap parenthesized callees in sprintfbool, fprintlnsprintf, writebytestring, closeerrorunchecked - #75294
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.
|
|
❌ Design Decision Gate 🏗️ failed to deliver outputs during design decision gate check.
|
|
✅ PR Code Quality Reviewer completed the code quality review.
|
|
✅ Ponytail Reviewer completed successfully!
|
|
🧠 Matt Pocock Skills Reviewer has completed the skills-based 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.
|
|
Warning The 🏗️ Design Decision Gate — ADR RequiredThis PR adds more than 100 new lines under 📄 Draft ADR committed:
Decision captured in the draft: linter matchers in 📋 What to do next
Once the PR body links an ADR, this gate re-runs and checks that the implementation matches the decision. ❓ Why ADRs Matter
ADRs keep a searchable, permanent record of why the codebase looks the way it does. 📋 Michael Nygard ADR Format ReferenceAn ADR needs these four sections to count as complete:
ADRs live in
|
There was a problem hiding this comment.
What this change does: The PR extends four linters to recognize parenthesized callees and arguments, with focused regression fixtures. The fprintlnsprintf fix also expands its edit ranges so wrapped Sprintf calls remain fixable.
Nice to have:
-
printedArgduplicatescall.Args[1](pkg/linters/fprintlnsprintf/fprintlnsprintf.go:80)- What this is:
buildFprintfFixalready receivescall, and its only caller passescall.Args[1]verbatim. - Problem: The extra parameter and its explanation add a second AST value that must stay paired with the outer call.
- Fix: Remove
printedArgand usecall.Args[1].Pos()and.End()for the two range endpoints. - If we skip it: This private helper keeps needless plumbing and a future caller could pass mismatched nodes.
- What this is:
Verdict: Ship.
Not checked: Tests were not run; this review was limited to changed-line complexity.
Lean: -3 lines possible.
Generated by ✂️ Ponytail Reviewer for #75294 · codex · routed: gpt56 max · ~3 AIC · ⌖ ~1 AIC · ⊞ 118
Comment /ponytail to run again
| // printedArg is the Fprintln argument as written; it differs from sprintfCall | ||
| // when the Sprintf call is parenthesized, in which case the surrounding parens | ||
| // are deleted together with "fmt.Sprintf(" and its closing ")". | ||
| func buildFprintfFix(pass *analysis.Pass, call *ast.CallExpr, printedArg ast.Expr, sprintfCall *ast.CallExpr) []analysis.SuggestedFix { |
There was a problem hiding this comment.
What this is: buildFprintfFix already receives call, and its only caller passes call.Args[1] verbatim. Problem: printedArg duplicates that value and adds a second AST source to keep paired. Fix: Remove the parameter and use call.Args[1].Pos()/.End() for the two range endpoints. If we skip it: This private helper keeps needless plumbing and a future caller could pass mismatched nodes.
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues remain for the parenthesis-handling changes across the four Go analyzers.
No open issues 🎉
What changed in this PR
This PR continues the parenthesis-handling fixes in gh-aw’s Go linters, allowing four more analyzers to recognize equivalent parenthesized expressions.
Changes:
- Unwrap parenthesized callees in
sprintfbool,fprintlnsprintf,writebytestring, andcloseerrorunchecked. - Extend format-literal handling and adjust
fprintlnsprintffix ranges to remove parentheses around nested calls. - Add regression fixtures and expected suggested-fix outputs.
| File | Description |
|---|---|
pkg/linters/writebytestring/writebytestring.go |
Recognizes parenthesized Write callees. |
pkg/linters/writebytestring/testdata/src/writebytestring/paren_callee.go.golden |
Records the expected io.WriteString replacement. |
pkg/linters/writebytestring/testdata/src/writebytestring/paren_callee.go |
Adds a parenthesized Write regression case. |
pkg/linters/sprintfbool/testdata/src/sprintfbool/paren.go.golden |
Records strconv.FormatBool replacements and import cleanup. |
pkg/linters/sprintfbool/testdata/src/sprintfbool/paren.go |
Covers parenthesized callees and format literals. |
pkg/linters/sprintfbool/sprintfbool.go |
Unwraps callees and boolean format literals. |
pkg/linters/fprintlnsprintf/testdata/src/fprintlnsprintf/paren.go.golden |
Records Fprintf fixes for four parenthesized forms. |
pkg/linters/fprintlnsprintf/testdata/src/fprintlnsprintf/paren.go |
Adds four parenthesis-handling regression cases. |
pkg/linters/fprintlnsprintf/fprintlnsprintf.go |
Expands matching and adjusts nested-call deletion ranges. |
pkg/linters/closeerrorunchecked/testdata/src/closeerrorunchecked/closeerrorunchecked.go |
Adds discarded-error cases and a non-error negative case. |
pkg/linters/closeerrorunchecked/closeerrorunchecked.go |
Recognizes parenthesized Close callees. |
Review effort: Balanced (auto)
There was a problem hiding this comment.
Reviewed the changed linter matching and suggested-fix logic. No actionable correctness, security, or performance issues were found in the changed lines. The added parenthesized-call coverage is consistent with the AST unwrapping and edit ranges.
🔎 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. I found no actionable correctness or test-coverage issues in the changed lines.
Validation
- The four linters consistently unwrap parenthesized callees.
fprintlnsprintfexpands fix ranges to remove outer parentheses without changing existing unparenthesized fixes.- Fixtures cover detection, golden fixes, and a negative case.
- Targeted tests passed:
go test ./pkg/linters/fprintlnsprintf/ ./pkg/linters/sprintfbool/ ./pkg/linters/writebytestring/ ./pkg/linters/closeerrorunchecked/.
🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · copilot · routed: gpt56 max · ~7 AIC · ⌖ ~1 AIC · ⊞ 5.5K
Comment /matt to run again
|
Copilot assignment requested for the following outstanding work:
Once you start work, post this work summary as a PR comment without the leading Copilot mention, including the Sous-chef head, work, and state lines below, to record that the assignment is running. Apply the necessary fixes on this PR's existing branch, reply to each listed review thread and resolve it when addressed. Ignore feedback already answered or resolved; stop when only human review or CI remains. Do not merge or trigger CI. Sous-chef requested-head: c851045
|
Work summary: I’m refreshing this branch from Sous-chef requested-head: c851045 |
…t-write-close-r121-4365f5b0a88439eb Co-authored-by: gh-aw-bot <[email protected]>
Co-authored-by: gh-aw-bot <[email protected]>
|
🎉 This pull request is included in a new release. Release: |
Summary
Four linters matched their target call with a bare
call.Fun.(*ast.SelectorExpr)type assertion, so a parenthesized callee such as(fmt.Sprintf)("%t", b)was silently skipped. This continues theparen_unwrap_gapseries (#74277, #74382, #74737, #75085) with the next batch queued from the previous Sergo run.sprintfbool(fmt.Sprintf)("%t", b),fmt.Sprintf(("%t"), b)call.Funand the format literal (same assprintfint)fprintlnsprintf(fmt.Fprintln)(w, ...),(fmt.Sprintf)(...),fmt.Fprintln(w, (fmt.Sprintf(...))),fmt.Sprintf(("fmt"), ...)isFmtFunc, the printed argument, the format literal, andouterSelwritebytestring(buf.Write)([]byte(s))call.Funcloseerrorunchecked(f.Close)(),_ = (f.Close)()call.FuninisCloseMethodCallEvidence
Fprintln(Sprintf)forms in the new fixture. The repo linter missed them before this change..gocode using these parenthesized forms. Only test fixtures use them, so the CI-enforced linters won't report anything new on existing code.fprintlnsprintf fix correctness
The suggested fix deletes
fmt.Sprintf(and its closing). Applied unchanged tofmt.Fprintln(w, (fmt.Sprintf("x %s", n))), it would keep the outer parentheses and producefmt.Fprintf(w, ("x %s\n", n)), which doesn't compile.buildFprintfFixnow also gets the argument as written, and its delete ranges extend to that argument'sPos()/End(). In the unparenthesized case those positions are unchanged, so existing goldens are unaffected.Tests
New fixtures, with goldens where the linter has fixes:
sprintfbool/testdata/.../paren.go(.golden): parenthesized callee and format literal. Thefmtimport is orphaned and swapped forstrconv.fprintlnsprintf/testdata/.../paren.go(.golden): four forms, including the doubly-wrapped argument.writebytestring/testdata/.../paren_callee.go(.golden)closeerrorunchecked/testdata/.../closeerrorunchecked.go: two positive cases and a non-error(nc.Close)()negative.Validation
get_diagnostics_for_file(gopls via Serena) reports 0 diagnostics on all four changed source files.unusedfuncinfo and, for fprintlnsprintf, staticcheck S1038 warnings. The closeerrorunchecked fixture's only error is aBrokenImportof its GOPATH-style sibling package, which gopls can't resolve and analysistest can.find_referencing_symbolsconfirms thatbuildFprintfFixhas exactly one caller, which is updated.go testandgofmtwere denied by the sandbox in this run, soanalysistesthasn't run. Please let CI rungo test ./pkg/linters/sprintfbool/ ./pkg/linters/fprintlnsprintf/ ./pkg/linters/writebytestring/ ./pkg/linters/closeerrorunchecked/.🤖 Generated with [Claude Code]((claude.com/redacted)