Skip to content

Commit 4d885d3

Browse files
author
perrysong
committed
fix(valid-template-root): add test option ignoreOnlyIfDirective is true
1 parent c019c6e commit 4d885d3

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

docs/rules/valid-template-root.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ title: vue/valid-template-root
55
description: enforce valid template root
66
since: v3.11.0
77
---
8+
89
# vue/valid-template-root
910

1011
> enforce valid template root
@@ -48,7 +49,7 @@ This rule reports the template root in the following cases:
4849
}
4950
```
5051

51-
- `ignoreOnlyIfDirective` (`boolean`) ... ignore the root elements and only have the `v-if` directive. Default is `true`.
52+
- `ignoreOnlyIfDirective` (`boolean`) ... don't report root elements with the `v-if` directive. Default is `true`.
5253

5354
## :rocket: Version
5455

tests/lib/rules/valid-template-root.js

+14-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ tester.run('valid-template-root', rule, {
9898
{
9999
filename: 'test.vue',
100100
code: '<template><template></template></template>'
101-
}
101+
},
102102
{
103103
filename: 'test.vue',
104104
options: [{ ignoreOnlyIfDirective: false }],
@@ -108,6 +108,11 @@ tester.run('valid-template-root', rule, {
108108
filename: 'test.vue',
109109
options: [{ ignoreOnlyIfDirective: false }],
110110
code: '<template> <div v-if="loading"></div><div v-else></div></template>'
111+
},
112+
{
113+
filename: 'test.vue',
114+
options: [{ ignoreOnlyIfDirective: true }],
115+
code: '<template> <div v-if="loading"></div></div></template>'
111116
}
112117
],
113118
invalid: [
@@ -135,6 +140,14 @@ tester.run('valid-template-root', rule, {
135140
code: '<template><div v-if="foo"></div></template>',
136141
options: [{ ignoreOnlyIfDirective: false }],
137142
errors: ['`v-if` should not be used on root element without `v-else`.']
143+
},
144+
{
145+
filename: 'test.vue',
146+
code: '<template src="foo.html"><div></div></template>',
147+
options: [{ ignoreOnlyIfDirective: true }],
148+
errors: [
149+
"The template root with 'src' attribute is required to be empty."
150+
]
138151
}
139152
]
140153
})

0 commit comments

Comments
 (0)