Closed opensas closed 1 year ago
possible duplicate of: https://github.com/sveltejs/language-tools/issues/748
<!-- prettier-ignore -->
<svelte:head>
<script src="http://localhost:5173/dummy.js" on:load={() => console.log('script:load')} />
</svelte:head>
prevents Prettier from formatting this - this should solve your "am stuck between two things" problem.
thanks a lot for keeping an eye on this issue, I followed your advise and ended up with something like this:
[...]
const onload = () => (ready = true);
</script>
<svelte:head>
<script on:load={onload} {src} {defer}></script>
</svelte:head>
but the prettier-ignore
thing could also work
@dummdidumm just to confirm that the <!-- prettier-ignore -->
workaround didn't work
the best alternative so far is to declare a function and call it from the script tag
Describe the bug
If I create a script element with an on:load handler like this:
pnpm check
runs ok butpnpm lint
(the prettier part) complainsIf I run
pnpm format
it gets rewritten like this (couldn't find a way to tell prettier to leave that as isbut then
pnpm check
complainsAlso, running
pnpm format
once more, against what prettier already formatted, throws a similar error:I couldn't find a way to configure prettier to leave those cases untouched, and neither could find a way for
svelte-check
to understand that it's a valid statementReproduction
create a new sveltekit project
run
pnpm install
replace routes/+page.svelte` with:
run
pnpm check
(ok) runpnpm lint
(complains about prettier) runpnpm format
(prettier rewrites the code adding a</script>
runpnpm format
again -> error! runpnpm check
again -> error!Expected behavior
Either
pnpm format
formats the closing script without adding a</script>
or both prettier and svelte-check accept the<script ... on:load={...}></script>
as validSystem Info
Which package is the issue about?
prettier-plugin-svelte (also related with svelte-check)
Additional Information, eg. Screenshots
Issue first reported at svelte-check repo
I created this repo with the error
You can open it in gitpod clicking here
then run