Closed mmanrai closed 3 weeks ago
I can reproduce this on c71652c1209367846864b3c2d7dc52fdcf37bd0e
and it also seems to affect match
expressions.
use leptos::*;
fn main() {
mount_to_body(|| {
view! {
{move || {
match true {
true => {
view! {
// comment in if condition.
<div>dummy text</div>
}
.into_view()
}
false => {
view! {
// comment in else condition.
<div>dummy text</div>
}
.into_view()
}
}
}}
}
})
}
Formats to:
use leptos::*;
fn main() {
mount_to_body(|| {
view! {
{move || {
match true {
true => {
view! {
// comment in if condition.
<div>dummy text</div>
}
.into_view()
}
false => {
view! {
// comment in if condition.
// comment in else condition.
<div>dummy text</div>
}
.into_view()
}
}
}}
}
})
}
Consecutive runs inserts another copy of the comment. After three runs:
use leptos::*;
fn main() {
mount_to_body(|| {
view! {
{move || {
match true {
true => {
view! {
// comment in if condition.
<div>dummy text</div>
}
.into_view()
}
false => {
view! {
// comment in if condition.
// comment in if condition.
// comment in if condition.
// comment in else condition.
<div>dummy text</div>
}
.into_view()
}
}
}}
}
})
}
Thanks for creating leptosfmt
! I hope these details are helpful.
Thank you @bram209, I've tested the fix and can confirm it works!
Thanks for letting me know :)
I've encountered an issue where leptosfmt incorrectly copies a comment from the if block into the else block when formatting code.
Code Example:
Before running leptosfmt:
After running leptosfmt:
Notice how '// comment in if condition' is copied over to else block.