Repository navigation
Description
The two formatter arms of rtk format inject different modes: black gets a read-only --check, ruff gets the write-mode format subcommand. Both then get a . appended. So the same bare command dry-runs in one project and rewrites the whole tree in another.
Provenance: AI-assisted source audit, human-directed, at v0.44.2 (700bdde). Reproduced by running the shipped rtk 0.44.2 with PATH stand-ins that print the argv they receive.
Observed
$ cd plain-project && rtk format # no config → ruff is the fallback
RUFF-ARGV: format .
$ cd black-project && rtk format # pyproject.toml has [tool.black]
BLACK-ARGV: --check .
The user typed neither format nor . in either case.
The code
src/cmds/system/format_cmd.rs:89-95:
// Inject --check if not present for check mode
"black" if !user_args.iter().any(|a| a == "--check" || a == "--diff") => {
cmd.arg("--check");
}
// Add "format" subcommand if not present
"ruff" if user_args.is_empty() || !user_args[0].starts_with("format") => {
cmd.arg("format");
}The black arm's own comment says "check mode" — that is clearly the intent for the command as a whole. The ruff arm adds format, which for ruff is the write subcommand; there is no --check alongside it. (ruff format --check is ruff's dry-run form.)
Then :104-106:
// Default to current directory if no path specified
if user_args.iter().all(|a| a.starts_with('-')) {
cmd.arg(".");
}Iterator::all is vacuously true on an empty iterator, so bare rtk format — no arguments at all — appends ..
Compounding it, ruff is also the fallback when no formatter is detected (:54), so a project with no formatter config at all takes the write path.
Why this is worth fixing rather than documenting
A wrapper whose purpose is reducing output should not change whether a command writes to disk. Someone running rtk format to see what would change gets a dry run on one project and a whole-tree rewrite on the next — and in the ruff case the scope is also widened from "whatever ruff's config resolves" to an explicit ..
Suggested fix (untested — no programmer has reviewed this)
Make the ruff arm match the black arm's intent: inject format --check (or check if that is the desired semantic), so both formatters are read-only by default. If write mode is wanted, it should be something the user asks for explicitly — src/cmds/php/pint_cmd.rs:41 and src/cmds/python/ruff_cmd.rs:46-50 both already distinguish read-only from write invocations and are the pattern to follow.
Separately, if user_args.iter().all(...) should probably be if user_args.is_empty() || user_args.iter().all(...) written explicitly, so the empty case is a deliberate decision rather than a property of all.
Related
Same family as the eslint --fix path injection reported in #3409 — a default path added to a command that writes. Filing separately because this one also gets the mode wrong, not just the scope.
Activity
pszymkowiak commentedon Aug 4, 2026
🔍 Automated Triage
bughighSummary
rtk format defaults to write-mode for ruff but check-mode for black, and the empty-args '.' path widens scope on a write command — fix ruff arm to inject '--check' (or equivalent read-only mode) to match black's behavior.
📁 Relevant files
src/cmds/system/format_cmd.rssrc/cmds/php/pint_cmd.rssrc/cmds/python/ruff_cmd.rsTriaged automatically by wshm · This is an automated analysis, not a human review.
nightcityblade commentedon Aug 9, 2026
Hi, I'd like to work on this. I'll submit a PR shortly.
HetCreep commentedon Aug 9, 2026
Sounds good — go for it. Happy to take a look once the PR is up.