# svelte/html-self-closing
enforce self-closing style
- π§ The
--fix
option on the command line can automatically fix some of the problems reported by this rule.
# π Rule Details
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 -->
<divRequire self-closing on HTML elements. (svelte/html-self-closing)></div>
<pRequire self-closing on HTML elements. (svelte/html-self-closing)> </p>
<div><divRequire self-closing on HTML elements. (svelte/html-self-closing)></div></div>
<imgRequire self-closing on HTML void elements. (svelte/html-self-closing)>
<svelte:bodyRequire self-closing on Svelte special elements. (svelte/html-self-closing)></svelte:body>
# π§ Options
presets:
{
"svelte/html-self-closing": [
"error",
"all" // or "html" or "none"
]
}
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>
)
# π Version
This rule was introduced in eslint-plugin-svelte v2.5.0