@@ -39,98 +39,72 @@ function makeError (line) {
39
39
}
40
40
}
41
41
42
- // ------------------------------------------------------------------------------
43
- // Tests
44
- // ------------------------------------------------------------------------------
45
-
46
- const ruleTester = new RuleTester ( )
47
- ruleTester . run ( 'return-in-computed-property' , rule , {
48
-
49
- valid : [
50
- {
51
- filename : 'test.js' ,
52
- code : `export default { }` ,
53
- parserOptions
54
- } ,
55
- {
56
- filename : 'test.js' ,
57
- code : `const foo = {}` ,
58
- parserOptions
59
- } ,
42
+ function notFoundTests ( ext ) {
43
+ return [
60
44
{
61
- filename : ' test.js' ,
45
+ filename : ` test.${ ext } ` ,
62
46
code : `export const foo = {}` ,
63
47
parserOptions
64
48
} ,
65
49
{
66
- filename : ' test.js' ,
67
- code : `var foo = {}` ,
50
+ filename : ` test.${ ext } ` ,
51
+ code : `export var foo = {}` ,
68
52
parserOptions
69
53
} ,
70
54
{
71
- filename : ' test.js' ,
72
- code : `foo({ }) ` ,
55
+ filename : ` test.${ ext } ` ,
56
+ code : `const foo = {} ` ,
73
57
parserOptions
74
58
} ,
75
59
{
76
- filename : ' test.js' ,
77
- code : `Vue.component('async-example', function (resolve, reject) { }) ` ,
60
+ filename : ` test.${ ext } ` ,
61
+ code : `var foo = {} ` ,
78
62
parserOptions
79
63
} ,
80
64
{
81
- filename : ' test.vue' ,
82
- code : `export const a = { }` ,
65
+ filename : ` test.${ ext } ` ,
66
+ code : `let foo = {}` ,
83
67
parserOptions
84
68
} ,
85
69
{
86
- filename : ' test.vue' ,
70
+ filename : ` test.${ ext } ` ,
87
71
code : `foo({ })` ,
88
72
parserOptions
89
73
} ,
90
74
{
91
- filename : ' test.vue' ,
75
+ filename : ` test.${ ext } ` ,
92
76
code : `foo(() => { return {} })` ,
93
77
parserOptions
94
78
} ,
95
79
{
96
- filename : ' test.jsx' ,
80
+ filename : ` test.${ ext } ` ,
97
81
code : `Vue.component('async-example', function (resolve, reject) { })` ,
98
82
parserOptions
99
83
} ,
100
84
{
101
- filename : 'test.jsx' ,
102
- code : `export const a = { }` ,
103
- parserOptions
104
- } ,
105
- {
106
- filename : 'test.jsx' ,
107
- code : `foo({ })` ,
108
- parserOptions
109
- } ,
110
- {
111
- filename : 'test.jsx' ,
112
- code : `foo(() => { return {} })` ,
85
+ filename : `test.${ ext } ` ,
86
+ code : `Vue.component('async-example', function (resolve, reject) { resolve({}) })` ,
113
87
parserOptions
114
88
} ,
115
89
{
116
- filename : ' test.js' ,
90
+ filename : ` test.${ ext } ` ,
117
91
code : `new Vue({ })` ,
118
92
parserOptions
119
93
} ,
120
94
{
121
- filename : 'test.jsx' ,
122
- code : `new Vue({ })` ,
123
- parserOptions
124
- } ,
125
- {
126
- filename : 'test.vue' ,
127
- code : `new Vue({ })` ,
95
+ filename : `test.${ ext } ` ,
96
+ code : `{
97
+ foo: {}
98
+ }` ,
128
99
parserOptions
129
100
}
130
- ] ,
131
- invalid : [
101
+ ]
102
+ }
103
+
104
+ function foundTests ( ext ) {
105
+ return [
132
106
{
133
- filename : ' test.vue' ,
107
+ filename : ` test.${ ext } ` ,
134
108
code : `Vue.component('async-example', function (resolve, reject) {
135
109
// @vue/component
136
110
resolve({})
@@ -139,39 +113,27 @@ ruleTester.run('return-in-computed-property', rule, {
139
113
errors : [ makeError ( 2 ) ]
140
114
} ,
141
115
{
142
- filename : ' test.js' ,
116
+ filename : ` test.${ ext } ` ,
143
117
code : `Vue.component({})` ,
144
118
parserOptions,
145
119
errors : [ makeError ( 1 ) ]
146
120
} ,
147
121
{
148
- filename : 'test.vue' ,
149
- code : `export default { }` ,
150
- parserOptions,
151
- errors : [ makeError ( 1 ) ]
152
- } ,
153
- {
154
- filename : 'test.jsx' ,
155
- code : `export default { }` ,
156
- parserOptions,
157
- errors : [ makeError ( 1 ) ]
158
- } ,
159
- {
160
- filename : 'test.js' ,
122
+ filename : `test.${ ext } ` ,
161
123
code : `// @vue/component
162
124
export default { }` ,
163
125
parserOptions,
164
126
errors : [ makeError ( 2 ) ]
165
127
} ,
166
128
{
167
- filename : ' test.js' ,
129
+ filename : ` test.${ ext } ` ,
168
130
code : `/* @vue/component */
169
131
export default { }` ,
170
132
parserOptions,
171
133
errors : [ makeError ( 2 ) ]
172
134
} ,
173
135
{
174
- filename : ' test.js' ,
136
+ filename : ` test.${ ext } ` ,
175
137
code : `
176
138
/*
177
139
* @vue/component
@@ -181,7 +143,7 @@ ruleTester.run('return-in-computed-property', rule, {
181
143
errors : [ makeError ( 5 ) ]
182
144
} ,
183
145
{
184
- filename : ' test.js' ,
146
+ filename : ` test.${ ext } ` ,
185
147
code : `// @vue/component
186
148
export default { }
187
149
// @vue/component
@@ -190,7 +152,7 @@ ruleTester.run('return-in-computed-property', rule, {
190
152
errors : [ makeError ( 2 ) , makeError ( 4 ) ]
191
153
} ,
192
154
{
193
- filename : ' test.js' ,
155
+ filename : ` test.${ ext } ` ,
194
156
code : `/* @vue/component */
195
157
export const a = { }
196
158
/* @vue/component */
@@ -199,23 +161,23 @@ ruleTester.run('return-in-computed-property', rule, {
199
161
errors : [ makeError ( 2 ) , makeError ( 4 ) ]
200
162
} ,
201
163
{
202
- filename : ' test.js' ,
164
+ filename : ` test.${ ext } ` ,
203
165
code : `export default { }
204
166
// @vue/component
205
167
export let b = { }` ,
206
168
parserOptions,
207
169
errors : [ makeError ( 3 ) ]
208
170
} ,
209
171
{
210
- filename : ' test.js' ,
172
+ filename : ` test.${ ext } ` ,
211
173
code : `let b = { }
212
174
// @vue/component
213
175
export let b = { }` ,
214
176
parserOptions,
215
177
errors : [ makeError ( 3 ) ]
216
178
} ,
217
179
{
218
- filename : ' test.js' ,
180
+ filename : ` test.${ ext } ` ,
219
181
code : `export var b = { }
220
182
// @vue/component
221
183
foo({ })
@@ -224,21 +186,19 @@ ruleTester.run('return-in-computed-property', rule, {
224
186
errors : [ makeError ( 3 ) ]
225
187
} ,
226
188
{
227
- filename : ' test.js' ,
189
+ filename : ` test.${ ext } ` ,
228
190
code : `foo({ })
229
191
export default {
230
192
test: {}
231
193
// @vue/component
232
- foo: {
233
-
234
- }
194
+ foo: { }
235
195
}
236
196
bar({ })` ,
237
197
parserOptions,
238
198
errors : [ makeError ( 5 ) ]
239
199
} ,
240
200
{
241
- filename : ' test.js' ,
201
+ filename : ` test.${ ext } ` ,
242
202
code : `export default {
243
203
bar () {
244
204
return {}
@@ -252,4 +212,34 @@ ruleTester.run('return-in-computed-property', rule, {
252
212
errors : [ makeError ( 7 ) ]
253
213
}
254
214
]
215
+ }
216
+
217
+ // ------------------------------------------------------------------------------
218
+ // Tests
219
+ // ------------------------------------------------------------------------------
220
+
221
+ const ruleTester = new RuleTester ( )
222
+ ruleTester . run ( 'return-in-computed-property' , rule , {
223
+
224
+ valid : [
225
+ {
226
+ filename : 'test.js' ,
227
+ code : `export default { }` ,
228
+ parserOptions
229
+ }
230
+ ] . concat ( notFoundTests ( 'js' ) ) . concat ( notFoundTests ( 'jsx' ) ) . concat ( notFoundTests ( 'vue' ) ) ,
231
+ invalid : [
232
+ {
233
+ filename : 'test.vue' ,
234
+ code : `export default { }` ,
235
+ parserOptions,
236
+ errors : [ makeError ( 1 ) ]
237
+ } ,
238
+ {
239
+ filename : 'test.jsx' ,
240
+ code : `export default { }` ,
241
+ parserOptions,
242
+ errors : [ makeError ( 1 ) ]
243
+ }
244
+ ] . concat ( foundTests ( 'js' ) ) . concat ( foundTests ( 'jsx' ) ) . concat ( foundTests ( 'vue' ) )
255
245
} )
0 commit comments