pageClass | sidebarDepth | title | description | since |
---|---|---|---|---|
rule-details |
0 |
svelte/html-self-closing |
enforce self-closing style |
v2.5.0 |
enforce self-closing style
- 🔧 The
--fix
option on the command line can automatically fix some of the problems reported by this rule.
You can choose either two styles for elements without content
- always:
<div />
- never:
<div></div>
<script>
/* eslint svelte/html-self-closing: "error" */
</script>
<!-- ✓ GOOD -->
<div />
<p>Hello</p>
<div><div /></div>
<img />
<svelte:head />
<!-- ✗ BAD -->
<div></div>
<p> </p>
<div><div></div></div>
<img>
<svelte:body></svelte:body>
presets:
config object:
{
"svelte/html-self-closing": [
"error",
{
"void": "always", // or "never" or "ignore"
"normal": "always", // or "never" or "ignore"
"foreign": "always", // or "never" or "ignore"
"component": "always", // or "never" or "ignore"
"svelte": "always" // or "never" or "ignore"
}
]
}
presets:
all
- all elements should be self closing (unless they have children)html
- html-compliant - only void elements and svelte special elements should be self closingnone
- no elements should be self closing
config object:
void
("always"
in default preset)... Style of HTML void elementsforeign
("always"
in default preset)... Style of foreign elements (SVG and MathML)component
("always"
in default preset)... Style of svelte componentssvelte
("always"
in default preset)... Style of svelte special elements (<svelte:head>
,<svelte:self>
)normal
("always"
in default preset)... Style of other elements
Every config oject option can be set to
- "always" (
<div />
) - "never" (
<div></div>
) - "ignore" (either
<div />
or<div></div>
)
This rule was introduced in eslint-plugin-svelte v2.5.0