bram209 / leptosfmt

A formatter for the leptos view! macro
Apache License 2.0
274 stars 30 forks source link

bug when if else clause is used within view! #71

Closed gitmalong closed 1 year ago

gitmalong commented 1 year ago
% leptosfmt .
❌ target/debug/build/selectors-8cba0d9c59eafdd9/out/ascii_case_insensitive_html_attributes.rs
                could not parse file

 view! { cx,

  {move || {
          if var().len() > 0 {
              view! { cx,
                  <p></p>
              }
                  .into_view(cx)
          } else {
              ().into_view(cx)
          }
      }}
}
bram209 commented 1 year ago

when I try to format the above snippet, it works fine for me?

The following test passes:

    #[test]
    fn github_issue_71() {
        let source = indoc! {r#"
            fn main() {
                view! { cx,
                    {move || {
                            if var().len() > 0 {
                                view! { cx,
                                    <p></p>
                                }
                                    .into_view(cx)
                            } else {
                                ().into_view(cx)
                            }
                        }}
                  }
            }
        "#};

        let result = format_file_source(
            source,
            FormatterSettings {
                max_width: 60,
                ..Default::default()
            },
        )
        .unwrap();

        insta::assert_snapshot!(result, @r###"
        fn main() {
            view! { cx,
                {move || {
                    if var().len() > 0 {
                        view! { cx, <p></p> }.into_view(cx)
                    } else {
                        ().into_view(cx)
                    }
                }}
            }
        }
        "###);
    }
bram209 commented 1 year ago

also could not parse file indicates that your rust code was not parsable. Please make sure that your code compiles before running the formatter if this error occurs. I guess that you have a syntax error somewhere.

Closing this issue, but feel free te reopen if you still think that this is a leptosfmt bug.