sveltejs / prettier-plugin-svelte

Format your svelte components using prettier.
MIT License
745 stars 97 forks source link

Extra whitespace in class attributes should be removed. #339

Closed ptrxyz closed 1 year ago

ptrxyz commented 1 year ago

Consider the following piece of HTML:

<div class="something        else"></div>

If this code is inside an .svelte file, prettier does not remove the extra whitespace in the class attribute, however if it's inside a .html file, prettier will indeed remove them (in accordance to prettier's docs).

To reproduce, follow this minimal example:

pnpm create svelte@latest demo
cd demo
pnpm i

I think the formatting should be consistent, no matter if the class attribute is inside a .svelte file or inside a .html file.

ptrxyz commented 1 year ago

As far as I can tell, in https://github.com/sveltejs/prettier-plugin-svelte/blob/3a353abcc3667659c087a70569a21f03b9424894/src/lib/elements.ts#L61-L65 formatting of attributes is intentionally turned off to be consistent with prettier's default behavior. This is not the case (anymore) with latest prettier:

Without any configuration, prettier turns this:

<html>
    <body>
        <div class="some     thing"></div>
    </body>
</html>

into this:

<html>
    <body>
        <div class="some thing"></div>
    </body>
</html>

For that reason, I would advocate to stay consistent with prettier and turn on class formatting by simply adding "class" to formattableAttributes.