You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/rules/html-self-closing.md
+35-21
Original file line number
Diff line number
Diff line change
@@ -14,10 +14,10 @@ since: 'v2.5.0'
14
14
15
15
## :book: Rule Details
16
16
17
-
You can choose either two styles for elements without content
17
+
You can choose either two styles for elements without content.
18
18
19
-
- always: `<div />`
20
-
- never: `<div></div>`
19
+
- always: `<SomeComponent />`
20
+
- never: `<SomeComponent></SomeComponent>`
21
21
22
22
<!-- prettier-ignore-start -->
23
23
<!--eslint-skip-->
@@ -28,18 +28,21 @@ You can choose either two styles for elements without content
28
28
</script>
29
29
30
30
<!-- ✓ GOOD -->
31
-
<div />
32
31
<p>Hello</p>
33
-
<div><div /></div>
32
+
<div></div>
34
33
<img />
35
34
<svelte:head />
35
+
<svg><path /></svg>
36
+
<math><msup></msup></math>
37
+
<SomeComponent />
36
38
37
39
<!-- ✗ BAD -->
38
-
<div></div>
39
-
<p> </p>
40
-
<div><div></div></div>
41
-
<img>
40
+
<div />
41
+
<div><div /></div>
42
42
<svelte:body></svelte:body>
43
+
<svg><path></path></svg>
44
+
<math><msup /></math>
45
+
<SomeComponent></SomeComponent>
43
46
```
44
47
45
48
<!-- prettier-ignore-end -->
@@ -52,7 +55,7 @@ presets:
52
55
{
53
56
"svelte/html-self-closing": [
54
57
"error",
55
-
"all"// or "html" or "none"
58
+
"default"// or "all" or "html" or "none"
56
59
]
57
60
}
58
61
```
@@ -65,8 +68,9 @@ config object:
65
68
"error",
66
69
{
67
70
"void":"always", // or "never" or "ignore"
68
-
"normal":"always", // or "never" or "ignore"
69
-
"foreign":"always", // or "never" or "ignore"
71
+
"normal":"never", // or "always" or "ignore"
72
+
"svg":"always", // or "never" or "ignore"
73
+
"never":"never", // or "always" or "ignore"
70
74
"component":"always", // or "never" or "ignore"
71
75
"svelte":"always"// or "never" or "ignore"
72
76
}
@@ -76,23 +80,33 @@ config object:
76
80
77
81
presets:
78
82
79
-
-`all` - all elements should be self closing (unless they have children)
80
-
-`html` - html-compliant - only void elements and svelte special elements should be self closing
81
-
-`none` - no elements should be self closing
83
+
-`default` - MathML and non-void HTML elements should have a closing tag; otherwise, they should be self-closing.
84
+
-`all` - all elements should be self-closing (unless they have children)
85
+
-`html` - html-compliant - only void elements and svelte special elements should be self-closing
86
+
-`none` - no elements should be self-closing
87
+
88
+
::: warning Note
89
+
We recommend selecting `default` as the preset. Choosing any other option may result in settings that are inconsistent with the compiler when using Svelte5.
90
+
:::
82
91
83
92
config object:
84
93
85
94
-`void` (`"always"` in default preset)... Style of HTML void elements
86
-
-`foreign` (`"always"` in default preset)... Style of foreign elements (SVG and MathML)
95
+
-`normal` (`"never"` in default preset)... Style of other elements
96
+
-`svg` (`"always"` in default preset)... Style of SVG
97
+
-`math` (`never` in default preset)... Style of MathML
87
98
-`component` (`"always"` in default preset)... Style of svelte components
88
99
-`svelte` (`"always"` in default preset)... Style of svelte special elements (`<svelte:head>`, `<svelte:self>`)
89
-
-`normal` (`"always"` in default preset)... Style of other elements
90
100
91
-
Every config oject option can be set to
101
+
::: warning
102
+
`foreign` is removed in `eslint-plugin-svelte` v3.
103
+
:::
104
+
105
+
Every config object option can be set to
92
106
93
-
- "always" (`<div />`)
94
-
- "never" (`<div></div>`)
95
-
- "ignore" (either `<div />` or `<div></div>`)
107
+
- "always" (`<SomeComponent />`)
108
+
- "never" (`<SomeComponent></SomeComponent>`)
109
+
- "ignore" (either `<SomeComponent />` or `<SomeComponent></SomeComponent>`)
Copy file name to clipboardExpand all lines: packages/eslint-plugin-svelte/tests/fixtures/rules/html-self-closing/invalid/foreign-never/svelte-never-errors.yaml
Copy file name to clipboardExpand all lines: packages/eslint-plugin-svelte/tests/fixtures/rules/html-self-closing/invalid/presets/html/preset-html-errors.yaml
+2-2
Original file line number
Diff line number
Diff line change
@@ -10,11 +10,11 @@
10
10
line: 5
11
11
column: 18
12
12
suggestions: null
13
-
- message: Require self-closing on foreign (SVG or MathML) elements.
13
+
- message: Require self-closing on SVG elements.
14
14
line: 6
15
15
column: 13
16
16
suggestions: null
17
-
- message: Require self-closing on foreign (SVG or MathML) elements.
17
+
- message: Disallow self-closing on MathML elements.
Copy file name to clipboardExpand all lines: packages/eslint-plugin-svelte/tests/fixtures/rules/html-self-closing/invalid/presets/html/preset-html-input.svelte
Copy file name to clipboardExpand all lines: packages/eslint-plugin-svelte/tests/fixtures/rules/html-self-closing/invalid/presets/html/preset-html-output.svelte
Copy file name to clipboardExpand all lines: packages/eslint-plugin-svelte/tests/fixtures/rules/html-self-closing/invalid/presets/none/preset-none-errors.yaml
+2-2
Original file line number
Diff line number
Diff line change
@@ -10,11 +10,11 @@
10
10
line: 5
11
11
column: 8
12
12
suggestions: null
13
-
- message: Disallow self-closing on foreign (SVG or MathML) elements.
13
+
- message: Disallow self-closing on SVG elements.
14
14
line: 6
15
15
column: 14
16
16
suggestions: null
17
-
- message: Disallow self-closing on foreign (SVG or MathML) elements.
17
+
- message: Disallow self-closing on MathML elements.
0 commit comments