bram209 / leptosfmt

A formatter for the leptos view! macro
Apache License 2.0
271 stars 29 forks source link

leptosfmt removes comment in body of `view!` macro. #157

Open bobhy opened 3 days ago

bobhy commented 3 days ago

Probably related to #155 ... In my scenario, leptosfmt is simply removing a comment. version 0.1.32

before:

#[test]
fn test_s2() {
    #[component]
    pub fn App() -> impl IntoView {
        view! {
            // ANCHOR: s2
            <Routes fallback=|| "Not found.">
                <Route path=path!("/") view=Home />
                <ParentRoute path=path!("/users") view=Users>
                    <Route path=path!(":id") view=UserProfile />
                </ParentRoute>
                <Route path=path!("/*any") view=|| view! { <h1>"Not Found"</h1> } />
            </Routes>
            // ANCHOR_END: s2
        }
    }
}

after:

#[test]
fn test_s2() {
    #[component]
    pub fn App() -> impl IntoView {
        view! {
            // ANCHOR: s2
            <Routes fallback=|| "Not found.">
                <Route path=path!("/") view=Home />
                <ParentRoute path=path!("/users") view=Users>
                    <Route path=path!(":id") view=UserProfile />
                </ParentRoute>
                <Route path=path!("/*any") view=|| view! { <h1>"Not Found"</h1> } />
            </Routes>
        }
    }
}

This is bad because rustdoc depends on the comment being where it is to properly format a code snippet for my doc book.

It doesn't matter whether the comment is // xxx or /* xxx */. If I move the comment just outside the closing } of the view macro, it is left alone.