Skip to content

feat(go): general go tool support with golangci-lint filtering#2114

Open
apowis wants to merge 7 commits into
rtk-ai:developfrom
apowis:feat/go-tool-support
Open

feat(go): general go tool support with golangci-lint filtering#2114
apowis wants to merge 7 commits into
rtk-ai:developfrom
apowis:feat/go-tool-support

Conversation

@apowis

@apowis apowis commented May 27, 2026

Copy link
Copy Markdown
Contributor

Fixes #744

Summary

Fixes two bugs in the original implementation (commit 8f985a2) and extends support to all go tool invocations.

Bug 1 — double run in command args

rtk go tool golangci-lint run ./... was producing:

go tool golangci-lint run --output.json.path stdout run ./...

because run_go_tool_golangci_lint always prepended run before appending all args (which already included run).

Fix: Extract build_go_tool_golangci_args() helper that strips a leading run before injecting the JSON flag. Both calling forms now work:

  • rtk go tool golangci-lint run ./... (explicit run)
  • rtk go tool golangci-lint ./... (no run prefix)

Bug 2 — rewrite rule and runtime dispatch too narrow

The original implementation only handled go tool golangci-lint — any other managed tool (go tool staticcheck, go tool pprof, etc.) was never rewritten by the hook and never tracked.

Fix:

  • Drop the GoTool enum; match_go_tool() now returns the tool name as a String and matches any go tool <name>
  • Unknown tools are routed through a new run_go_tool_passthrough() that executes transparently and records usage in the tracking DB (visible in rtk gain --history)
  • Rewrite pattern broadened from ^go\s+(test|build|vet) to ^go\s+(test|build|vet|tool\s+\S+)

Behaviour after this change

Command Before After
go tool golangci-lint run ./... unfiltered passthrough filtered + tracked
go tool golangci-lint ./... unfiltered passthrough filtered + tracked
go tool staticcheck ./... not rewritten, untracked transparent passthrough + tracked
go tool pprof cpu.prof not rewritten, untracked transparent passthrough + tracked
Any future go tool <x> ignored transparent passthrough + tracked

Test plan

  • 7 new unit tests for match_go_tool (now accepts any tool name) and build_go_tool_golangci_args (no double-run)
  • 5 new registry tests covering classify + rewrite for golangci-lint and arbitrary tools
  • Verified end-to-end against a real Go 1.26 project with golangci-lint v2.10.0 registered as a go tool

aeppling and others added 7 commits May 22, 2026 17:57
…master--components--rtk

chore(master): release 0.41.0
…master--components--rtk

chore(master): release 0.42.0
Fixes two bugs in the original go tool golangci-lint implementation
(commit 8f985a2) and extends support to all go tool invocations.

Bug 1 — double 'run' in command args:
  rtk go tool golangci-lint run ./... was producing
  'go tool golangci-lint run --output.json.path stdout run ./...'
  because run_go_tool_golangci_lint always prepended 'run' before
  appending all args (which already included 'run').

  Fix: extract build_go_tool_golangci_args() helper that strips a
  leading 'run' before injecting the JSON flag. Both calling forms
  now work correctly:
    rtk go tool golangci-lint run ./...   (explicit run)
    rtk go tool golangci-lint ./...       (no run prefix)

Bug 2 — rewrite rule too narrow:
  The registry pattern only matched go tool golangci-lint, so
  'go tool staticcheck ./...' and any other managed tool was never
  rewritten to 'rtk go tool ...' by the Claude Code hook.

  Fix: drop the GoTool enum in favour of match_go_tool() returning
  the tool name as a String, matching any 'go tool <name>'. Unknown
  tools are routed through a new run_go_tool_passthrough() that
  executes transparently and records usage in the tracking DB so
  they appear in 'rtk gain --history'. The rewrite pattern is
  broadened to '^go\s+(test|build|vet|tool\s+\S+)'.

Closes rtk-ai#744
@rtk-release-bot rtk-release-bot Bot added the wrong-base PR targets master instead of develop label May 27, 2026
@rtk-release-bot

Copy link
Copy Markdown
Contributor

Automatic message from CI checks : It seems like this branch is targeting the wrong branch, any contribution should target develop branch.

See CONTRIBUTING.md for details.

@CLAassistant

CLAassistant commented May 27, 2026

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
2 out of 3 committers have signed the CLA.

✅ apowis
✅ aeppling
❌ rtk-release-bot[bot]
You have signed the CLA already but the status is still pending? Let us recheck it.

@apowis apowis changed the base branch from master to develop May 27, 2026 11:14
@apowis

apowis commented Jun 2, 2026

Copy link
Copy Markdown
Contributor Author

@aeppling - let me know if I have done everything correctly for contributing here? I did a previous PR on golangci-lint here but I remembered to use the correct base of rtk-ai:develop

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

Labels

wrong-base PR targets master instead of develop

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(go): Support golangci-lint called via go tool

3 participants