useSelfClosingElements
¥Summary
-
规则生效日期:
v1.0.0¥Rule available since:
v1.0.0 -
诊断类别:
lint/style/useSelfClosingElements¥Diagnostic Category:
lint/style/useSelfClosingElements -
此规则包含 safe 修复程序。
¥This rule has a safe fix.
-
此规则的默认严重级别为 information。
¥The default severity of this rule is information.
-
来源:
¥Sources:
¥How to configure
{ "linter": { "rules": { "style": { "useSelfClosingElements": "error" } } }}¥Description
防止为没有子元素的组件添加额外的闭合标签。
¥Prevent extra closing tags for components without children.
没有子元素的 JSX 元素应标记为自闭合。在 JSX 中,任何元素都可以是自闭合的。
¥JSX elements without children should be marked as self-closing. In JSX, it is valid for any element to be self-closing.
¥Examples
¥Invalid
<div></div>code-block.jsx:1:1 lint/style/useSelfClosingElements FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ℹ JSX elements without children should be marked as self-closing. In JSX, it is valid for any element to be self-closing.
> 1 │ <div></div>
│ ^^^^^^^^^^^
2 │
ℹ Safe fix: Use a self-closing element instead.
1 │ - <div></div>
1 │ + <div·/>
2 2 │
<Component></Component>code-block.jsx:1:1 lint/style/useSelfClosingElements FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ℹ JSX elements without children should be marked as self-closing. In JSX, it is valid for any element to be self-closing.
> 1 │ <Component></Component>
│ ^^^^^^^^^^^^^^^^^^^^^^^
2 │
ℹ Safe fix: Use a self-closing element instead.
1 │ - <Component></Component>
1 │ + <Component·/>
2 2 │
<Foo.bar></Foo.bar>code-block.jsx:1:1 lint/style/useSelfClosingElements FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ℹ JSX elements without children should be marked as self-closing. In JSX, it is valid for any element to be self-closing.
> 1 │ <Foo.bar></Foo.bar>
│ ^^^^^^^^^^^^^^^^^^^
2 │
ℹ Safe fix: Use a self-closing element instead.
1 │ - <Foo.bar></Foo.bar>
1 │ + <Foo.bar·/>
2 2 │
¥Valid
<div /><div>child</div><Component /><Component>child</Component><Foo.bar /><Foo.bar>child</Foo.bar>¥Options
ignoreHtmlElements
Section titled “ignoreHtmlElements”默认:false
¥Default: false
此选项允许你指定是否忽略对原生 HTML 元素的检查。
¥This option allows you to specify whether to ignore checking native HTML elements.
在以下示例中,当选项设置为 “true” 时,它不会自动关闭原生 HTML 元素。
¥In the following example, when the option is set to “true”, it will not self close native HTML elements.
{ "//":"...", "options": { "ignoreHtmlElements": true }}<div></div>¥Related links
Biome v2.1 中文网 - 粤ICP备13048890号