linters: modernize golang.org/x/tools usage — Cursor API, direct assertions, golden fix test#36221
Conversation
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 Merge main, recompile |
There was a problem hiding this comment.
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
ctxbackgroundto use theinspector.CursorAPI 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-unusedfmtimports. - Regenerate many
.github/workflows/*.lock.ymlfiles (not described in the PR description), including makingsafe-output-artifact-clientunconditional 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
| 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' |
|
@copilot lint go, update wasm https://github.com/github/gh-aw/actions/runs/26761144093/job/78874693251 |
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
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. |
|
@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>
Addressed in b53ae77. I merged the latest |
The
pkg/linters/suite had three mechanical gaps flagged in thegolang.org/x/toolsmodule review: untested suggested-fix output inctxbackground, defensive comma-ok boilerplate that can never trigger across all 19 analyzers, andWithStack+slices.Backwardancestor scans where the newer Cursor API is cleaner.Changes
ctxbackground: pilotinspector.CursorAPIReplaces
insp.WithStack(...) + slices.Backward(stack)withinsp.Root().Preorder+cur.Enclosing((*ast.FuncDecl)(nil)), removing push/pop/stack bookkeeping and theslicesimport:ctxbackground: verify suggested fix with golden fileAdds
testdata/src/ctxbackground/ctxbackground.go.goldenand switches the test fromanalysistest.Run→analysistest.RunWithSuggestedFixes, so thecontext.Background()→ ctx text-edit is now actually verified.All 19 analyzers: drop comma-ok inspector assertion
Every
runfunction repeated:Since
inspect.Analyzeris in everyRequires, this branch is unreachable. Replaced with the idiomatic direct assertion and removed the now-unusedfmtimports (~76 lines eliminated across the suite).