Skip to content

fix(cli): respect .rustfmt.toml in dx fmt --raw and -f modes#5632

Open
costajohnt wants to merge 1 commit into
DioxusLabs:mainfrom
costajohnt:fix/fmt-respect-rustfmt-toml
Open

fix(cli): respect .rustfmt.toml in dx fmt --raw and -f modes#5632
costajohnt wants to merge 1 commit into
DioxusLabs:mainfrom
costajohnt:fix/fmt-respect-rustfmt-toml

Conversation

@costajohnt

Copy link
Copy Markdown
Contributor

Problem

dx fmt ignored .rustfmt.toml for RSX blocks in --raw and -f file/stdin
modes (#5631). indentation_for was called with the "." directory, and
rustfmt's --print-config current <path> only walks up to .rustfmt.toml when
given a concrete file, not a directory, so those modes silently used defaults.
The whole-project path already passed a real file and worked correctly.

Fix

  • -f file: pass the input file itself so rustfmt resolves the nearest config.
  • --raw / stdin: no input file exists, so fall back to a representative
    project .rs file (mirroring the whole-project path), or "." when the
    project has none.

Verification

In a project with .rustfmt.toml containing hard_tabs = true:

  • Before: dx fmt -f src/main.rs and dx fmt --raw "..." formatted RSX with
    spaces (rustfmt defaults).
  • After: both produce tab-indented RSX.

Added a unit test for the path-selection fallback. cargo fmt --check,
cargo clippy, and the autoformat tests pass.

Fixes #5631

`dx fmt` ignored `.rustfmt.toml` for RSX blocks in `--raw` and `-f file`/stdin
modes because `indentation_for` was called with the `"."` directory. rustfmt's
`--print-config current <path>` only walks up to `.rustfmt.toml` when given a
concrete file, not a directory, so those modes silently fell back to defaults.

Pass the input file itself for `-f file`, and a representative project `.rs`
file (mirroring the existing whole-project path) for the file-less `--raw` and
stdin modes, falling back to `"."` when the project has none.

Fixes DioxusLabs#5631
@costajohnt costajohnt requested a review from a team as a code owner June 17, 2026 05:08
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.

dx fmt ignores .rustfmt.toml when formatting whole project

1 participant