DioxusLabs / DioxusLabs/dioxus

dx fmt adds indent to eval JS content

Open
#4,507 0 comments 1 reaction 0 assignees View on GitHub
autoformatting bug
Dominant language
Rust
Stars
39.1k
Forks
1.9k
Avg merge
4d 10h
Merged PRs (30d)
4

Description

**Problem**

Each time I run `dx fmt` indentation is added to the JS within an eval call.

**Steps To Reproduce**

Steps to reproduce the behavior:

```
# Use all barebones options
dx new fmt_err
```

Replace the generated Hero rsx!() with an eval that has multi-line JS:
```rust
#[component]
pub fn Hero() -> Element {
rsx! {
div {
onmounted: move |_| async move {
let eval = document::eval(
r#"
console.log('eval line 1');
console.log('eval line 2');
"#,
)
.await;
if let Err(err) = eval {
println!("eval {err}")
}
},
}
}
}
```

Run `dx fmt`, notice that the JS now has indentation:

```rust
#[component]
pub fn Hero() -> Element {
rsx! {
div {
onmounted: move |_| async move {
let eval = document::eval(
r#"
console.log('eval line 1');
console.log('eval line 2');
"#,
)
.await;
if let Err(err) = eval {
println!("eval {err}")
}
},
}
}
}

```

Run `dx fmt` again, more indentation is added:

```rust
#[component]
pub fn Hero() -> Element {
rsx! {
div {
onmounted: move |_| async move {
let eval = document::eval(
r#"
console.log('eval line 1');
console.log('eval line 2');
"#,
)
.await;
if let Err(err) = eval {
println!("eval {err}")
}
},
}
}
}
```

**Expected behavior**

`dx fmt` should not alter indentation of content within eval, especially if it is within r#""#

**Environment:**

- Dioxus version: v0.6.3
- Rust version: 1.88.0
- OS info: Ubuntu 24
- App platform: Android

**Questionnaire**

I could help to fix if someone can give me an idea of where to look for the issue.

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.