You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: lib/rules/no-use-v-if-with-v-for.js
+11-4
Original file line number
Diff line number
Diff line change
@@ -37,7 +37,7 @@ function getVForUsingIterationVar (vIf) {
37
37
variable.kind==='v-for'
38
38
)
39
39
if(targetVFor){
40
-
returntargetVFor.id.parent
40
+
returntargetVFor
41
41
}
42
42
}
43
43
returnundefined
@@ -76,13 +76,20 @@ module.exports = {
76
76
if(utils.hasDirective(element,'for')){
77
77
if(isUsingIterationVar(node)){
78
78
if(!allowUsingIterationVar){
79
-
constvFor=getVForUsingIterationVar(node)
79
+
constvForVar=getVForUsingIterationVar(node)
80
+
81
+
lettargetVForExpr=vForVar.id.parent
82
+
while(targetVForExpr.type!=='VForExpression'){
83
+
targetVForExpr=targetVForExpr.parent
84
+
}
85
+
constiteratorNode=targetVForExpr.right
80
86
context.report({
81
87
node,
82
88
loc: node.loc,
83
-
message: "The '{{iteratorName}}' variable inside 'v-for' directive should be replaced with a computed property that returns filtered array instead. You should not mix 'v-for' with 'v-if'.",
89
+
message: "The '{{iteratorName}}' {{kind}} inside 'v-for' directive should be replaced with a computed property that returns filtered array instead. You should not mix 'v-for' with 'v-if'.",
message: "This 'v-if' should be moved to the wrapper element.",
140
189
line: 6
141
190
}]
191
+
},
192
+
{
193
+
filename: 'test.vue',
194
+
code: '<template><div><div v-for="{x,y,z} in list" v-if="z.isActive"></div></div></template>',
195
+
errors: [{
196
+
message: "The 'list' variable inside 'v-for' directive should be replaced with a computed property that returns filtered array instead. You should not mix 'v-for' with 'v-if'.",
197
+
line: 1
198
+
}]
199
+
},
200
+
{
201
+
filename: 'test.vue',
202
+
code: `
203
+
<template>
204
+
<ul>
205
+
<li
206
+
v-for="{foo, bar, user} in users"
207
+
v-if="user.isActive"
208
+
:key="user.id"
209
+
>
210
+
{{ user.name }}
211
+
<li>
212
+
</ul>
213
+
</template>
214
+
`,
215
+
errors: [{
216
+
message: "The 'users' variable inside 'v-for' directive should be replaced with a computed property that returns filtered array instead. You should not mix 'v-for' with 'v-if'.",
217
+
line: 6
218
+
}]
219
+
},
220
+
{
221
+
filename: 'test.vue',
222
+
code: `
223
+
<template>
224
+
<ul>
225
+
<li
226
+
v-for="{foo, bar, user} in users"
227
+
v-if="shouldShowUsers"
228
+
:key="user.id"
229
+
>
230
+
{{ user.name }}
231
+
<li>
232
+
</ul>
233
+
</template>
234
+
`,
235
+
errors: [{
236
+
message: "This 'v-if' should be moved to the wrapper element.",
237
+
line: 6
238
+
}]
239
+
},
240
+
{
241
+
filename: 'test.vue',
242
+
code: '<template><div><div v-for="{x} in list()" v-if="x.isActive"></div></div></template>',
243
+
errors: [{
244
+
message: "The 'list()' expression inside 'v-for' directive should be replaced with a computed property that returns filtered array instead. You should not mix 'v-for' with 'v-if'.",
245
+
line: 1
246
+
}]
247
+
},
248
+
{
249
+
filename: 'test.vue',
250
+
code: '<template><div><div v-for="i in 5" v-if="i"></div></div></template>',
251
+
errors: [{
252
+
message: "The '5' expression inside 'v-for' directive should be replaced with a computed property that returns filtered array instead. You should not mix 'v-for' with 'v-if'.",
0 commit comments