Skip to content

Update: disallow v-show on <template> tag #1451

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/rules/valid-v-show.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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."]
}
]
})