Skip to content

Commit 73a9dd4

Browse files
HerringtonDarkholmemysticatea
authored andcommitted
Fix: require-v-for-key shouldn't be raised on slots (fixes #216)(#223)
1 parent 43f248b commit 73a9dd4

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

lib/rules/require-v-for-key.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const utils = require('../utils')
2121
* @param {ASTNode} element The element node to check.
2222
*/
2323
function checkKey (context, element) {
24-
if (element.name === 'template') {
24+
if (element.name === 'template' || element.name === 'slot') {
2525
for (const child of element.children) {
2626
if (child.type === 'VElement') {
2727
checkKey(context, child)

tests/lib/rules/require-v-for-key.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,14 @@ tester.run('require-v-for-key', rule, {
4242
{
4343
filename: 'test.vue',
4444
code: '<template><div><template v-for="x in list"><div :key="x"></div></template></div></template>'
45+
},
46+
{
47+
filename: 'test.vue',
48+
code: '<template><div><slot v-for="x in list" :name="x"></slot></div></template>'
49+
},
50+
{
51+
filename: 'test.vue',
52+
code: '<template><div><slot v-for="x in list" :name="x"><div :key="x"></div></slot></div></template>'
4553
}
4654
],
4755
invalid: [
@@ -59,6 +67,11 @@ tester.run('require-v-for-key', rule, {
5967
filename: 'test.vue',
6068
code: '<template><div><template v-for="x in list"><div></div></template></div></template>',
6169
errors: ["Elements in iteration expect to have 'v-bind:key' directives."]
70+
},
71+
{
72+
filename: 'test.vue',
73+
code: '<template><div><slot v-for="x in list" :name="x"><div></div></slot></div></template>',
74+
errors: ["Elements in iteration expect to have 'v-bind:key' directives."]
6275
}
6376
]
6477
})

0 commit comments

Comments
 (0)