DioxusLabs / DioxusLabs/dioxus

dx fmt ignores .rustfmt.toml when formatting whole project

Open
#5,631 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
39.1k
Forks
1.9k
Avg merge
4d 10h
Merged PRs (30d)
4

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 `"."`:

- [autoformat.rs#L56](https://github.com/DioxusLabs/dioxus/blob/b00ff7525901984f3a07fa5cfa175b537b64630b/packages/cli/src/cli/autoformat.rs#L56) (`--raw` mode)
- [autoformat.rs#L90](https://github.com/DioxusLabs/dioxus/blob/b00ff7525901984f3a07fa5cfa175b537b64630b/packages/cli/src/cli/autoformat.rs#L90) (`-f file` mode)

Internally, `indentation_for` runs `cargo fmt -- --print-config current `. When `` is a directory, rustfmt does not walk up to find `.rustfmt.toml` and falls back to defaults. When `` is an actual file (as on [L175](https://github.com/DioxusLabs/dioxus/blob/b00ff7525901984f3a07fa5cfa175b537b64630b/packages/cli/src/cli/autoformat.rs#L175) for the whole-project case), it works correctly.

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

```sh
# 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.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.