fix(cli): respect .rustfmt.toml in dx fmt --raw and -f modes#5632
Open
costajohnt wants to merge 1 commit into
Open
fix(cli): respect .rustfmt.toml in dx fmt --raw and -f modes#5632costajohnt wants to merge 1 commit into
costajohnt wants to merge 1 commit into
Conversation
`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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
dx fmtignored.rustfmt.tomlfor RSX blocks in--rawand-f file/stdinmodes (#5631).
indentation_forwas called with the"."directory, andrustfmt's
--print-config current <path>only walks up to.rustfmt.tomlwhengiven 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 representativeproject
.rsfile (mirroring the whole-project path), or"."when theproject has none.
Verification
In a project with
.rustfmt.tomlcontaininghard_tabs = true:dx fmt -f src/main.rsanddx fmt --raw "..."formatted RSX withspaces (rustfmt defaults).
Added a unit test for the path-selection fallback.
cargo fmt --check,cargo clippy, and the autoformat tests pass.Fixes #5631