Repository navigation
fix(linters): see through parentheses in tolowerequalfold and bufioscannererunchecked - #75816
Conversation
|
✅ Ponytail Reviewer completed successfully!
|
|
✅ PR Code Quality Reviewer completed the code quality review. Caution agentic threat detected DetailsPotential security threats were detected in the agent output. Detected threat types: prompt injection. Review the workflow run logs for details.
|
|
✅ 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. ✅
|
|
✅ Design Decision Gate 🏗️ completed the design decision gate check. See the comment below for the result and any generated ADR draft.
|
|
✅ 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.
|
There was a problem hiding this comment.
What this change does: It makes both analyzers recognize parentheses around scanner calls, receiver expressions, case-conversion calls, aliases, and labeled scanner loops. It adds fixtures for these forms and keeps the existing fix behavior.
Should fix:
-
Expression-only normalization is wrapped in an unnecessary ast.Node adapter (
pkg/linters/tolowerequalfold/tolowerequalfold.go:271-277)- What this is:
unwrapParenNodeaccepts anyast.Nodebefore delegating toastutil.UnwrapParenExpr. - Problem: Every caller of
caseConvFuncAndArgandcaseConvPkgName, plus their callers, supplies anast.Expr, so the type assertion and unchanged-non-expression branch cannot run. - Fix: Tighten the expression-only helpers to
ast.Exprand callastutil.UnwrapParenExprdirectly; this removes the adapter. - If we skip it: The linter keeps dead branching and an extra abstraction that future changes must maintain.
- What this is:
Not checked: I did not run tests because this review is limited to unnecessary complexity.
Verdict: fix 1 first.
Lean: -8 lines possible.
Generated by ✂️ Ponytail Reviewer for #75816 · codex · routed: gpt56 max · ~4 AIC · ⌖ ~1 AIC · ⊞ 118
Comment /ponytail to run again
|
|
||
| // unwrapParenNode strips redundant parentheses when n is an expression and | ||
| // returns n unchanged otherwise. | ||
| func unwrapParenNode(n ast.Node) ast.Node { |
There was a problem hiding this comment.
What this is: unwrapParenNode is a small adapter around astutil.UnwrapParenExpr. Problem: caseConvFuncAndArg and caseConvPkgName, plus all their callers, only receive ast.Expr values, so the ast.Node type assertion and unchanged-non-expression branch can never run and add wrapper code. Fix: tighten these helpers to ast.Expr and call astutil.UnwrapParenExpr directly. If we skip it: the linter keeps a dead branch and an extra abstraction that future changes must maintain.
There was a problem hiding this comment.
Tightened the helpers to ast.Expr and removed the redundant wrapper. Validation passed. Commit: e882134.
✅ Design Decision Gate — ADR VerifiedADR reviewed: ADR-75294: Unwrap Parenthesized Expressions in Linter Matchers. The implementation follows the stated decision. 🏗️ This PR adds 143 lines under Next step: link the ADR in the PR body (for example 📋 Verification SummaryHow the code matches ADR-75294
Minor note (not a divergence)
Other notes
|
|
Caution agentic threat detected DetailsPotential security threats were detected in the agent output. Detected threat types: prompt injection. Review the workflow run logs for details. Comment MemoryPeek at saved memory (pr-code-quality-reviewer)Note This comment is managed by comment memory.Expand the saved memory block to view or edit the persistent context for this thread.
|
There was a problem hiding this comment.
Caution
agentic threat detected
Threat detection flagged this output in warn mode. Manual review is REQUIRED before any follow-up automation.
Details
Potential security threats were detected in the agent output. Detected threat types: prompt injection.
Review the workflow run logs for details.
Found one correctness issue in alias invalidation: parenthesized alias reads are now recognized, but parenthesized reassignments can leave stale alias state and produce false-positive EqualFold diagnostics. Please invalidate aliases consistently before merging.
🔎 Code quality review by PR Code Quality Reviewer · copilot · gpt50 · ~3 AIC · ⌖ ~2 AIC · ⊞ 1.6K
Comment /review to run again
|
|
||
| func caseConvAliasArg(pass *analysis.Pass, expr ast.Expr, aliases map[types.Object]caseConvAliasInfo) (ast.Expr, bool) { | ||
| ident, ok := expr.(*ast.Ident) | ||
| ident, ok := astutil.UnwrapParenExpr(expr).(*ast.Ident) |
There was a problem hiding this comment.
Unwrapping parenthesized alias reads without unwrapping alias assignments leaves stale aliases after (lower) = ..., causing false positives for comparisons that are no longer based on ToLower/ToUpper.
💡 Keep alias invalidation consistent
collectAliasesFromAssignStmt and deleteAliasForExpr still assert *ast.Ident directly on assignment/range LHS expressions. Update those invalidation paths (and the IncDec path if applicable) to use astutil.UnwrapParenExpr, then add a fixture where (lower) = "BOB" precedes (lower) == "alice" and expects no diagnostic.
There was a problem hiding this comment.
Parenthesized assignment targets now invalidate the alias, with a regression case for (lower) = "bob"; the analyzer test passes. Commit: e882134.
There was a problem hiding this comment.
🟡 Changes recommended
The golden fixture reverses the argument order emitted by buildEqualFoldFix, causing TestAnalyzer’s suggested-fix comparison to fail.
1 open issue
What changed in this PR
Continues the parenthesis-handling fixes across gh-aw’s Go linters, extending detection in tolowerequalfold and bufioscannererunchecked.
Changes:
- Recognizes parenthesized case-conversion calls, aliases, and scanner receivers and methods.
- Adds analysis of labeled scanner loops.
- Adds regression fixtures and expected
EqualFoldrewrites.
| File | Description |
|---|---|
pkg/linters/tolowerequalfold/tolowerequalfold.go |
Unwraps parentheses when matching conversions and operands. |
pkg/linters/tolowerequalfold/testdata/src/tolowerequalfold/paren.go.golden |
Records expected fixes for parenthesized comparisons. |
pkg/linters/tolowerequalfold/testdata/src/tolowerequalfold/paren.go |
Adds positive and negative parenthesized comparison cases. |
pkg/linters/bufioscannererunchecked/testdata/src/basic/good.go |
Covers valid error checks with parentheses and labels. |
pkg/linters/bufioscannererunchecked/testdata/src/basic/bad.go |
Covers unchecked parenthesized and labeled scanner loops. |
pkg/linters/bufioscannererunchecked/bufioscannererunchecked.go |
Unwraps scanner expressions and strips loop labels. |
Review effort: Balanced (auto)
There was a problem hiding this comment.
Skills-Based Review 🧠
Applied /diagnosing-bugs and /tdd. Requesting changes: the tolowerequalfold analysistest fails on the new fixture, and the fix leaves a false positive on the write side.
📋 Key Themes & Highlights
Key Themes
- Failing golden:
paren.go.goldenline 10 expectsEqualFold(name, "alice")for"alice" == (strings.ToLower(name)). The linter emitsEqualFold("alice", name), which is the same operand order as the existing unparenthesized golden. The PR notes saygo testwas not run, and this is why CI would fail. - Write-side alias gap: Reads now unwrap parens, but
collectAliasesFromAssignStmt(lhs.(*ast.Ident)) anddeleteAliasForExpr(expr.(*ast.Ident)) do not. So(lower) = "bob"leaves the alias live and(lower) == "alice"is flagged. This is a new false positive that this PR introduces.
Verification
- With the golden corrected and the writer sites unwrapped in a temporary local edit,
tolowerequalfoldandbufioscannereruncheckedboth pass. I reverted those edits. - The
bufioscannereruncheckedsuite passes as written, including the parenthesized and labeled-loop cases.
Positive Highlights
- ✅ Paren unwrapping is applied consistently to the callee, the receiver, and the alias read path.
- ✅
unlabeledStmthandles nested labels with a clear loop. - ✅ Fixtures cover both operand orders and the
!=form.
Remaining Uncertainty
I did not run the full make agent-report-progress gate or gofmt. The triage fallback was not used. Triage returned a valid result.
@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 · ⊞ 5.4K
Comment /matt to run again
| func parenthesizedExamples(name string) { | ||
| _ = strings.EqualFold(name, "alice") // want `use strings\.EqualFold` | ||
|
|
||
| _ = strings.EqualFold(name, "alice") // want `use strings\.EqualFold` |
There was a problem hiding this comment.
[/diagnosing-bugs] This golden expectation is wrong, so the tolowerequalfold suite fails. For the reversed form "alice" == (strings.ToLower(name)) the linter emits strings.EqualFold("alice", name), which matches the existing unparenthesized case in tolowerequalfold.go.golden:19.
💡 Fix
Change line 10 to:
_ = strings.EqualFold("alice", name) // want `use strings\.EqualFold`With this change and the write-side fix below, both analysistest suites pass in a temporary local edit, which I reverted.
@copilot please address this.
There was a problem hiding this comment.
Corrected the golden output to preserve operand order; the impacted analyzer test now passes. Commit: e882134.
|
|
||
| func caseConvAliasArg(pass *analysis.Pass, expr ast.Expr, aliases map[types.Object]caseConvAliasInfo) (ast.Expr, bool) { | ||
| ident, ok := expr.(*ast.Ident) | ||
| ident, ok := astutil.UnwrapParenExpr(expr).(*ast.Ident) |
There was a problem hiding this comment.
[/diagnosing-bugs] Reads now see through parentheses, but the alias writers do not. collectAliasesFromAssignStmt (line 181) and deleteAliasForExpr (line 237) still assert a raw *ast.Ident, so (lower) = "bob" does not clear the alias. A later (lower) == "alice" is then flagged. I confirmed this with a probe, which reported a diagnostic on that comparison. Before this PR the parenthesized read was never matched, so this false positive is new.
💡 Fix
Unwrap at both writer sites, matching the read side here:
ident, ok := astutil.UnwrapParenExpr(lhs).(*ast.Ident) // line 181
ident, ok := astutil.UnwrapParenExpr(expr).(*ast.Ident) // line 237Add (lower) = "bob" followed by (lower) == "alice" to paren.go as a regression case. Write it red first, then fix, per /tdd.
@copilot please address this.
There was a problem hiding this comment.
Alias invalidation now unwraps parenthesized assignment targets, and the added regression test passes. Commit: e882134.
|
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: ed81258
|
…lower-scanner-r123-3e4ea65d9c044fb6 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
Continues the paren-unwrap series (#74382, #74737, #75085, #75294, #75599). Two more linters detected only unparenthesized forms.
tolowerequalfoldcaseConvFuncAndArg,caseConvPkgName,caseConvAliasArg,caseConvAliasIsCompatibleandsameOperandasserted concrete node types without unwrapping*ast.ParenExpr. Missed forms (now reported, with the EqualFold fix where a direct call is present):(strings.ToLower(name)) == "alice"(strings.ToUpper)(name) == "ALICE"(lower) == "alice"wherelower := strings.ToLower(name)bufioscannereruncheckedscannerMethodCallReceiverassertedcall.Fun.(*ast.SelectorExpr)andreceiverKeyswitched on the raw receiver expr, sofor (sc).Scan()/for (sc.Scan)()were never matched (also made(sc).Err()not count as an Err check, causing false positives).analyzeBlockStatementsonly matched*ast.ForStmtdirectly, so labeled loops (lines: for sc.Scan() {...}) were skipped entirely. Labels are now stripped. No labeled scanner loops exist inpkg/today, so no new findings in the repo.Validation
tolowerequalfold/testdata/.../paren.go(+.golden), and bad/good cases inbufioscannererunchecked/testdata/src/basic/.get_diagnostics_for_file: 0 diagnostics on both changed source files; fixtures compile (only unused-func hints).go test,gofmt/make fmtandmake agent-report-progresswere denied by the sandbox in this run, so the analysistest suites have not been executed. CI should confirm.🤖 Generated with [Claude Code]((claude.com/redacted)