Skip to content

Commit fe78932

Browse files
committed
update html-self-closing
1 parent 03f7c96 commit fe78932

File tree

1 file changed

+41
-22
lines changed

1 file changed

+41
-22
lines changed

docs/rules/html-self-closing.md

Lines changed: 41 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,32 @@ In Vue.js template, we can use either two styles for elements which don't have t
88
1. `<YourComponent></YourComponent>`
99
2. `<YourComponent/>` (self-closing)
1010

11-
Self-closing is simple and shorter, but it's not supported in raw HTML.
12-
This rule helps you to unify the self-closing style.
11+
Self-closing is simple and shorter, but it's not supported in the HTML spec.
12+
This rule helps you to make consistent on the self-closing style.
1313

14-
## Rule Details
14+
## :book: Rule Details
1515

16-
This rule has options which specify self-closing style for each context.
16+
This rule aims to enforce the self-closing sign as the configured style.
17+
18+
<eslint-code-block :rules="{'vue/html-self-closing': ['error']}">
19+
```
20+
<template>
21+
<!-- ✓ GOOD -->
22+
<div/>
23+
<img>
24+
<MyComponent/>
25+
<svg><path d=""/></svg>
26+
27+
<!-- ✗ BAD -->
28+
<div></div>
29+
<img/>
30+
<MyComponent></MyComponent>
31+
<svg><path d=""></path></svg>
32+
</template>
33+
```
34+
</eslint-code-block>
35+
36+
## :wrench: Options
1737

1838
```json
1939
{
@@ -41,28 +61,27 @@ Every option can be set to one of the following values:
4161
- `"never"` ... Disallow self-closing.
4262
- `"any"` ... Don't enforce self-closing style.
4363

44-
----
64+
### `{html: {normal: "never", void: "always"}}`
4565

46-
:-1: Examples of **incorrect** code for this rule:
47-
48-
```html
49-
<div></div>
50-
<img/>
51-
<img></img>
52-
<MyComponent/></MyComponent>
53-
<svg><path d=""></path></svg>
66+
<eslint-code-block :rules="{'vue/html-self-closing': ['error', {html: {normal: 'never', void: 'always'}}]}">
5467
```
55-
56-
:+1: Examples of **correct** code for this rule:
57-
58-
```html
59-
<div/>
60-
<img>
61-
<MyComponent/>
62-
<svg><path d=""/></svg>
68+
<template>
69+
<!-- ✓ GOOD -->
70+
<div></div>
71+
<img/>
72+
<MyComponent/>
73+
<svg><path d=""/></svg>
74+
75+
<!-- ✗ BAD -->
76+
<div/>
77+
<img>
78+
<MyComponent></MyComponent>
79+
<svg><path d=""></path></svg>
80+
</template>
6381
```
82+
</eslint-code-block>
6483

65-
## Related links
84+
## :books: Further reading
6685

6786
- [Style guide - Self closing components](https://vuejs.org/v2/style-guide/#Self-closing-components-strongly-recommended)
6887

0 commit comments

Comments
 (0)