Skip to content

fix(ruff): keep ruff's statistics table for check --statistics - #4731

Open
umi008 wants to merge 1 commit into
rtk-ai:developfrom
umi008:fix/ruff-statistics-table
Open

umi008 wants to merge 1 commit into
rtk-ai:developfrom
umi008:fix/ruff-statistics-table

Conversation

@umi008

@umi008 umi008 commented Oct 21, 2026

Copy link
Copy Markdown

Summary

  • rtk ruff check --statistics no longer injects --output-format=json. The statistics output goes to passthrough, so it matches ruff's own table byte for byte (80 B in my repro, same exit code). It used to be pretty-printed JSON that the diagnostics filter could not parse.
  • The same applies when the user passes --output-format=json together with --statistics. That output is a statistics array, not diagnostics, so it passes through instead of reaching filter_ruff_check_json.
  • --statistics is detected with arg_tokenizer::tokenize, so a path after -- or a flag's value spelled --statistics doesn't trigger it.
  • A plain rtk ruff check is unchanged: JSON is injected and the output is filtered.

Closes #4701

Test plan

  • Four unit tests on the new check_format decision. statistics_keeps_ruffs_own_format failed before the fix, and the others pin the existing behaviour.
  • Manual: rtk ruff check --statistics against ruff 0.15.12 gives the same table as native.
  • cargo fmt --all && cargo clippy --all-targets && cargo test --all: fmt is clean, clippy gives 0 warnings, all 22 ruff tests pass, and the other failures are listed below.

All checks ran on Windows 11 with cargo +1.99.0. The remaining test failures also fail on unmodified develop (5ab6291) on that machine:

  • find_cmd::run_from_args_propagates_find_exit_status and core::stream::test_read_lines_lossy_preserves_lines_after_invalid_utf8 fail on every run.
  • rewrite_shell_wrapper_test fails intermittently, on a different test each run.
  • a_clustered_h_is_answered_by_git_once fails on develop too.

a_wrapped_tools_own_help_survives_rtk was skipped because it opens browser tabs on Windows (#4728).

Important: All PRs must target the develop branch (not master).
See CONTRIBUTING.md for details.

@rtk-wshm-sync-bot rtk-wshm-sync-bot Bot added area:cli bug Something isn't working ruff labels Oct 21, 2026
@rtk-wshm-sync-bot

Copy link
Copy Markdown

wshm · Automated triage by AI

📊 Automated PR Analysis

🐛 Type bug-fix
🟢 Risk low

Summary

Fixes rtk ruff check --statistics so the statistics table/array passes through unmodified instead of being mangled by rtk's JSON injection and diagnostics filter, which could not parse it. Uses the existing arg_tokenizer to robustly detect the --statistics flag (ignoring values after -- or flag arguments that merely contain the string), leaving plain check and user-specified --output-format behavior unchanged.

Review Checklist

  • Tests present
  • Breaking change
  • Docs updated

Linked issues: #4701


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

@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.

Independently checked 0f786e17 against develop 5ab62913 with real Ruff 0.17.0 on Linux. The default check --statistics table now matches native stdout byte for byte; the base injects JSON instead. Explicit JSON (both spellings), full/concise, empty results, --exit-zero, rule selection, quiet mode, a path-first implicit check, a file named format, and help also preserve native statistics output in the tested cases. The path-first shorthand was compared with native ruff check plus the same arguments.

23 scenarios / 69 native-base-head processes: exit codes match throughout. Ordinary diagnostics, clean runs, explicit diagnostic JSON, an attached --cache-dir=--statistics value and flag-first routing retain base behavior. Missing values, invalid statistics values and duplicate formats still reject with exit 2; the invalid-statistics usage text now also matches native Ruff. The 22 Ruff unit tests, fmt and warnings-denied all-target clippy pass.

One inherited boundary remains separate: check -- --statistics (a filename) adds . and scans extra files on both base and head. This change correctly avoids treating that filename as the statistics flag; it does not repair the added-dot behavior. No full-suite, other-platform or pending-PR integration claim. No blocker found for this scoped statistics fix.

@umi008
umi008 force-pushed the fix/ruff-statistics-table branch from 0f786e1 to af052f7 Compare October 31, 2026 15:55
rtk injected --output-format=json into every `ruff check` where the user
chose no format. With --statistics ruff then prints a statistics array
instead of diagnostics, which filter_ruff_check_json cannot read, so the
JSON came back as-is: larger than ruff's own table and in a different
shape.

Detect --statistics through the argument tokenizer, so a path after `--`
or an attached value is not mistaken for the flag. When present, leave
the format to ruff and pass the output through, also when the user asked
for JSON themselves.

Closes rtk-ai#4701
@umi008
umi008 force-pushed the fix/ruff-statistics-table branch from af052f7 to e44d906 Compare November 28, 2026 23:03
@umi008

umi008 commented Nov 28, 2026

Copy link
Copy Markdown
Author

Rebased onto current develop (e44d906) to clear the conflict in src/cmds/python/ruff_cmd.rs. The only change from the approved commit: has_flag now takes a &Grammar instead of a Dialect (from b1cb395), so has_statistics_flag passes a local flag-free POSIX grammar. Behavior is unchanged: the ruff tests (44) pass, cargo fmt --check and cargo clippy --all-targets -- -D warnings are clean. Two failures in tests/git_log_cap_notice_test.rs reproduce on plain develop too, so they are not from this PR.

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 ruff

Projects

None yet

Development

Successfully merging this pull request may close these issues.

rtk ruff check --statistics prints ruff's statistics JSON instead of its table, larger than ruff's own output

2 participants