leptosfmt icon indicating copy to clipboard operation
leptosfmt copied to clipboard

Bug: leptosfmt produces invalid code

Open alisterd51 opened this issue 1 month ago • 0 comments

Version:

leptosfmt 0.1.33

Input code:

#[derive(Copy, Clone, Debug, PartialEq, Eq)]
struct Counter {
    id: usize,
    count: RwSignal<i32>,
}

#[component]
fn DynamicList(counters: RwSignal<Vec<Counter>>) -> impl IntoView {
    view! {
        <ForEnumerate
            each=move || counters.get()
            key=|counter| counter.id
            children={move |index: ReadSignal<usize>, counter: Counter| {
                view! {
                    <button>{move || index.get()} ". Value: " {move || counter.count.get()}</button>
                }
            }}
        />
    }
}

Formatted output (invalid):

#[derive(Copy, Clone, Debug, PartialEq, Eq)]
struct Counter {
    id: usize,
    count: RwSignal<i32>,
}

#[component]
fn DynamicList(counters: RwSignal<Vec<Counter>>) -> impl IntoView {
    view! {
        <ForEnumerate
            each=move || counters.get()
            key=|counter| counter.id
            children=move |index: ReadSignal<usize>, counter: Counter| {
                view! {
                    <button>{move || index.get()} ". Value: " {move || counter.count.get()}</button>
                }
            }
        />
    }
}

Problem:

leptosfmt removes the braces around the children block, changing:

children={move |...|}

to

children=move |...|

This causes a compilation error because children expects a block expression enclosed in {}.

Expected behavior:

leptosfmt should preserve the braces around the children expression to maintain valid syntax.

alisterd51 avatar Nov 11 '25 16:11 alisterd51