-
-
Notifications
You must be signed in to change notification settings - Fork 681
/
Copy pathno-use-v-else-with-v-for.js
44 lines (41 loc) · 1.27 KB
/
no-use-v-else-with-v-for.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
'use strict'
const { defineTemplateBodyVisitor, hasDirective } = require('../utils')
module.exports = {
meta: {
type: 'suggestion',
docs: {
description:
'disallow using `v-else-if`/`v-else` on the same element as `v-for`',
categories: null,
url: 'https://eslint.vuejs.org/rules/no-use-v-else-with-v-for.html'
},
fixable: null,
schema: [],
messages: {
unexpectedDirectiveWithVFor:
'Unexpected `{{ directiveName }}` and `v-for` on the same element. Move `{{ directiveName }}` to a wrapper element instead.'
}
},
/** @param {RuleContext} context */
create(context) {
return defineTemplateBodyVisitor(context, {
/** @param {VDirective} node */
"VAttribute[directive=true][key.name.name='for']"(node) {
const element = node.parent.parent
if (hasDirective(element, 'else-if')) {
context.report({
node: element,
messageId: 'unexpectedDirectiveWithVFor',
data: { directiveName: 'v-else-if' }
})
} else if (hasDirective(element, 'else')) {
context.report({
node: element,
messageId: 'unexpectedDirectiveWithVFor',
data: { directiveName: 'v-else' }
})
}
}
})
}
}