Skip to content

fix(linters): see through parentheses in tolowerequalfold and bufioscannererunchecked - #75816

Merged
pelikhan merged 3 commits into
mainfrom
sergo/paren-unwrap-tolower-scanner-r123-3e4ea65d9c044fb6
Nov 8, 2026
Merged

pelikhan merged 3 commits into
mainfrom
sergo/paren-unwrap-tolower-scanner-r123-3e4ea65d9c044fb6

Conversation

@github-actions

@github-actions github-actions Bot commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

Summary

Continues the paren-unwrap series (#74382, #74737, #75085, #75294, #75599). Two more linters detected only unparenthesized forms.

tolowerequalfold

caseConvFuncAndArg, caseConvPkgName, caseConvAliasArg, caseConvAliasIsCompatible and sameOperand asserted 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" where lower := strings.ToLower(name)

bufioscannererunchecked

  • scannerMethodCallReceiver asserted call.Fun.(*ast.SelectorExpr) and receiverKey switched on the raw receiver expr, so for (sc).Scan() / for (sc.Scan)() were never matched (also made (sc).Err() not count as an Err check, causing false positives).
  • analyzeBlockStatements only matched *ast.ForStmt directly, so labeled loops (lines: for sc.Scan() {...}) were skipped entirely. Labels are now stripped. No labeled scanner loops exist in pkg/ today, so no new findings in the repo.

Validation

  • Added fixtures: tolowerequalfold/testdata/.../paren.go(+.golden), and bad/good cases in bufioscannererunchecked/testdata/src/basic/.
  • Serena (gopls) get_diagnostics_for_file: 0 diagnostics on both changed source files; fixtures compile (only unused-func hints).
  • Not run: go test, gofmt/make fmt and make agent-report-progress were 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)

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

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

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

github-actions Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor Author

✅ Ponytail Reviewer completed successfully!

Generated by Ponytail Reviewer for #75816

@github-actions

github-actions Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor Author

✅ PR Code Quality Reviewer completed the code quality review.

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.

🔎 Code quality review by PR Code Quality Reviewer

@github-actions

github-actions Bot commented Nov 8, 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 · ~1 AIC · ⌖ ~1 AIC · ⊞ 1.7K · ◷

Generated by PR Specification Reviewer for #75816

@github-actions

github-actions Bot commented Nov 8, 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

@github-actions

github-actions Bot commented Nov 8, 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.

🏗️ ADR gate enforced by Design Decision Gate 🏗️

@github-actions

github-actions Bot commented Nov 8, 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: gpt56 max · ~2 AIC · ⌖ ~2 AIC · ⊞ 6.3K · ◷

🧪 Test quality analysis by Test Quality Sentinel

@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 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:

  1. Expression-only normalization is wrapped in an unnecessary ast.Node adapter (pkg/linters/tolowerequalfold/tolowerequalfold.go:271-277)

    • What this is: unwrapParenNode accepts any ast.Node before delegating to astutil.UnwrapParenExpr.
    • Problem: Every caller of caseConvFuncAndArg and caseConvPkgName, plus their callers, supplies an ast.Expr, so the type assertion and unchanged-non-expression branch cannot run.
    • Fix: Tighten the expression-only helpers to ast.Expr and call astutil.UnwrapParenExpr directly; this removes the adapter.
    • If we skip it: The linter keeps dead branching and an extra abstraction that future changes must maintain.

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 {

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

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.

Tightened the helpers to ast.Expr and removed the redundant wrapper. Validation passed. Commit: e882134.

@github-actions

github-actions Bot commented Nov 8, 2026

Copy link
Copy Markdown
Contributor Author

✅ Design Decision Gate — ADR Verified

ADR reviewed: ADR-75294: Unwrap Parenthesized Expressions in Linter Matchers. The implementation follows the stated decision. 🏗️

This PR adds 143 lines under pkg/, which is above the 100-line threshold, so the gate applies. The PR body says it continues the paren-unwrap series started in #75294, and ADR-75294 is already in docs/adr/ on this branch, so no new ADR is needed.

Next step: link the ADR in the PR body (for example ADR: [ADR-75294](docs/adr/75294-unwrap-parenthesized-expressions-in-linter-matchers.md)) so later gate runs find it directly.

📋 Verification Summary

How the code matches ADR-75294

  • Unwraps with astutil.UnwrapParenExpr before type assertions: done in both linters.

    • bufioscannererunchecked.go: scannerMethodCallReceiver (call.Fun) and receiverKey (receiver expr).
    • tolowerequalfold.go: caseConvAliasArg, caseConvFuncAndArg, caseConvAliasIsCompatible, caseConvPkgName and sameOperand.
  • Matching and fixes stay specific to each linter; no shared matcher abstraction: followed. The new unwrapParenNode helper is private to tolowerequalfold and only wraps UnwrapParenExpr so it accepts an ast.Node. Nothing new was added to the shared API.

  • Fixes account for parentheses in the source span: paren.go.golden shows that (strings.ToLower(name)) == \"alice\" and ((strings.ToLower))(name) != \"alice\" become clean strings.EqualFold / !strings.EqualFold calls with no leftover parentheses.

  • Regression fixtures document the supported forms: there are new paren.go / paren.go.golden files and new bad/good cases in bufioscannererunchecked/testdata/src/basic/, including negative cases (self-comparison, a literal whose case does not match, and Err() called on a different scanner).

  • The ADR expected follow-up work: its Negative consequences say other linters may need the same treatment. This PR is that follow-up.

Minor note (not a divergence)

  • unlabeledStmt in bufioscannererunchecked.go strips *ast.LabeledStmt so labeled for loops get analyzed. This handles a different wrapper node (a statement label, not parentheses), but it is a small, local matcher fix in the same spirit. You could add one sentence to ADR-75294 saying that wrapper nodes such as statement labels are handled the same way, but it is optional.

Other notes

  • ADR-75294 is still in Draft status. Consider finalizing it now that several follow-up PRs depend on it.
  • The PR body says go test / make fmt were not run in the authoring sandbox, so CI still needs to confirm the analysistest suites pass. This does not affect the ADR check.

🏗️ ADR gate enforced by Design Decision Gate 🏗️ · pi · routed: opus55 xhigh · ~33 AIC · ⌖ ~2 AIC · ⊞ 7.7K · ◷
Comment /review to run again

@github-actions

github-actions Bot commented Nov 8, 2026

Copy link
Copy Markdown
Contributor Author

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.

Comment Memory

Peek at saved memory (pr-code-quality-reviewer)
reviewed_at: 2026-11-08T04:05:00Z
review_event: REQUEST_CHANGES
top_themes:
  - stale alias invalidation with parenthesized assignments
files_reviewed:
  - pkg/linters/bufioscannererunchecked/bufioscannererunchecked.go
  - pkg/linters/bufioscannererunchecked/testdata/src/basic/bad.go
  - pkg/linters/bufioscannererunchecked/testdata/src/basic/good.go
  - pkg/linters/tolowerequalfold/tolowerequalfold.go
  - pkg/linters/tolowerequalfold/testdata/src/tolowerequalfold/paren.go
  - pkg/linters/tolowerequalfold/testdata/src/tolowerequalfold/paren.go.golden
comment_count: 1

Note

This comment is managed by comment memory.

Expand the saved memory block to view or edit the persistent context for this thread.
Edit only the text inside the backtick fences; workflow metadata and the footer are regenerated automatically.

Learn more about comment memory

🔎 Code quality review by PR Code Quality Reviewer · copilot · gpt50 · ~3 AIC · ⌖ ~2 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.

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)

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.

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.

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.

