sveltejs / prettier-plugin-svelte

Format your svelte components using prettier.
MIT License
735 stars 95 forks source link

Quotes are broken inside directives #457

Closed rChaoz closed 1 month ago

rChaoz commented 1 month ago

With attributes such as 'class' this works fine:

<!-- stays the same after formatting -->
<Component class="my-class {condition ? 'a' : 'b'}" />

But it fails with directives, such as:

<Component style:transform="translateX({condition ? '10%' : '20%'})" />

gets formatted to

<Component style:transform="translateX({condition ? "10%" : "20%"})" />

which breaks the code because of the quotes.

Workaround

Use raw strings instead, which are kept as-is:

<Component style:transform="translateX({condition ? `10%` : `20%`})" />