dx fmt ignores .rustfmt.toml when formatting whole project

Open Beginner friendly
#5,631 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
74/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Quiet
Tech stack
rust

Research direction

Start in packages/cli/src/cli/autoformat.rs at the indentation_for calls on lines 56 and 90, then compare them with the whole-project path around line 175. Reproduce the behavior with a project-level .rustfmt.toml and the cargo fmt -- --print-config current commands shown in the issue. Done means dx fmt respects the project's configuration in --raw, -f file, and whole-project modes.

Written by the indexing model from the issue text.

Description

Problem

dx fmt does not pick up settings from .rustfmt.toml. RSX blocks are formatted using rustfmt defaults instead of the project's configuration.

In two places, indentation_for is called with the hardcoded string ".":

Internally, indentation_for runs cargo fmt -- --print-config current <path>. When <path> is a directory, rustfmt does not walk up to find .rustfmt.toml and falls back to defaults. When <path> is an actual file (as on L175 for the whole-project case), it works correctly.

This can be verified. For example, with hard_tabs = true in .rustfmt.toml:

# Does NOT pick up .rustfmt.toml:
cargo fmt -- --print-config current .
# → hard_tabs = false

# Correctly picks up .rustfmt.toml:
cargo fmt -- --print-config current src/main.rs
# → hard_tabs = true

May also be related to #3433.

Steps To Reproduce

  • Create a project with a .rustfmt.toml containing any non-default setting (e.g. hard_tabs = true)
  • Add a component using rsx!
  • Run dx fmt -f src/main.rs or dx fmt --raw "div {}"
  • Observe that RSX is formatted using rustfmt defaults, ignoring .rustfmt.toml

Expected behavior

dx fmt should respect .rustfmt.toml when formatting RSX blocks in all modes.

Screenshots

N/A

Environment:

  • Dioxus version: 0.7.9
  • Rust version: 1.87
  • OS info: Linux
  • App platform: web

Questionnaire

I don't have time to fix this right now, but maybe later.

Dominant language
Rust
Stars
39.2k
Forks
1.9k
Avg merge
3d 12h
Merged PRs (30d)
6

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from DioxusLabs/dioxus

All issues in DioxusLabs/dioxus

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.