rtk icon indicating copy to clipboard operation
rtk copied to clipboard

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

Open apowis opened this issue 6 months ago • 3 comments

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

apowis avatar May 27 '26 11:05 apowis

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.

rtk-release-bot[bot] avatar May 27 '26 11:05 rtk-release-bot[bot]

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.

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

CLAassistant avatar May 27 '26 11:05 CLAassistant

@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

apowis avatar Jun 02 '26 09:06 apowis