Skip to content

Commit bf85163

Browse files
authored
Update: disallow v-show on <template> tag (#1451)
1 parent ff8cfaa commit bf85163

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

docs/rules/valid-v-show.md

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ This rule reports `v-show` directives in the following cases:
2020
- The directive has that argument. E.g. `<div v-show:aaa></div>`
2121
- The directive has that modifier. E.g. `<div v-show.bbb></div>`
2222
- The directive does not have that attribute value. E.g. `<div v-show></div>`
23+
- The directive is put on `<template>` tag. E.g. `<template v-show="condition" />`
2324

2425
<eslint-code-block :rules="{'vue/valid-v-show': ['error']}">
2526

@@ -32,6 +33,7 @@ This rule reports `v-show` directives in the following cases:
3233
<div v-show/>
3334
<div v-show:aaa="foo"/>
3435
<div v-show.bbb="foo"/>
36+
<template v-show="condition" />
3537
</template>
3638
```
3739

lib/rules/valid-v-show.js

+7
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,13 @@ module.exports = {
5252
message: "'v-show' directives require that attribute value."
5353
})
5454
}
55+
if (node.parent.parent.name === 'template') {
56+
context.report({
57+
node,
58+
loc: node.loc,
59+
message: "'v-show' directives cannot be put on <template> tags."
60+
})
61+
}
5562
}
5663
})
5764
}

tests/lib/rules/valid-v-show.js

+10
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,16 @@ tester.run('valid-v-show', rule, {
6363
filename: 'empty-value.vue',
6464
code: '<template><div v-show=""></div></template>',
6565
errors: ["'v-show' directives require that attribute value."]
66+
},
67+
{
68+
filename: 'test.vue',
69+
code: '<template><template v-show="condition"></template></template>',
70+
errors: ["'v-show' directives cannot be put on <template> tags."]
71+
},
72+
{
73+
filename: 'test.vue',
74+
code: '<template><template v-show="condition" /></template>',
75+
errors: ["'v-show' directives cannot be put on <template> tags."]
6676
}
6777
]
6878
})

0 commit comments

Comments
 (0)