# 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 -->
<div
Require self-closing on HTML elements. (svelte/html-self-closing)
></div>
<p
Require self-closing on HTML elements. (svelte/html-self-closing)
> </p>
<div><div
Require self-closing on HTML elements. (svelte/html-self-closing)
></div>
</div>
<img
Require self-closing on HTML void elements. (svelte/html-self-closing)
>
<svelte:body
Require 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 closing
  • none - no elements should be self closing

config object:

  • void ("always" in default preset)… Style of HTML void elements
  • foreign ("always" in default preset)… Style of foreign elements (SVG and MathML)
  • component ("always" in default preset)… Style of svelte components
  • svelte ("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

# πŸ” Implementation