Skip to content

fix(discover): keep a trailing redirect when rewriting golangci-lint - #4340

Merged
TaKO8Ki merged 1 commit into
developfrom
fix/golangci-rewrite-keeps-redirect
Oct 5, 2026
Merged

TaKO8Ki merged 1 commit into
developfrom
fix/golangci-rewrite-keeps-redirect

Conversation

@KuSh

@KuSh KuSh commented Sep 28, 2026

Copy link
Copy Markdown
Collaborator

Problem

The golangci-lint rewrite drops a trailing redirect. The hook turns

golangci-lint run ./... 2>&1
golangci-lint run 2>/dev/null
golangci-lint run ./... 2>&1 | tail -5

into rtk golangci-lint run ./..., rtk golangci-lint run and rtk golangci-lint run ./... | tail -5, so output the command sent to /dev/null or merged into stdout reaches the terminal (and the agent's context) instead.

The golangci-lint branch rebuilds the command from its parsed global and run segments and returned early, before the redirect split off for matching was put back. Every other rewrite path re-attaches it.

Change

Every rewrite of a supported command now builds only the command part (rewrite_command_part), and the trailing redirect is re-attached once, exactly as typed, for all of them. A special-case branch can no longer forget it, and the original boundary is kept: run ${PKG}2>/dev/null stays one operand followed by a redirect, with no separating space inserted. The golangci parser also runs only for the golangci-lint rule instead of for every supported command.

Verification

  • cargo fmt --all --check && cargo clippy --all-targets -- -D warnings && cargo test --all: 4071 passing, clippy clean.
  • Every rule rewrite prefix × six trailing-redirect forms (1752 inputs): golangci-lint was the only rewrite that dropped the redirect (20 cases on develop); none does now.
  • Differential run against develop 6d4b77e on ~100k rtk rewrite inputs (all rule prefixes × argument shapes × redirect forms, with env prefixes, wrappers, pipelines, gh --json and PHP forms): only golangci-lint outputs differ, each by re-attaching the redirect verbatim. That includes ./...2>&1, which develop turned into ./...2.
  • New tests pin the golangci forms (including no-space redirects) and the redirect path for git, gh --json (still skipped) and PHP tools.

🤖 Generated with Claude Code

The golangci-lint rewrite rebuilt the command from its parsed global and
`run` segments and returned early, before the trailing redirect was put
back, so `golangci-lint run 2>&1` became `rtk golangci-lint run` and
output meant for a file or /dev/null reached the terminal instead.

Every rewrite of a supported command now builds only the command part
(`rewrite_command_part`), and the redirect split off before matching is
re-attached once, exactly as typed. A branch can no longer forget it, and
the original boundary is kept: `run ${PKG}2>/dev/null` stays one operand
followed by a redirect, with no separating space inserted.

Across every rule prefix combined with six trailing-redirect forms (1752
inputs), golangci-lint was the only rewrite that dropped the redirect;
with this change none does.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@rtk-wshm-sync-bot rtk-wshm-sync-bot Bot added area:cli bug Something isn't working labels Sep 28, 2026
@rtk-wshm-sync-bot

Copy link
Copy Markdown

wshm · Automated triage by AI

📊 Automated PR Analysis

🐛 Type bug-fix
🟢 Risk low

Summary

Fixes a bug in the golangci-lint command rewrite where a trailing shell redirect (e.g. 2>&1, >/dev/null) was dropped, sending output to the terminal instead of its intended destination. The fix centralizes redirect handling so all rewrite paths split off and re-attach the trailing redirect exactly once and exactly as typed, and restricts the golangci-specific parser to only the golangci-lint rule.

Review Checklist

  • Tests present
  • Breaking change
  • Docs updated

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

@TaKO8Ki
TaKO8Ki self-requested a review October 5, 2026 17:07
@TaKO8Ki
TaKO8Ki merged commit aec5fa9 into develop Oct 5, 2026
18 checks passed
@rtk-release-bot rtk-release-bot Bot mentioned this pull request Oct 5, 2026
@KuSh
KuSh deleted the fix/golangci-rewrite-keeps-redirect branch December 1, 2026 07:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:cli bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants