breaking: new options, deprecate svelteStrictMode
#379I tried both of these options to stop that behaviour :
"svelte.plugin.svelte.format.config.svelteStrictMode": true,
"svelte.plugin.html.completions.enable": false
With "svelte.plugin.svelte.format.config.svelteStrictMode": true
, <div></div>
does not become <div />
when saving.
But <Container></Container>
will still become <Container />
I tried to disable other html formatting but couldn't find any option that prevents self-closing of Svelte components
Given the following example:
<input {value} on:input="{(ev) => console.log(ev.currentTarget.value)}" />
Formatting with strict mode turned off will result in the following output:
<input {value} on:input={(ev) => console.log(ev.currentTarget.value)} />
While having it on will result in the following output:
<input value="{value}" on:input="{(ev) => console.log(ev.currentTarget.value)}" />
Now my editor plugin that handles svelte syntax highlighting (emacs web-mode) is an ungodly mess of spaghetti code and regexes and doesn't like unquoted curly braces so I'd like to enforce quotes around them, while still using shorthand attributes and self-closing tags where strict mode wouldn't allow them. Can an option be added that enables just the quoting behavior from strict mode?
Hello,
I think when the html tag is empty, it should use self-closing on format.
When I'm writing code, sometimes I write just boilerplate of HTML tags before I implement any styles and it's kinda annoying that it's closing empty elements, and to be honest it doesn't really make sense...
If the tag is not empty and contains any attribute so I believe self-closing will be the right way to go for e.g.
<div class="a" /> ✅
<div /> ❌
<div></div> ✅
Thanks!
Write any HTML tag and save the file I use Prettier for formatting, and auto-format on save
No response
System:
OS: macOS 10.15.5
CPU: (12) x64 Intel(R) Xeon(R) CPU X5690 @ 3.47GHz
Memory: 2.86 GB / 48.00 GB
Shell: 5.7.1 - /bin/zsh
Binaries:
Node: 16.13.2 - ~/.nvm/versions/node/v16.13.2/bin/node
npm: 8.1.2 - ~/.nvm/versions/node/v16.13.2/bin/npm
Browsers:
Chrome: 100.0.4896.75
Firefox: 98.0.2
Firefox Developer Edition: 98.0
Safari: 13.1.1
npmPackages:
svelte: ^3.44.0 => 3.46.6
annoyance
Remove the "always quote things" option because it's technically invalid: sveltejs/svelte#7925 This means we should likely deprecate the strict mode option altogether in favor of a more fine grained set of options around self closing tags, shorthand props etc.
svelteSelfCloseComponents
and svelteSelfCloseElements
to specify whether or not empty elements/components should self-close. svelteStrictMode
no longer has any effect on this behavior.
<div></div>
it stays as this, and if the user says <div />
that also stays like this. This is what Prettier currently does in both HTML and JSXsvelteAllowShorthand
now takes precedence over svelteStrictMode
, which no longer has any effect on that behaviorsvelteStrictMode
is deprecated as future Svelte versions might coerce numbers coming from mustache tags inside strings into stringscloses #348 closes #284 closes #279 closes #238 related to #377
To summarize what I said in Discord:
I don't think we should have either svelteSelfCloseComponents
or svelteSelfCloseElements
as options.
For elements, I think we should either leave them as the user wrote them, or else rewrite them according to whether they're a valid void element in HTML (even though the Svelte compiler doesn't care about that). I don't have a strong opinion one way or the other.
For components, leaving it as the user wrote it would probably be fine, if that's what Prettier does for JSX.
refactor: Remove deprecated concat
Remove Concat node checks
Updates the code base to using prettier v3. This required a refactoring of embeds since the call timing is now different
Co-authored-by: Simon H 5968653+dummdidumm@users.noreply.github.com Co-authored-by: Rolaka hyperion.neil@gmail.com Co-authored-by: Simon Holthausen simon.holthausen@vercel.com
svelteSelfCloseComponents
and svelteSelfCloseElements
to specify whether or not empty elements/components should self-close. svelteStrictMode
no longer has any effect on this behavior - svelteAllowShorthand
now takes precedence over svelteStrictMode
, which no longer has any effect on that behavior - svelteStrictMode
is deprecated as future Svelte versions might coerce numbers coming from mustache tags inside strings into strings closes #348 closes #284 closes #279 closes #238 related to #377