Skip to content

linters: modernize golang.org/x/tools usage — Cursor API, direct assertions, golden fix test#36221

Merged
pelikhan merged 7 commits into
mainfrom
copilot/go-fan-review-golang-org-x-tools
Jun 1, 2026
Merged

linters: modernize golang.org/x/tools usage — Cursor API, direct assertions, golden fix test#36221
pelikhan merged 7 commits into
mainfrom
copilot/go-fan-review-golang-org-x-tools

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jun 1, 2026

The pkg/linters/ suite had three mechanical gaps flagged in the golang.org/x/tools module review: untested suggested-fix output in ctxbackground, defensive comma-ok boilerplate that can never trigger across all 19 analyzers, and WithStack+slices.Backward ancestor scans where the newer Cursor API is cleaner.

Changes

  • ctxbackground: pilot inspector.Cursor API
    Replaces insp.WithStack(...) + slices.Backward(stack) with insp.Root().Preorder + cur.Enclosing((*ast.FuncDecl)(nil)), removing push/pop/stack bookkeeping and the slices import:

    for cur := range insp.Root().Preorder((*ast.CallExpr)(nil)) {
        call := cur.Node().(*ast.CallExpr)
        for encl := range cur.Enclosing((*ast.FuncDecl)(nil)) {
            fn := encl.Node().(*ast.FuncDecl)
            // report and break
        }
    }
  • ctxbackground: verify suggested fix with golden file
    Adds testdata/src/ctxbackground/ctxbackground.go.golden and switches the test from analysistest.Runanalysistest.RunWithSuggestedFixes, so the context.Background() → ctx text-edit is now actually verified.

  • All 19 analyzers: drop comma-ok inspector assertion
    Every run function repeated:

    insp, ok := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector)
    if !ok {
        return nil, fmt.Errorf("inspect analyzer result has unexpected type %T", ...)
    }

    Since inspect.Analyzer is in every Requires, this branch is unreachable. Replaced with the idiomatic direct assertion and removed the now-unused fmt imports (~76 lines eliminated across the suite).

Copilot AI linked an issue Jun 1, 2026 that may be closed by this pull request
4 tasks
Copilot AI and others added 2 commits June 1, 2026 11:41
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
…I in ctxbackground

- Replace comma-ok assertion pattern with direct assertion across all 19 linters
- Remove now-unused fmt imports from all affected files
- Rewrite ctxbackground.go using inspector.Cursor API (Preorder + Enclosing)
  replacing WithStack + slices.Backward ancestor scan
- Add testdata/src/ctxbackground/ctxbackground.go.golden
- Switch ctxbackground_test.go to analysistest.RunWithSuggestedFixes

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Review Go module golang.org/x/tools linters: modernize golang.org/x/tools usage — Cursor API, direct assertions, golden fix test Jun 1, 2026
Copilot AI requested a review from pelikhan June 1, 2026 11:49
@pelikhan pelikhan marked this pull request as ready for review June 1, 2026 11:51
Copilot AI review requested due to automatic review settings June 1, 2026 11:51
@pelikhan
Copy link
Copy Markdown
Collaborator

pelikhan commented Jun 1, 2026

@copilot Merge main, recompile

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR modernizes the Go linter analyzers under pkg/linters/ to align with newer golang.org/x/tools APIs (Cursor-based inspector traversal, direct analyzer result assertions) and improves verification of suggested fixes via golden testing. In addition, it regenerates numerous workflow lock files, changing setup/guardrail step behavior in those workflows.

