withastro / prettier-plugin-astro

Prettier plugin for Astro
Other
475 stars 33 forks source link

🐛 BUG: Fragment is moved if it wraps a component #416

Open AlphaJack opened 4 months ago

AlphaJack commented 4 months ago

Describe the Bug

It seems that wrapping a component within causes the formatter to move at the end of the parent element, breaking the structure.

Steps to Reproduce

npm init astro using template any

<BaseLayout>
    <Fragment slot="AdditionalSEO">
        <Problem>
     </Fragment>
    <header>
    </header>
    <article>
    </article>
</BaseLayout>

Wrong result:

<BaseLayout>
  <Fragment slot="AdditionalSEO">
    <Problem />
    <header></header>
    <article></article>
  </Fragment></BaseLayout
>

Expected result:

<BaseLayout>
  <Fragment slot="AdditionalSEO"> <Problem /> </Fragment>
  <header></header>
  <article></article>
</BaseLayout>

With text it works:

<BaseLayout>
    <Fragment slot="AdditionalSEO">
        Not a problem
     </Fragment>
    <header>
    </header>
    <article>
    </article>
</BaseLayout>

...

<BaseLayout>
  <Fragment slot="AdditionalSEO"> Not a problem </Fragment>
  <header></header>
  <article></article>
</BaseLayout>
horo-fox commented 2 months ago

This is just a prettier configuration thing I think. Try "bracketSameLine": true in your .prettierrc. Note that this configuration doesn't work within braces, which is annoying.