# 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></div>
<p> </p>
<div><div></div></div>
<img>
<svelte:body></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