Changes:

  • Refactor ctxbackground to use the inspector.Cursor API and add golden coverage for its suggested fix output.
  • Simplify all affected analyzers by replacing unreachable comma-ok type checks with direct .(*inspector.Inspector) assertions and removing now-unused fmt imports.
  • Regenerate many .github/workflows/*.lock.yml files (not described in the PR description), including making safe-output-artifact-client unconditional and removing conditional execution for the daily ET guardrail step.
Show a summary per file
File Description
pkg/linters/uncheckedtypeassertion/uncheckedtypeassertion.go Drop unreachable comma-ok inspector assertion; remove fmt import.
pkg/linters/strconvparseignorederror/strconvparseignorederror.go Drop unreachable comma-ok inspector assertion; remove fmt import.
pkg/linters/regexpcompileinfunction/regexpcompileinfunction.go Drop unreachable comma-ok inspector assertion; remove fmt import.
pkg/linters/rawloginlib/rawloginlib.go Drop unreachable comma-ok inspector assertion; remove fmt import.
pkg/linters/panic-in-library-code/panic-in-library-code.go Drop unreachable comma-ok inspector assertion; remove fmt import.
pkg/linters/ossetenvlibrary/ossetenvlibrary.go Drop unreachable comma-ok inspector assertion; remove fmt import.
pkg/linters/osexitinlibrary/osexitinlibrary.go Drop unreachable comma-ok inspector assertion; remove fmt import.
pkg/linters/manualmutexunlock/manualmutexunlock.go Drop unreachable comma-ok inspector assertion; remove fmt import.
pkg/linters/largefunc/largefunc.go Drop unreachable comma-ok inspector assertion; remove fmt import.
pkg/linters/jsonmarshalignoredeerror/jsonmarshalignoredeerror.go Drop unreachable comma-ok inspector assertion; remove fmt import.
pkg/linters/fprintlnsprintf/fprintlnsprintf.go Drop unreachable comma-ok inspector assertion; remove fmt import.
pkg/linters/fmterrorfnoverbs/fmterrorfnoverbs.go Replace defensive inspector retrieval with direct assertion.
pkg/linters/fileclosenotdeferred/fileclosenotdeferred.go Drop unreachable comma-ok inspector assertion; remove fmt import.
pkg/linters/excessivefuncparams/excessivefuncparams.go Drop unreachable comma-ok inspector assertion; remove fmt import.
pkg/linters/errstringmatch/errstringmatch.go Drop unreachable comma-ok inspector assertion; remove fmt import.
pkg/linters/errormessage/errormessage.go Drop unreachable comma-ok inspector assertion; remove fmt import.
pkg/linters/contextcancelnotdeferred/contextcancelnotdeferred.go Drop unreachable comma-ok inspector assertion; remove fmt import.
pkg/linters/ctxbackground/ctxbackground.go Migrate to Cursor API for ancestor lookup and keep suggested fix behavior.
pkg/linters/ctxbackground/ctxbackground_test.go Switch to RunWithSuggestedFixes so edits are asserted.
pkg/linters/ctxbackground/testdata/src/ctxbackground/ctxbackground.go.golden Add golden output validating the suggested fix edit.
.github/workflows/daily-mcp-concurrency-analysis.lock.yml Regenerated lock workflow (setup input + guardrail step condition changes).
.github/workflows/daily-malicious-code-scan.lock.yml Regenerated lock workflow (setup input + guardrail step condition changes).
.github/workflows/daily-issues-report.lock.yml Regenerated lock workflow (setup input + guardrail step condition changes).
.github/workflows/daily-hippo-learn.lock.yml Regenerated lock workflow (setup input + guardrail step condition changes).
.github/workflows/daily-grafana-otel-instrumentation-advisor.lock.yml Regenerated lock workflow (setup input + guardrail step condition changes).
.github/workflows/daily-geo-optimizer.lock.yml Regenerated lock workflow (setup input + guardrail step condition changes).
.github/workflows/daily-function-namer.lock.yml Regenerated lock workflow (setup input + guardrail step condition changes).
.github/workflows/daily-firewall-report.lock.yml Regenerated lock workflow (setup input + guardrail step condition changes).
.github/workflows/daily-file-diet.lock.yml Regenerated lock workflow (setup input + guardrail step condition changes).
.github/workflows/daily-fact.lock.yml Regenerated lock workflow (setup input + guardrail step condition changes).
.github/workflows/daily-experiment-report.lock.yml Regenerated lock workflow (setup input + guardrail step condition changes).
.github/workflows/daily-doc-updater.lock.yml Regenerated lock workflow (setup input + guardrail step condition changes).
.github/workflows/daily-doc-healer.lock.yml Regenerated lock workflow (setup input + guardrail step condition changes).
.github/workflows/daily-compiler-threat-spec-optimizer.lock.yml Regenerated lock workflow (setup input + guardrail step condition changes).
.github/workflows/daily-compiler-quality.lock.yml Regenerated lock workflow (setup input + guardrail step condition changes).
.github/workflows/daily-community-attribution.lock.yml Regenerated lock workflow (setup input + guardrail step condition changes).
.github/workflows/daily-code-metrics.lock.yml Regenerated lock workflow (setup input + guardrail step condition changes).
.github/workflows/daily-cli-tools-tester.lock.yml Regenerated lock workflow (setup input + guardrail step condition changes).
.github/workflows/daily-cli-performance.lock.yml Regenerated lock workflow (setup input + guardrail step condition changes).
.github/workflows/daily-choice-test.lock.yml Regenerated lock workflow (setup input + guardrail step condition changes).
.github/workflows/daily-caveman-optimizer.lock.yml Regenerated lock workflow (setup input + guardrail step condition changes).
.github/workflows/daily-cache-strategy-analyzer.lock.yml Regenerated lock workflow (setup input + guardrail step condition changes).
.github/workflows/daily-byok-ollama-test.lock.yml Regenerated lock workflow (setup input + guardrail step condition changes).
.github/workflows/daily-aw-cross-repo-compile-check.lock.yml Regenerated lock workflow (setup input + guardrail step condition changes).
.github/workflows/daily-astrostylelite-markdown-spellcheck.lock.yml Regenerated lock workflow (setup input + guardrail step condition changes).
.github/workflows/daily-assign-issue-to-user.lock.yml Regenerated lock workflow (setup input + guardrail step condition changes).
.github/workflows/daily-architecture-diagram.lock.yml Regenerated lock workflow (setup input + guardrail step condition changes).
.github/workflows/daily-agentrx-trace-optimizer.lock.yml Regenerated lock workflow (setup input + guardrail step condition changes).
.github/workflows/daily-agent-of-the-day-blog-writer.lock.yml Regenerated lock workflow (setup input + guardrail step condition changes).
.github/workflows/craft.lock.yml Regenerated lock workflow (setup input + guardrail step condition changes).
.github/workflows/copilot-session-insights.lock.yml Regenerated lock workflow (setup input + guardrail step condition changes).
.github/workflows/copilot-pr-prompt-analysis.lock.yml Regenerated lock workflow (setup input + guardrail step condition changes).
.github/workflows/copilot-pr-nlp-analysis.lock.yml Regenerated lock workflow (setup input + guardrail step condition changes).
.github/workflows/copilot-pr-merged-report.lock.yml Regenerated lock workflow (setup input + guardrail step condition changes).
.github/workflows/copilot-opt.lock.yml Regenerated lock workflow (setup input + guardrail step condition changes).
.github/workflows/copilot-cli-deep-research.lock.yml Regenerated lock workflow (setup input + guardrail step condition changes).
.github/workflows/copilot-agent-analysis.lock.yml Regenerated lock workflow (setup input + guardrail step condition changes).
.github/workflows/contribution-check.lock.yml Regenerated lock workflow (setup input + guardrail step condition changes).
.github/workflows/constraint-solving-potd.lock.yml Regenerated lock workflow (setup input + guardrail step condition changes).
.github/workflows/commit-changes-analyzer.lock.yml Regenerated lock workflow (setup input + guardrail step condition changes).
.github/workflows/codex-github-remote-mcp-test.lock.yml Regenerated lock workflow (setup input + guardrail step condition changes).
.github/workflows/code-simplifier.lock.yml Regenerated lock workflow (setup input + guardrail step condition changes).
.github/workflows/code-scanning-fixer.lock.yml Regenerated lock workflow (setup input + guardrail step condition changes).
.github/workflows/cloclo.lock.yml Regenerated lock workflow (setup input + guardrail step condition changes).
.github/workflows/cli-version-checker.lock.yml Regenerated lock workflow (setup input + guardrail step condition changes).
.github/workflows/cli-consistency-checker.lock.yml Regenerated lock workflow (setup input + guardrail step condition changes).
.github/workflows/claude-code-user-docs-review.lock.yml Regenerated lock workflow (setup input + guardrail step condition changes).
.github/workflows/ci-doctor.lock.yml Regenerated lock workflow (setup input + guardrail step condition changes).
.github/workflows/ci-coach.lock.yml Regenerated lock workflow (setup input + guardrail step condition changes).
.github/workflows/chaos-pr-bundle-fuzzer.lock.yml Regenerated lock workflow (setup input + guardrail step condition changes).
.github/workflows/changeset.lock.yml Regenerated lock workflow (setup input + guardrail step condition changes).
.github/workflows/breaking-change-checker.lock.yml Regenerated lock workflow (setup input + guardrail step condition changes).
.github/workflows/brave.lock.yml Regenerated lock workflow (setup input + guardrail step condition changes).
.github/workflows/bot-detection.lock.yml Regenerated lock workflow (setup input + guardrail step condition changes).
.github/workflows/blog-auditor.lock.yml Regenerated lock workflow (setup input + guardrail step condition changes).
.github/workflows/aw-failure-investigator.lock.yml Regenerated lock workflow (setup input + guardrail step condition changes).
.github/workflows/avenger.lock.yml Regenerated lock workflow (setup input + guardrail step condition changes).
.github/workflows/auto-triage-issues.lock.yml Regenerated lock workflow (setup input + guardrail step condition changes).
.github/workflows/audit-workflows.lock.yml Regenerated lock workflow (setup input + guardrail step condition changes).
.github/workflows/artifacts-summary.lock.yml Regenerated lock workflow (setup input + guardrail step condition changes).
.github/workflows/architecture-guardian.lock.yml Regenerated lock workflow (setup input + guardrail step condition changes).
.github/workflows/archie.lock.yml Regenerated lock workflow (setup input + guardrail step condition changes).
.github/workflows/approach-validator.lock.yml Regenerated lock workflow (setup input + guardrail step condition changes).
.github/workflows/api-consumption-report.lock.yml Regenerated lock workflow (setup input + guardrail step condition changes).
.github/workflows/ai-moderator.lock.yml Regenerated lock workflow (setup input + guardrail step condition changes).
.github/workflows/agentic-token-optimizer.lock.yml Regenerated lock workflow (setup input + guardrail step condition changes).
.github/workflows/agentic-token-audit.lock.yml Regenerated lock workflow (setup input + guardrail step condition changes).
.github/workflows/agent-persona-explorer.lock.yml Regenerated lock workflow (setup input + guardrail step condition changes).
.github/workflows/agent-performance-analyzer.lock.yml Regenerated lock workflow (setup input + guardrail step condition changes).
.github/workflows/ace-editor.lock.yml Regenerated lock workflow (setup input + guardrail step condition changes).
.github/workflows/ab-testing-advisor.lock.yml Regenerated lock workflow (setup input + guardrail step condition changes).

Copilot's findings

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 91/91 changed files
  • Comments generated: 1

Comment on lines 125 to +129
uses: ./actions/setup
with:
destination: ${{ runner.temp }}/gh-aw/actions
job-name: ${{ github.job }}
safe-output-artifact-client: ${{ env.GH_AW_MAX_DAILY_EFFECTIVE_TOKENS != '' }}
safe-output-artifact-client: 'true'
@pelikhan
Copy link
Copy Markdown
Collaborator

pelikhan commented Jun 1, 2026

Copilot AI and others added 2 commits June 1, 2026 14:39
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Jun 1, 2026

@copilot lint go, update wasm

https://github.com/github/gh-aw/actions/runs/26761144093/job/78874693251

Addressed in af38ba4. I restored checked analyzer assertions where the custom linter requires the two-value form and refreshed the wasm golden outputs after the merge.

@pelikhan
Copy link
Copy Markdown
Collaborator

pelikhan commented Jun 1, 2026

@copilot merge main and recompile

…go-fan-review-golang-org-x-tools

# Conflicts:
#	.github/workflows/daily-cache-strategy-analyzer.lock.yml
#	.github/workflows/daily-fact.lock.yml
#	.github/workflows/daily-observability-report.lock.yml
#	.github/workflows/dev.lock.yml
#	.github/workflows/duplicate-code-detector.lock.yml
#	.github/workflows/grumpy-reviewer.lock.yml
#	.github/workflows/issue-arborist.lock.yml
#	.github/workflows/necromancer.lock.yml
#	.github/workflows/schema-feature-coverage.lock.yml
#	.github/workflows/smoke-call-workflow.lock.yml
#	.github/workflows/smoke-codex.lock.yml

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Jun 1, 2026

@copilot merge main and recompile

Addressed in b53ae77. I merged the latest main into the branch, recompiled the workflow lock files, and re-ran the targeted build/test checks.

@pelikhan pelikhan merged commit aef4be5 into main Jun 1, 2026
25 checks passed
@pelikhan pelikhan deleted the copilot/go-fan-review-golang-org-x-tools branch June 1, 2026 15:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[go-fan] Go Module Review: golang.org/x/tools

3 participants