Skip to content

fix(ruff): match format routing to first argument - #3933

Closed
Tiancheng-Xu wants to merge 1 commit into
rtk-ai:developfrom
Tiancheng-Xu:fix/ruff-format-routing-3928
Closed

Tiancheng-Xu wants to merge 1 commit into
rtk-ai:developfrom
Tiancheng-Xu:fix/ruff-format-routing-3928

Conversation

@Tiancheng-Xu

Copy link
Copy Markdown

Summary

  • Route Ruff format filtering only when format is the first argument.
  • Add a focused regression test covering format --check and help format.

中文说明

修复 Ruff 参数路由:只有首个参数是 format 时才进入 format 过滤;后续参数中的 format 不再意外绕过 passthrough 截断。

Testing

  • cargo fmt --all
  • cargo clippy --all-targets
  • cargo test --all (3258 unit tests passed, 8 ignored; all integration tests passed)
  • Focused red-green regression test: ruff_format_routing_requires_first_argument

Fixes #3928

Copilot AI lite review requested due to automatic review settings September 8, 2026 01:29
@CLAassistant

CLAassistant commented Sep 8, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The change directly addresses the reported routing bug with a minimal, well-scoped fix and includes a regression test covering the problematic argv shape.

Pull request overview

This PR fixes Ruff subcommand routing in RTK’s Python Ruff wrapper so that the format filter is only selected when format is the first CLI argument, preventing accidental selection when the token appears later in argv (e.g., help format). It aligns the routing decision with the intended invocation shape and adds a targeted regression test.

Changes:

  • Replace args.iter().any(|a| a == "format") with a first-argument check via is_format_invocation(args).
  • Introduce is_format_invocation() helper to make the routing rule explicit and testable.
  • Add a focused unit test ensuring format --check matches while help format does not.
File summaries
File Description
src/cmds/python/ruff_cmd.rs Tightens format routing to first-arg-only and adds a regression test for the routing decision.
Review details
  • Files reviewed: 1/1 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@Tiancheng-Xu
Tiancheng-Xu force-pushed the fix/ruff-format-routing-3928 branch from 1f5dd82 to f5655e9 Compare September 8, 2026 13:12

@Protocol-zero-0 Protocol-zero-0 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The help format fix works, but matching only argv[0] introduces a regression for valid Ruff global options before the subcommand.

I compared parent f7495466 and head f5655e9a with real Ruff 0.17.0 on Linux. For a directory containing 80 Python files with x= [1,2,3]:

ruff --isolated format --check bulk
rtk ruff --isolated format --check bulk
rtk ruff --config pyproject.toml format --check bulk

Raw Ruff and the parent retain all diagnostics and the final 80 files would be reformatted summary (10,190 stdout bytes). This head emits 2,001 bytes, stopping partway through a diagnostic and losing the summary. All exit codes remain 1. The equivalent ordinary format --check bulk invocation retains the format route. The same loss occurs with --output-format=concise.

Could the routing identify the actual subcommand after supported global options, including --isolated and the value of --config, while still keeping help format out of the format filter? A regression covering a leading global option and output longer than the passthrough cap would catch the loss; the current helper-only test does not.

Validation: all 11 Ruff unit tests passed. I exercised 11 real CLI scenarios against raw/base/head, plus three concise-output comparisons: help, format/check successes and failures, version, and leading globals. help format now correctly follows the intended cap (4,884 to 2,001 bytes). Ruff 0.17.0's ordinary format output already falls back to raw output in both versions; I am not attributing that existing parser gap to this change. No source edits or full-suite/cross-platform validation were performed for this review.

@Tiancheng-Xu

Copy link
Copy Markdown
Author

Thanks for the detailed report and reproduction. I’m updating the routing to account for supported global options before the subcommand and adding regression coverage for the truncated-output case, while preserving the help format behavior. I’ll post the result once the change is verified.

@Protocol-zero-0

Copy link
Copy Markdown
Contributor

Thanks for the update. I will verify the global-option-before-subcommand path, truncated-output regression, and preserved help format behavior against the new revision once you post it.

@KuSh

KuSh commented Oct 31, 2026

Copy link
Copy Markdown
Collaborator

Thanks for this fix. #3968, merged on 2026-10-31, rewrote Ruff argument routing so the format filter applies only when format is the effective subcommand, and it pins help format and check ... format staying off that path. It also handles global flags before the subcommand, such as --config ruff.toml format. If you see a case it still gets wrong, please comment here or reopen.

@KuSh KuSh closed this Oct 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ruff filter: is_format matches a bare format token anywhere in argv, so the passthrough cap is applied inconsistently

5 participants