Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default options for valid-compile and html-self-closing have conflicting opinions on <textarea> elements #950

Open
2 tasks done
scottohara opened this issue Dec 3, 2024 · 0 comments

Comments

@scottohara
Copy link

Before You File a Bug Report Please Confirm You Have Done The Following...

  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.

What version of ESLint are you using?

9.16.0

What version of eslint-plugin-svelte are you using?

2.46.1

What did you do?

Configuration
"svelte/valid-compile": "error"
"svelte/html-self-closing": "error"
<textarea rows="10" bind:value={$value}></textarea>

What did you expect to happen?

No errors.

The <textarea> element is non-void and as such needs a closing tag, and should not be self-closing.

What actually happened?

When a <textarea> element has a closing tag:

<textarea rows="10" bind:value={$value}></textarea>

...the html-self-closing rule reports:

error  Require self-closing on HTML elements  svelte/html-self-closing

This is because the default preset for that rule sets all element types (void, normal, foreign, component, svelte) to "always".


If you follow the above advice and change it to be self-closing:

<textarea rows="10" bind:value={$value} />

...the valid-compile rule reports:

error  Self-closing HTML tags for non-void elements are ambiguous — use `<textarea ...></textarea>` rather than `<textarea ... />

If you relax the html-self-closing options to "normal": "never", that does satisfy both rules.

However, any other non-void, normal, self-closing elements (that valid-compile doesn't complain about) now need to be changed to have closing tags (<slot></slot>).


I'm not sure what the right answer here is, but it seems that the out-of-box experience for these two rules could be improved to avoid such conflicting advice.
Suggest either:

  1. Changing the default preset for html-self-closing to set "normal": "never" to align the guidance for <textarea> elements to match the valid-compile rule, or
  2. Changing the valid-compile rule not to warn on self-closing <textarea/> elements in the same way that it doesn't warn on self-closing <slot/> elements, or
  3. Changing the valid-compile rule to warn on self-closing <slot/> elements in the same way that it warns on self-closing <textarea/> elements.

Link to GitHub Repo with Minimal Reproducible Example

https://eslint-online-playground.netlify.app/#eNp1kMFuwyAQRH9ltccotturm+TUvwg5ELx2aTEgwGmqyP/eNSZSKyUXbLRvmNm5YQyqoascvaE6XsgkwhZ3UQXt00FYAEMJLtJM9CbsrikDAGH5muiaZCAJwX3HvcDXF4Fw1rZrs2J/y5+5OeAWKRptU62c7fVQf0a20aN3IcFqC31wI4jCVd5Mg7bVOhPI5sLSNfMd9XIyCY5LvLouscvL8SiwNzI1ZxlZd9ou0G05AHptKLasw82m2RTdnQEIUx4XmFfElWh4C91Vyo2eHxDYLilDcEFgUf5hP9Joqkimr5RxUdvhH7/ic5Yt54n34m68VF9yIG7FWe4lJxCYfnxxG13H2YqdwI4u7+TJdmSVprgwJfS9vlXGNVDk/5LyWbcP0UfDnFrYGedfCOi9RA==

(Note: I can't get the issue to reproduce in the online playground link above, but then again I can't get any eslint-plugin-svelte warnings to show in the playground?)

Additional comments

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant