Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autoformatter tries to format all macros #1419

Closed
1 of 3 tasks
RubixDev opened this issue Sep 2, 2023 · 2 comments · Fixed by #1420
Closed
1 of 3 tasks

Autoformatter tries to format all macros #1419

RubixDev opened this issue Sep 2, 2023 · 2 comments · Fixed by #1420
Labels
autoformatting Related to the autofmt crate bug Something isn't working

Comments

@RubixDev
Copy link

RubixDev commented Sep 2, 2023

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
@ealmloff ealmloff added bug Something isn't working autoformatting Related to the autofmt crate labels Sep 2, 2023
@srid
Copy link
Contributor

srid commented Oct 5, 2023

e799c2e appears to be in tag 0.4.1, which is what I have:

❯ dx --version
dioxus 0.4.1

But I still get this error for the use of println! in https://github.com/srid/dioxus-desktop-template/pull/6/files#diff-87619baf236177a7a9fc38150961151b7583b6f2f082ade75915f3ac4ca49c41

image
❯ find src -name \*.rs | xargs -n 1 dx fmt -f
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Error("Expected Ident or Expression")', /private/tmp/nix-build-dioxus-cli-0.4.1.drv-0/dioxus-cli-0.4.1-vendor.tar.gz/dioxus-autofmt/src/lib.rs:71:50
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
formatted src/main.rs

@ealmloff
Copy link
Member

ealmloff commented Oct 6, 2023

e799c2e appears to be in tag 0.4.1, which is what I have:

❯ dx --version
dioxus 0.4.1

But I still get this error for the use of println! in https://github.com/srid/dioxus-desktop-template/pull/6/files#diff-87619baf236177a7a9fc38150961151b7583b6f2f082ade75915f3ac4ca49c41

image ``` ❯ find src -name \*.rs | xargs -n 1 dx fmt -f thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Error("Expected Ident or Expression")', /private/tmp/nix-build-dioxus-cli-0.4.1.drv-0/dioxus-cli-0.4.1-vendor.tar.gz/dioxus-autofmt/src/lib.rs:71:50 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace formatted src/main.rs ```

I just installed the 0.4.1 version of the CLI from crates.io and it seems to format println! correctly:

pub async fn test(){
    println!("hello");
}

(no dioxus.toml)

You can try installing the git version of the CLI with this command:

cargo install --git https://github.com/DioxusLabs/dioxus

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
autoformatting Related to the autofmt crate bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants