Skip to content

fix(golangci-lint): restore run wrapper and preserve global-flag rewrites#798

Open
mgierok wants to merge 3 commits intortk-ai:developfrom
mgierok:fix/golangci-lint-run-wrapper-develop
Open

fix(golangci-lint): restore run wrapper and preserve global-flag rewrites#798
mgierok wants to merge 3 commits intortk-ai:developfrom
mgierok:fix/golangci-lint-run-wrapper-develop

Conversation

@mgierok
Copy link

@mgierok mgierok commented Mar 24, 2026

Summary

This PR fixes a regression in the golangci-lint wrapper and restores consistency between runtime behavior, discover/rewrite, and the documented compact path.

It includes exactly these 3 commits:

  • fix(golangci-lint): restore run wrapper and align guidance
  • fix(discover): preserve golangci-lint flags in rewrite
  • fix(golangci-lint): support inline global flags before run

What changed

  • restored rtk golangci-lint as a single wrapper entrypoint with passthrough for non-run invocations
  • kept compact filtering only for rtk golangci-lint run ...
  • fixed discover / rewrite so global flags before run are preserved
  • fixed inline --flag=value handling in both runtime parsing and rewrite/discovery
  • updated guidance/docs so the compact path is consistently advertised as rtk golangci-lint run ...

Validation

Targeted checks passed:

  • rtk cargo test golangci_cmd -- --nocapture
  • rtk cargo test discover::registry -- --nocapture
  • rtk cargo run -- rewrite 'golangci-lint --color=never run ./...'

Local full gate status:

  • rtk cargo fmt --all --check passed
  • rtk cargo clippy --all-targets reported one existing warning in src/rake_cmd.rs
  • rtk cargo test in this environment still hits pre-existing tracking DB file failures unrelated to this PR

mgierok added 3 commits March 24, 2026 19:30
Keep bare golangci-lint invocations as passthrough while preserving compact filtering for golangci-lint run.
Update discover/rewrite rules, regression tests, and docs to advertise only the supported compact run path.
Normalize golangci-lint global flags before run during classification and keep them in rewritten commands.
Add regression coverage for classify_command and rewrite_command with pre-run global flags.
Handle --flag=value forms consistently in both the runtime parser and discover rewrite logic.
Add regression coverage for classify and rewrite paths using inline global flag values before run.
@CLAassistant
Copy link

CLAassistant commented Mar 24, 2026

CLA assistant check
All committers have signed the CLA.

@mgierok
Copy link
Author

mgierok commented Mar 24, 2026

This PR fixes a regression in the golangci-lint wrapper path and closes the follow-up parser gaps around rewrite/discovery.

Problem

The original regression came from shifting golangci-lint toward a nested Clap subcommand flow instead of treating it as a single wrapper entrypoint.

That created two distinct problems.

1. Runtime wrapper regression

rtk golangci-lint run ... could build an incorrect child command with duplicated run, because run was effectively being interpreted both by wrapper routing and as an upstream argument.

At the same time, bare rtk golangci-lint stopped behaving like a true passthrough entrypoint and was treated too much like the compact run path.

That made the public interface inconsistent with the intended contract:

  • compact filtering should apply to rtk golangci-lint run ...
  • bare rtk golangci-lint and other upstream subcommands should remain passthrough

2. Rewrite / discovery regressions

After narrowing the compact path to golangci-lint run, the discovery layer became too strict and stopped recognizing valid invocations with global flags before run, for example:

golangci-lint -v run ./...
golangci-lint --color never run ./...

That meant hook users could silently fall back to the raw verbose command even though the runtime wrapper explicitly supports those forms.

A second bug affected the standard inline syntax:

golangci-lint --color=never run ./...
golangci-lint --config=foo.yml run ./...

Both the runtime parser and the rewrite/discovery parser normalized --flag=value down to the flag name, but still skipped the next token as if the value were separate. In practice, that jumped past run, so these commands no longer took the compact path.

Fix

This PR is intentionally split into 3 commits, each tightening one part of the behavior:

1. Restore the wrapper contract

The wrapper keeps a single public entrypoint for rtk golangci-lint and moves the behavioral split into golangci_cmd.

Only invocations whose first real upstream subcommand is run take the compact filtered path. Bare rtk golangci-lint and non-run subcommands remain passthrough.

In the filtered path, run is consumed logically only once, so the child process receives exactly one run.

2. Restore rewrite/discovery support for pre-run global flags

discover and rewrite now recognize supported global flags that appear before run and preserve them in rewritten commands.

Examples that now work correctly again:

golangci-lint -v run ./...
golangci-lint --color never run ./...

and rewrite to:

rtk golangci-lint -v run ./...
rtk golangci-lint --color never run ./...

3. Support inline --flag=value forms consistently

Both the runtime parser and the rewrite/discovery parser now distinguish between:

  • --flag value
  • --flag=value

So these forms also stay on the supported compact path:

golangci-lint --color=never run ./...
golangci-lint --config=foo.yml run ./...

and rewrite to:

rtk golangci-lint --color=never run ./...
rtk golangci-lint --config=foo.yml run ./...

Resulting behavior

After this PR, the contract is consistent again:

  • compact path:
    • rtk golangci-lint run [args...]
    • rtk golangci-lint -v run [args...]
    • rtk golangci-lint --color never run [args...]
    • rtk golangci-lint --color=never run [args...]
  • passthrough path:
    • rtk golangci-lint
    • rtk golangci-lint version
    • rtk golangci-lint linters

Tests

This PR adds or updates regression coverage for:

  • runtime dispatch for run
  • runtime dispatch with global flags before run
  • runtime dispatch with inline --flag=value
  • discover classification for golangci-lint run
  • discover classification/rewrite for -v, --color never, --color=never, and --config=...
  • env-prefixed rewrite cases
  • helper normalization for global flags before run

Targeted validation run locally:

  • rtk cargo test golangci_cmd -- --nocapture
  • rtk cargo test discover::registry -- --nocapture
  • rtk cargo run -- rewrite 'golangci-lint --color=never run ./...'

The local full gate still reports unrelated tracking DB failures in this environment, which appear to be pre-existing and not caused by these 3 commits.

@pszymkowiak pszymkowiak added bug Something isn't working effort-medium 1-2 jours, quelques fichiers filter-quality Filter produces incorrect/truncated signal labels Mar 24, 2026
@pszymkowiak
Copy link
Collaborator

[w] wshm · Automated triage by AI

📊 Automated PR Analysis

🐛 Type bug-fix
🟡 Risk medium

Summary

Restores the golangci-lint run wrapper so that only rtk golangci-lint run triggers compact filtering, while bare rtk golangci-lint passes through. Fixes discover/rewrite to preserve global flags (e.g. --color, --config) that appear before the run subcommand, and updates all documentation to reflect the correct compact path.

Review Checklist

  • Tests present
  • Breaking change
  • Docs updated

Analyzed automatically by wshm · This is an automated analysis, not a human review.

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

Labels

bug Something isn't working effort-medium 1-2 jours, quelques fichiers filter-quality Filter produces incorrect/truncated signal

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants