Closed ptrxyz closed 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
.
Consider the following piece of HTML:
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:
edit
src/app.html
to contain the following line somewhere inside the<body>
tag:edit
src/routes/+page.svelte
to contain the same line somewhere.run:
pnpm run format
check
app.html
and find the class attribute value formatted, no extra whitespaces.check
src/routes/+page.svelte
and find the class attribute value NOT formatted. Extra whitespaces everywhere.I think the formatting should be consistent, no matter if the class attribute is inside a
.svelte
file or inside a.html
file.