Repository: DioxusLabs/dioxus

Issue #1419: Autoformatter tries to format all macros
Created: 2023-09-02T11:42:59Z
Problem
Instead of only touching rsx! and render! macros, the autoformatter tries to format all macros. This causes issues with macros that use syntax different from the rsx macros.
Steps To Reproduce
Steps to reproduce the behavior:
use dioxus::prelude::*;

fn main() {
    dioxus_web::launch(app);
}

fn app(cx: Scope) -> Element {
    let message = format!("Hello, {}!", "World");
    render!{
	message
	}
}

cargo new dioxus-broken-fmt-example
cd dioxus-broken-fmt-example
cargo add dioxus dioxus-web
copy the above code into src/main.rs
dx fmt

Expected behavior
The file should be formatted to the following:
use dioxus::prelude::*;

fn main() {
    dioxus_web::launch(app);
}

fn app(cx: Scope) -> Element {
    let message = format!("Hello, {}!", "World");
    render! {message}
}
Actual Behaviour
The dx fmt command panics:
thread 'tokio-runtime-worker' panicked at 'called `Result::unwrap()` on an `Err` value: Error("Expected Ident or Expression")', /home/deck/.local/share/cargo/registry/src/in
dex.crates.io-6f17d22bba15001f/dioxus-autofmt-0.4.0/src/lib.rs:71:50
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
error formatting file: /home/deck/Downloads/dioxus-broken-fmt-example/src/main.rs
task 7 panicked

If you change the format! macro call to format!("Hello, {0}!", "World") so that it is acceptable rsx syntax, it is formatted to format!( "Hello, {0}!", "World" ) (notice the added spaces). Dioxus should not change that macro call, and cargo fmt also reverts it to without the spaces.
Environment:

Dioxus version: v0.4.0
Rust version: rustc 1.71.1 (eb26296b5 2023-08-03)
OS info: Arch Linux
App platform: web (but should affect all platforms)

Questionnaire


 I'm interested in fixing this myself but don't know where to start
 I would like to fix and I have a solution
 I don't have time to fix this right now, but maybe later

Duplicate issue #1744:  `dx fmt` command inserts extra space before comma in tuple patterns within for loops
Created: 2023-12-23T17:21:02Z
Problem
When using the dx fmt, an extra space is inserted before the comma in tuple patterns within a for loop.
Steps To Reproduce
Steps to reproduce the behavior:

Create a Rust file with a function that includes a for loop iterating over tuples, as shown in the example below.
Run the dx fmt command on the file.
Observe that the formatted code includes an extra space before the comma in the tuple pattern.

Expected behavior
The dx fmt command should format the tuple pattern in the for loop without inserting an extra space before the comma. The expected formatted code should look like this:
fn App(cx: Scope) -> Element {
    let tuples = vec![(1, 1), (2, 2), (3, 3)];
    let triples = vec![(1, 1, 1), (2, 2, 2), (3, 3, 3)];
    cx.render(rsx! (
        for (first, second) in tuples {
            p { "{first}, {second}" }
        }
        for (first, second, third) in triples {
            p { "{first}, {second}, {third}" }
        }
    ))
}
Environment:

Dioxus version: v0.4.3
Rust version: 1.74.1
OS info: MacOS
App platform: web, fullstack

Questionnaire

 I'm interested in fixing this myself but don't know where to start
 I would like to fix and I have a solution
 I don't have time to fix this right now, but maybe later

Closing comment (2023-12-23T20:15:46Z): This looks similar to #1419. You may need to reinstall the dioxus cli. After installing the 0.4.3 version of the CLI, the example you posted is formatted correctly on my computer