Skip to content

Commit

Permalink
Update: disallow v-show on <template> tag (#1451)
Browse files Browse the repository at this point in the history
  • Loading branch information
g-plane committed Mar 22, 2021
1 parent ff8cfaa commit bf85163
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
2 changes: 2 additions & 0 deletions docs/rules/valid-v-show.md
Expand Up @@ -20,6 +20,7 @@ This rule reports `v-show` directives in the following cases:
- The directive has that argument. E.g. `<div v-show:aaa></div>`
- The directive has that modifier. E.g. `<div v-show.bbb></div>`
- The directive does not have that attribute value. E.g. `<div v-show></div>`
- The directive is put on `<template>` tag. E.g. `<template v-show="condition" />`

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

Expand All @@ -32,6 +33,7 @@ This rule reports `v-show` directives in the following cases:
<div v-show/>
<div v-show:aaa="foo"/>
<div v-show.bbb="foo"/>
<template v-show="condition" />
</template>
```

Expand Down
7 changes: 7 additions & 0 deletions lib/rules/valid-v-show.js
Expand Up @@ -52,6 +52,13 @@ module.exports = {
message: "'v-show' directives require that attribute value."
})
}
if (node.parent.parent.name === 'template') {
context.report({
node,
loc: node.loc,
message: "'v-show' directives cannot be put on <template> tags."
})
}
}
})
}
Expand Down
10 changes: 10 additions & 0 deletions tests/lib/rules/valid-v-show.js
Expand Up @@ -63,6 +63,16 @@ tester.run('valid-v-show', rule, {
filename: 'empty-value.vue',
code: '<template><div v-show=""></div></template>',
errors: ["'v-show' directives require that attribute value."]
},
{
filename: 'test.vue',
code: '<template><template v-show="condition"></template></template>',
errors: ["'v-show' directives cannot be put on <template> tags."]
},
{
filename: 'test.vue',
code: '<template><template v-show="condition" /></template>',
errors: ["'v-show' directives cannot be put on <template> tags."]
}
]
})

0 comments on commit bf85163

Please sign in to comment.