src/content/docs/linter/rules/use-self-closing-elements.mdx
import { Tabs, TabItem } from '@astrojs/starlight/components';
<Tabs> <TabItem label="JavaScript (and super languages)" icon="seti:javascript"> ## Summary - Rule available since: `v1.0.0` - Diagnostic Category: [`lint/style/useSelfClosingElements`](/reference/diagnostics#diagnostic-category) - This rule isn't recommended, so you need to enable it. - This rule has a [**safe**](/linter/#safe-fixes) fix. - The default severity of this rule is [**information**](/reference/diagnostics#information). - Sources: - Same as [`@stylistic/jsx-self-closing-comp`](https://eslint.style/rules/default/jsx-self-closing-comp){
"linter": {
"rules": {
"style": {
"useSelfClosingElements": "error"
}
}
}
}
Prevent extra closing tags for components without children.
JSX elements without children should be marked as self-closing. In JSX, it is valid for any element to be self-closing.
<div></div>
<Component></Component>
<Foo.bar></Foo.bar>
<div />
<div>child</div>
<Component />
<Component>child</Component>
<Foo.bar />
<Foo.bar>child</Foo.bar>
ignoreHtmlElementsDefault: false
This option allows you to specify whether to ignore checking native HTML elements.
In the following example, when the option is set to "true", it will not self close native HTML elements.
{
"//":"...",
"options": {
"ignoreHtmlElements": true
}
}
<div></div>