Parenthesized assignment targets now invalidate the alias, with a regression case for (lower) = "bob"; the analyzer test passes. Commit: e882134.

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.

🟡 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 EqualFold rewrites.
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)

@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. 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.golden line 10 expects EqualFold(name, "alice") for "alice" == (strings.ToLower(name)). The linter emits EqualFold("alice", name), which is the same operand order as the existing unparenthesized golden. The PR notes say go test was not run, and this is why CI would fail.
  • Write-side alias gap: Reads now unwrap parens, but collectAliasesFromAssignStmt (lhs.(*ast.Ident)) and deleteAliasForExpr (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, tolowerequalfold and bufioscannererunchecked both pass. I reverted those edits.
  • The bufioscannererunchecked suite 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.
  • ✅ unlabeledStmt handles 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`

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.

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

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.

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)

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.

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

Add (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.

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.

Alias invalidation now unwraps parenthesized assignment targets, and the added regression test passes. Commit: e882134.

@gh-aw-bot

Copy link
Copy Markdown
Collaborator

@copilot

Copilot assignment requested for the following outstanding work:

  1. Update this branch with the latest main using make merge-main, resolving any conflicts and preserving the intended changes.
  2. Fix failing check impacted-go-tests (FAILURE): https://github.com/github/gh-aw/actions/runs/42445055121/job/128622193483.

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
Sous-chef requested-work: 42e5d572d9d75b7168fe7d0aeda0717cc07e65ed240f6d299e6fec661214f1ac
Sous-chef requested-state: e8e3d55f0cbbde87df57015866b2f09b45be8db7e1958211c85d5c81a9ac0d38

Generated by 👨🍳 PR Sous Chef · pi · haiku45 · ~8 AIC · ⌖ ~16 AIC · ⊞ 1.2K · ◷
Comment /souschef to run again

Copilot AI commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

@copilot

Copilot assignment requested for the following outstanding work:...

Sous-chef requested-head: ed81258
Sous-chef requested-work: 42e5d572d9d75b7168fe7d0aeda0717cc07e65ed240f6d299e6fec661214f1ac
Sous-chef requested-state: e8e3d55f0cbbde87df57015866b2f09b45be8db7e1958211c85d5c81a9ac0d38

Copilot AI and others added 2 commits November 8, 2026 04:39
Copilot AI requested a review from gh-aw-bot November 8, 2026 04:51
@pelikhan
pelikhan merged commit f596d0c into main Nov 8, 2026
90 checks passed
@github-actions

Copy link
Copy Markdown
Contributor Author

🎉 This pull request is included in a new release.

Release: v1.2.2

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

Labels

cookie Issue Monster Loves Cookies! needs-review sergo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants