@@ -8,12 +8,32 @@ In Vue.js template, we can use either two styles for elements which don't have t
8
8
1 . ` <YourComponent></YourComponent> `
9
9
2 . ` <YourComponent/> ` (self-closing)
10
10
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.
13
13
14
- ## Rule Details
14
+ ## : book : Rule Details
15
15
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
17
37
18
38
``` json
19
39
{
@@ -41,28 +61,27 @@ Every option can be set to one of the following values:
41
61
- ` "never" ` ... Disallow self-closing.
42
62
- ` "any" ` ... Don't enforce self-closing style.
43
63
44
- ----
64
+ ### ` {html: {normal: "never", void: "always"}} `
45
65
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'}}]} " >
54
67
```
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>
63
81
```
82
+ </eslint-code-block >
64
83
65
- ## Related links
84
+ ## : books : Further reading
66
85
67
86
- [ Style guide - Self closing components] ( https://vuejs.org/v2/style-guide/#Self-closing-components-strongly-recommended )
68
87
0 commit comments