-
-
Notifications
You must be signed in to change notification settings - Fork 681
/
Copy pathvalid-v-else-if.js
123 lines (120 loc) · 4.13 KB
/
valid-v-else-if.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/**
* @author Toru Nagashima
* @copyright 2017 Toru Nagashima. All rights reserved.
* See LICENSE file in root directory for full license.
*/
'use strict'
const RuleTester = require('../../eslint-compat').RuleTester
const rule = require('../../../lib/rules/valid-v-else-if')
const tester = new RuleTester({
languageOptions: { parser: require('vue-eslint-parser'), ecmaVersion: 2015 }
})
tester.run('valid-v-else-if', rule, {
valid: [
{
filename: 'test.vue',
code: ''
},
{
filename: 'test.vue',
code: '<template><div><div v-if="foo"></div><div v-else-if="foo"></div></div></template>'
},
{
filename: 'test.vue',
code: '<template><div><div v-if="foo"></div><div v-else-if="foo"></div><div v-else-if="foo"></div></div></template>'
},
{
filename: 'test.vue',
code: `<template>\n <c1 v-if="1" />\n <c2 v-else-if="1" />\n <c3 v-else />\n</template>`
},
// parsing error
{
filename: 'parsing-error.vue',
code: '<template><div v-if="foo"></div><div v-else-if="."></div></template>'
},
// comment value (parsing error)
{
filename: 'comment-value.vue',
code: '<template><div v-if="foo"></div><div v-else-if="/**/"></div></template>'
}
],
invalid: [
{
filename: 'test.vue',
code: '<template><template v-else-if="foo"><div></div></template></template>',
errors: [
"'v-else-if' directives require being preceded by the element which has a 'v-if' or 'v-else-if' directive."
]
},
{
filename: 'test.vue',
code: '<template><div v-else-if="foo"></div></template>',
errors: [
"'v-else-if' directives require being preceded by the element which has a 'v-if' or 'v-else-if' directive."
]
},
{
filename: 'test.vue',
code: '<template><div><div v-else-if="foo"></div></div></template>',
errors: [
"'v-else-if' directives require being preceded by the element which has a 'v-if' or 'v-else-if' directive."
]
},
{
filename: 'test.vue',
code: '<template><div><div></div><div v-else-if="foo"></div></div></template>',
errors: [
"'v-else-if' directives require being preceded by the element which has a 'v-if' or 'v-else-if' directive."
]
},
{
filename: 'test.vue',
code: '<template><div><div if="foo"></div><div v-else-if="foo"></div></div></template>',
errors: [
"'v-else-if' directives require being preceded by the element which has a 'v-if' or 'v-else-if' directive."
]
},
{
filename: 'test.vue',
code: '<template><div><div v-if="foo"></div><div></div><div v-else-if="foo"></div></div></template>',
errors: [
"'v-else-if' directives require being preceded by the element which has a 'v-if' or 'v-else-if' directive."
]
},
{
filename: 'test.vue',
code: '<template><div><div v-if="foo"></div><div v-else-if="foo" v-if="bar"></div></div></template>',
errors: [
"'v-else-if' and 'v-if' directives can't exist on the same element."
]
},
{
filename: 'test.vue',
code: '<template><div><div v-if="foo"></div><div v-else-if="foo" v-else></div></div></template>',
errors: [
"'v-else-if' and 'v-else' directives can't exist on the same element."
]
},
{
filename: 'test.vue',
code: '<template><div><div v-if="foo"></div><div v-else-if:aaa="foo"></div></div></template>',
errors: ["'v-else-if' directives require no argument."]
},
{
filename: 'test.vue',
code: '<template><div><div v-if="foo"></div><div v-else-if.aaa="foo"></div></div></template>',
errors: ["'v-else-if' directives require no modifier."]
},
{
filename: 'test.vue',
code: '<template><div><div v-if="foo"></div><div v-else-if></div></div></template>',
errors: ["'v-else-if' directives require that attribute value."]
},
// empty value
{
filename: 'empty-value.vue',
code: '<template><div v-if="foo"></div><div v-else-if=""></div></template>',
errors: ["'v-else-if' directives require that attribute value."]
}
]
})