-
-
Notifications
You must be signed in to change notification settings - Fork 681
/
Copy pathvalid-template-root.js
136 lines (131 loc) · 4.07 KB
/
valid-template-root.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
124
125
126
127
128
129
130
131
132
133
134
135
136
/**
* @author Toru Nagashima
* @copyright 2017 Toru Nagashima. All rights reserved.
* See LICENSE file in root directory for full license.
*/
'use strict'
// ------------------------------------------------------------------------------
// Requirements
// ------------------------------------------------------------------------------
const RuleTester = require('eslint').RuleTester
const rule = require('../../../lib/rules/valid-template-root')
// ------------------------------------------------------------------------------
// Tests
// ------------------------------------------------------------------------------
const tester = new RuleTester({
parser: 'vue-eslint-parser',
parserOptions: { ecmaVersion: 2015 }
})
tester.run('valid-template-root', rule, {
valid: [
{
filename: 'test.vue',
code: ''
},
{
filename: 'test.vue',
code: '<template><div>abc</div></template>'
},
{
filename: 'test.vue',
code: '<template>\n <div>abc</div>\n</template>'
},
{
filename: 'test.vue',
code: '<template>\n <!-- comment -->\n <div>abc</div>\n</template>'
},
{
filename: 'test.vue',
code: '<template>\n <!-- comment -->\n <div v-if="foo">abc</div>\n <div v-else>abc</div>\n</template>'
},
{
filename: 'test.vue',
code: '<template>\n <!-- comment -->\n <div v-if="foo">abc</div>\n <div v-else-if="bar">abc</div>\n <div v-else>abc</div>\n</template>'
},
{
filename: 'test.vue',
code: `<template>\n <c1 v-if="1" />\n <c2 v-else-if="1" />\n <c3 v-else />\n</template>`
},
{
filename: 'test.vue',
code: '<template><div v-if="foo"></div></template>'
},
{
filename: 'test.vue',
code: '<template><div v-if="foo"></div><div v-else-if="bar"></div></template>'
},
{
filename: 'test.vue',
code: '<template src="foo.html"></template>'
},
{
filename: 'test.vue',
code: '<template><div><textarea/>test</div></template>'
},
{
filename: 'test.vue',
code: '<template><table><custom-thead></custom-thead></table></template>'
},
{
filename: 'test.vue',
code: '<template lang="pug">test</template>'
}
],
invalid: [
{
filename: 'test.vue',
code: '<template>\n</template>',
errors: ['The template root requires exactly one element.']
},
{
filename: 'test.vue',
code: '<template><div></div><div></div></template>',
errors: ['The template root requires exactly one element.']
},
{
filename: 'test.vue',
code: '<template>\n <div></div>\n <div></div>\n</template>',
errors: ['The template root requires exactly one element.']
},
{
filename: 'test.vue',
code: '<template>{{a b c}}</template>',
errors: ['The template root requires an element rather than texts.']
},
{
filename: 'test.vue',
code: '<template><div></div>aaaaaa</template>',
errors: ['The template root requires an element rather than texts.']
},
{
filename: 'test.vue',
code: '<template>aaaaaa<div></div></template>',
errors: ['The template root requires an element rather than texts.']
},
{
filename: 'test.vue',
code: '<template><div v-for="x in list"></div></template>',
errors: ["The template root disallows 'v-for' directives."]
},
{
filename: 'test.vue',
code: '<template><slot></slot></template>',
errors: ["The template root disallows '<slot>' elements."]
},
{
filename: 'test.vue',
code: '<template><template></template></template>',
errors: ["The template root disallows '<template>' elements."]
},
{
filename: 'test.vue',
code: '<template src="foo.html">abc</template>',
errors: ["The template root with 'src' attribute is required to be empty."]
},
{
filename: 'test.vue',
code: '<template src="foo.html"><div></div></template>',
errors: ["The template root with 'src' attribute is required to be empty."]
}
]
})