DioxusLabs / DioxusLabs/dioxus

`dx fmt` formating is not accepted by `cargo fmt --check`

Open
#3,433 2 comments 0 reactions 0 assignees View on GitHub
autoformatting bug cli
Dominant language
Rust
Stars
39.1k
Forks
1.9k
Avg merge
4d 10h
Merged PRs (30d)
4

Description

**Problem**
The formatting which is created by `dx fmt` is not accepted by ` cargo fmt --check`.

**Steps To Reproduce**

Steps to reproduce the behavior:
create a new dioxus project with the following `main.rs`
```rust
use dioxus::prelude::*;

fn main() {
dioxus::launch(App);
}

enum BookType {
AudioBook,
EBook,
}

#[component]
fn App() -> Element {
let value = BookType::AudioBook;
rsx! {
"hello world"
match value {
BookType::AudioBook => rsx! {
div { "audio icon eeeeeeeeeeeeeeeeeeeeeeeeee" }
},
BookType::EBook => rsx! {
div { "book icon eeeeeeeeeeeeeeeeeeeeeeeeeee" }
},
}
}
}
```
the code was formatted with `cargo fmt` and the following `rustfmt.toml` config:
```toml
edition = "2021"

hard_tabs = true
tab_spaces = 4
```
run `dx fmt` and you get the follwing code:
```rust
use dioxus::prelude::*;
fn main() {
dioxus::launch(App);
}
enum BookType {
AudioBook,
EBook,
}
#[component]
fn App() -> Element {
let value = BookType::AudioBook;
rsx! {
"hello world"
match value {
BookType::AudioBook => rsx! {
div { "audio icon eeeeeeeeeeeeeeeeeeeeeeeeee" }
},
BookType::EBook => rsx! {
div { "book icon eeeeeeeeeeeeeeeeeeeeeeeeeee" }
},
}
}
}

```
This code has 2 tabs and 4 space in front of the `BookType` instead of 3 tabs.
```
❯ cargo fmt --check
Diff in /home/lukas/git/dx-fmt-test/src/main.rs:15:
rsx! {
"hello world"
match value {
- BookType::AudioBook => rsx! {
+ BookType::AudioBook => rsx! {
div { "audio icon eeeeeeeeeeeeeeeeeeeeeeeeee" }
},
- BookType::EBook => rsx! {
+ BookType::EBook => rsx! {
div { "book icon eeeeeeeeeeeeeeeeeeeeeeeeeee" }
},
}

❯ echo $?
1
```

**Expected behavior**
* Create code with 3 spaces in front of `BookType`
* Create code which is accepted by `cargo fmt --check`

**Screenshots**

**Additional Information**
I use `dx fmt` and `cargo +nightly fmt` both for formatting, since dx did not support the nightly features of `cargo fmt`.
Running `dx fmt` even **without** `--all-code` did change a lot `cargo fmt` nightly formatting.
So i regular run `dx fmt` first and then `cargo +nightly fmt` to be able to format rsx and get the cargo fmt nightly features.
To check if the code is formatted i run the following commands at the CI:
```yml
- run: cargo +nightly fmt --all -- --check
- run: cargo +stable fmt --all
- run: dx fmt --check
```
However this fail because `dx fmt` format the at different way as `cargo fmt`.

**Environment:**
- Dioxus version: dioxus 0.6.1 (was built without git repository)
- Rust version: rustc 1.83.0 (90b35a623 2024-11-26)
- OS info: Arch linux
- App platform: web (but the others should be affected too)

**Questionnaire**

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.