Skip to content

dx fmt ignores .rustfmt.toml when formatting whole project #5631

Description

@timothee-haudebourg

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions