]>
Commit | Line | Data |
---|---|---|
eb39fafa DC |
1 | /** |
2 | * @fileoverview Disallows or enforces spaces inside computed properties. | |
3 | * @author Jamund Ferguson | |
4 | */ | |
5 | "use strict"; | |
6 | ||
7 | //------------------------------------------------------------------------------ | |
8 | // Requirements | |
9 | //------------------------------------------------------------------------------ | |
10 | ||
11 | const rule = require("../../../lib/rules/computed-property-spacing"), | |
12 | { RuleTester } = require("../../../lib/rule-tester"); | |
13 | ||
14 | //------------------------------------------------------------------------------ | |
15 | // Tests | |
16 | //------------------------------------------------------------------------------ | |
17 | ||
18 | const ruleTester = new RuleTester(); | |
19 | ||
20 | ruleTester.run("computed-property-spacing", rule, { | |
21 | ||
22 | valid: [ | |
23 | ||
24 | // default - never | |
25 | "obj[foo]", | |
26 | "obj['foo']", | |
27 | { code: "var x = {[b]: a}", parserOptions: { ecmaVersion: 6 } }, | |
28 | ||
29 | // always | |
30 | { code: "obj[ foo ]", options: ["always"] }, | |
31 | { code: "obj[\nfoo\n]", options: ["always"] }, | |
32 | { code: "obj[ 'foo' ]", options: ["always"] }, | |
33 | { code: "obj[ 'foo' + 'bar' ]", options: ["always"] }, | |
34 | { code: "obj[ obj2[ foo ] ]", options: ["always"] }, | |
35 | { code: "obj.map(function(item) { return [\n1,\n2,\n3,\n4\n]; })", options: ["always"] }, | |
36 | { code: "obj[ 'map' ](function(item) { return [\n1,\n2,\n3,\n4\n]; })", options: ["always"] }, | |
37 | { code: "obj[ 'for' + 'Each' ](function(item) { return [\n1,\n2,\n3,\n4\n]; })", options: ["always"] }, | |
38 | { code: "var foo = obj[ 1 ]", options: ["always"] }, | |
39 | { code: "var foo = obj[ 'foo' ];", options: ["always"] }, | |
40 | { code: "var foo = obj[ [1, 1] ];", options: ["always"] }, | |
41 | ||
42 | // always - objectLiteralComputedProperties | |
43 | { code: "var x = {[ \"a\" ]: a}", options: ["always"], parserOptions: { ecmaVersion: 6 } }, | |
44 | { code: "var y = {[ x ]: a}", options: ["always"], parserOptions: { ecmaVersion: 6 } }, | |
45 | { code: "var x = {[ \"a\" ]() {}}", options: ["always"], parserOptions: { ecmaVersion: 6 } }, | |
46 | { code: "var y = {[ x ]() {}}", options: ["always"], parserOptions: { ecmaVersion: 6 } }, | |
47 | ||
48 | // always - unrelated cases | |
49 | { code: "var foo = {};", options: ["always"] }, | |
50 | { code: "var foo = [];", options: ["always"] }, | |
51 | ||
52 | // never | |
53 | { code: "obj[foo]", options: ["never"] }, | |
54 | { code: "obj['foo']", options: ["never"] }, | |
55 | { code: "obj['foo' + 'bar']", options: ["never"] }, | |
56 | { code: "obj['foo'+'bar']", options: ["never"] }, | |
57 | { code: "obj[obj2[foo]]", options: ["never"] }, | |
58 | { code: "obj.map(function(item) { return [\n1,\n2,\n3,\n4\n]; })", options: ["never"] }, | |
59 | { code: "obj['map'](function(item) { return [\n1,\n2,\n3,\n4\n]; })", options: ["never"] }, | |
60 | { code: "obj['for' + 'Each'](function(item) { return [\n1,\n2,\n3,\n4\n]; })", options: ["never"] }, | |
61 | { code: "obj[\nfoo]", options: ["never"] }, | |
62 | { code: "obj[foo\n]", options: ["never"] }, | |
63 | { code: "var foo = obj[1]", options: ["never"] }, | |
64 | { code: "var foo = obj['foo'];", options: ["never"] }, | |
65 | { code: "var foo = obj[[ 1, 1 ]];", options: ["never"] }, | |
66 | ||
67 | // never - objectLiteralComputedProperties | |
68 | { code: "var x = {[\"a\"]: a}", options: ["never"], parserOptions: { ecmaVersion: 6 } }, | |
69 | { code: "var y = {[x]: a}", options: ["never"], parserOptions: { ecmaVersion: 6 } }, | |
70 | { code: "var x = {[\"a\"]() {}}", options: ["never"], parserOptions: { ecmaVersion: 6 } }, | |
71 | { code: "var y = {[x]() {}}", options: ["never"], parserOptions: { ecmaVersion: 6 } }, | |
72 | ||
73 | // never - unrelated cases | |
74 | { code: "var foo = {};", options: ["never"] }, | |
75 | { code: "var foo = [];", options: ["never"] }, | |
76 | ||
77 | //------------------------------------------------------------------------------ | |
78 | // Classes | |
79 | //------------------------------------------------------------------------------ | |
80 | ||
81 | // explicitly disabled option | |
82 | { | |
83 | code: "class A { [ a ](){} }", | |
84 | options: ["never", { enforceForClassMembers: false }], | |
85 | parserOptions: { ecmaVersion: 6 } | |
86 | }, | |
87 | { | |
88 | code: "A = class { [ a ](){} get [ b ](){} set [ c ](foo){} static [ d ](){} static get [ e ](){} static set [ f ](bar){} }", | |
89 | options: ["never", { enforceForClassMembers: false }], | |
90 | parserOptions: { ecmaVersion: 6 } | |
91 | }, | |
92 | { | |
93 | code: "A = class { [a](){} }", | |
94 | options: ["always", { enforceForClassMembers: false }], | |
95 | parserOptions: { ecmaVersion: 6 } | |
96 | }, | |
97 | { | |
98 | code: "class A { [a](){} get [b](){} set [b](foo){} static [c](){} static get [d](){} static set [d](bar){} }", | |
99 | options: ["always", { enforceForClassMembers: false }], | |
100 | parserOptions: { ecmaVersion: 6 } | |
101 | }, | |
102 | ||
103 | // valid spacing | |
104 | { | |
105 | code: "A = class { [a](){} }", | |
106 | options: ["never", { enforceForClassMembers: true }], | |
107 | parserOptions: { ecmaVersion: 6 } | |
108 | }, | |
109 | { | |
110 | code: "class A { [a] ( ) { } }", | |
111 | options: ["never", { enforceForClassMembers: true }], | |
112 | parserOptions: { ecmaVersion: 6 } | |
113 | }, | |
114 | { | |
115 | code: "A = class { [ \n a \n ](){} }", | |
116 | options: ["never", { enforceForClassMembers: true }], | |
117 | parserOptions: { ecmaVersion: 6 } | |
118 | }, | |
119 | { | |
120 | code: "class A { [a](){} get [b](){} set [b](foo){} static [c](){} static get [d](){} static set [d](bar){} }", | |
121 | options: ["never", { enforceForClassMembers: true }], | |
122 | parserOptions: { ecmaVersion: 6 } | |
123 | }, | |
124 | { | |
125 | code: "class A { [ a ](){} }", | |
126 | options: ["always", { enforceForClassMembers: true }], | |
127 | parserOptions: { ecmaVersion: 6 } | |
128 | }, | |
129 | { | |
130 | code: "class A { [ a ](){}[ b ](){} }", | |
131 | options: ["always", { enforceForClassMembers: true }], | |
132 | parserOptions: { ecmaVersion: 6 } | |
133 | }, | |
134 | { | |
135 | code: "A = class { [\na\n](){} }", | |
136 | options: ["always", { enforceForClassMembers: true }], | |
137 | parserOptions: { ecmaVersion: 6 } | |
138 | }, | |
139 | { | |
140 | code: "A = class { [ a ](){} get [ b ](){} set [ c ](foo){} static [ d ](){} static get [ e ](){} static set [ f ](bar){} }", | |
141 | options: ["always", { enforceForClassMembers: true }], | |
142 | parserOptions: { ecmaVersion: 6 } | |
143 | }, | |
144 | ||
145 | // non-computed | |
146 | { | |
147 | code: "class A { a ( ) { } get b(){} set b ( foo ){} static c (){} static get d() {} static set d( bar ) {} }", | |
148 | options: ["never", { enforceForClassMembers: true }], | |
149 | parserOptions: { ecmaVersion: 6 } | |
150 | }, | |
151 | { | |
152 | code: "A = class {a(){}get b(){}set b(foo){}static c(){}static get d(){}static set d(bar){}}", | |
153 | options: ["always", { enforceForClassMembers: true }], | |
154 | parserOptions: { ecmaVersion: 6 } | |
155 | }, | |
156 | ||
157 | // handling of parens and comments | |
158 | { | |
159 | code: [ | |
160 | "const foo = {", | |
161 | " [ (a) ]: 1", | |
162 | "}" | |
163 | ].join("\n"), | |
164 | options: ["always"], | |
165 | parserOptions: { ecmaVersion: 6 } | |
166 | }, | |
167 | { | |
168 | code: [ | |
169 | "const foo = {", | |
170 | " [ ( a ) ]: 1", | |
171 | "}" | |
172 | ].join("\n"), | |
173 | options: ["always"], | |
174 | parserOptions: { ecmaVersion: 6 } | |
175 | }, | |
176 | { | |
177 | code: [ | |
178 | "const foo = {", | |
179 | " [( a )]: 1", | |
180 | "}" | |
181 | ].join("\n"), | |
182 | options: ["never"], | |
183 | parserOptions: { ecmaVersion: 6 } | |
184 | }, | |
185 | { | |
186 | code: [ | |
187 | "const foo = {", | |
188 | " [ /**/ a /**/ ]: 1", | |
189 | "}" | |
190 | ].join("\n"), | |
191 | options: ["always"], | |
192 | parserOptions: { ecmaVersion: 6 } | |
193 | }, | |
194 | { | |
195 | code: [ | |
196 | "const foo = {", | |
197 | " [/**/ a /**/]: 1", | |
198 | "}" | |
199 | ].join("\n"), | |
200 | options: ["never"], | |
201 | parserOptions: { ecmaVersion: 6 } | |
202 | }, | |
203 | { | |
204 | code: [ | |
205 | "const foo = {", | |
206 | " [ a[ b ] ]: 1", | |
207 | "}" | |
208 | ].join("\n"), | |
209 | options: ["always"], | |
210 | parserOptions: { ecmaVersion: 6 } | |
211 | }, | |
212 | { | |
213 | code: [ | |
214 | "const foo = {", | |
215 | " [a[b]]: 1", | |
216 | "}" | |
217 | ].join("\n"), | |
218 | options: ["never"], | |
219 | parserOptions: { ecmaVersion: 6 } | |
220 | }, | |
221 | { | |
222 | code: [ | |
223 | "const foo = {", | |
224 | " [ a[ /**/ b ]/**/ ]: 1", | |
225 | "}" | |
226 | ].join("\n"), | |
227 | options: ["always"], | |
228 | parserOptions: { ecmaVersion: 6 } | |
229 | }, | |
230 | { | |
231 | code: [ | |
232 | "const foo = {", | |
233 | " [/**/a[b /**/] /**/]: 1", | |
234 | "}" | |
235 | ].join("\n"), | |
236 | options: ["never"], | |
237 | parserOptions: { ecmaVersion: 6 } | |
238 | } | |
239 | ], | |
240 | ||
241 | invalid: [ | |
242 | { | |
243 | code: "var foo = obj[ 1];", | |
244 | output: "var foo = obj[ 1 ];", | |
245 | options: ["always"], | |
246 | errors: [ | |
247 | { | |
248 | messageId: "missingSpaceBefore", | |
249 | data: { tokenValue: "]" }, | |
250 | type: "MemberExpression", | |
251 | line: 1, | |
252 | column: 17, | |
253 | endLine: 1, | |
254 | endColumn: 18 | |
255 | ||
256 | } | |
257 | ] | |
258 | }, | |
259 | { | |
260 | code: "var foo = obj[1 ];", | |
261 | output: "var foo = obj[ 1 ];", | |
262 | options: ["always"], | |
263 | errors: [ | |
264 | { | |
265 | messageId: "missingSpaceAfter", | |
266 | data: { tokenValue: "[" }, | |
267 | type: "MemberExpression", | |
268 | line: 1, | |
269 | column: 14, | |
270 | endLine: 1, | |
271 | endColumn: 15 | |
272 | } | |
273 | ] | |
274 | }, | |
275 | { | |
276 | code: "var foo = obj[ 1];", | |
277 | output: "var foo = obj[1];", | |
278 | options: ["never"], | |
279 | errors: [ | |
280 | { | |
281 | messageId: "unexpectedSpaceAfter", | |
282 | data: { tokenValue: "[" }, | |
283 | type: "MemberExpression", | |
284 | line: 1, | |
285 | column: 15, | |
286 | endLine: 1, | |
287 | endColumn: 16 | |
288 | } | |
289 | ] | |
290 | }, | |
291 | { | |
292 | code: "var foo = obj[1 ];", | |
293 | output: "var foo = obj[1];", | |
294 | options: ["never"], | |
295 | errors: [ | |
296 | { | |
297 | messageId: "unexpectedSpaceBefore", | |
298 | data: { tokenValue: "]" }, | |
299 | type: "MemberExpression", | |
300 | line: 1, | |
301 | column: 16, | |
302 | endLine: 1, | |
303 | endColumn: 17 | |
304 | } | |
305 | ] | |
306 | }, | |
307 | { | |
308 | code: "obj[ foo ]", | |
309 | output: "obj[foo]", | |
310 | options: ["never"], | |
311 | errors: [ | |
312 | { | |
313 | messageId: "unexpectedSpaceAfter", | |
314 | data: { tokenValue: "[" }, | |
315 | type: "MemberExpression", | |
316 | line: 1, | |
317 | column: 5, | |
318 | endLine: 1, | |
319 | endColumn: 6 | |
320 | }, | |
321 | { | |
322 | messageId: "unexpectedSpaceBefore", | |
323 | data: { tokenValue: "]" }, | |
324 | type: "MemberExpression", | |
325 | line: 1, | |
326 | column: 9, | |
327 | endLine: 1, | |
328 | endColumn: 10 | |
329 | } | |
330 | ] | |
331 | }, | |
332 | { | |
333 | code: "obj[foo ]", | |
334 | output: "obj[foo]", | |
335 | options: ["never"], | |
336 | errors: [ | |
337 | { | |
338 | messageId: "unexpectedSpaceBefore", | |
339 | data: { tokenValue: "]" }, | |
340 | type: "MemberExpression", | |
341 | line: 1, | |
342 | column: 8, | |
343 | endLine: 1, | |
344 | endColumn: 9 | |
345 | } | |
346 | ] | |
347 | }, | |
348 | { | |
349 | code: "obj[ foo]", | |
350 | output: "obj[foo]", | |
351 | options: ["never"], | |
352 | errors: [ | |
353 | { | |
354 | messageId: "unexpectedSpaceAfter", | |
355 | data: { tokenValue: "[" }, | |
356 | type: "MemberExpression", | |
357 | line: 1, | |
358 | column: 5, | |
359 | endLine: 1, | |
360 | endColumn: 6 | |
361 | } | |
362 | ] | |
363 | }, | |
364 | { | |
365 | code: "var foo = obj[1]", | |
366 | output: "var foo = obj[ 1 ]", | |
367 | options: ["always"], | |
368 | errors: [ | |
369 | { | |
370 | messageId: "missingSpaceAfter", | |
371 | data: { tokenValue: "[" }, | |
372 | type: "MemberExpression", | |
373 | line: 1, | |
374 | column: 14, | |
375 | endLine: 1, | |
376 | endColumn: 15 | |
377 | }, | |
378 | { | |
379 | messageId: "missingSpaceBefore", | |
380 | data: { tokenValue: "]" }, | |
381 | type: "MemberExpression", | |
382 | line: 1, | |
383 | column: 16, | |
384 | endLine: 1, | |
385 | endColumn: 17 | |
386 | } | |
387 | ] | |
388 | }, | |
389 | ||
390 | // multiple spaces | |
391 | { | |
392 | code: "obj[ foo]", | |
393 | output: "obj[foo]", | |
394 | options: ["never"], | |
395 | errors: [ | |
396 | { | |
397 | messageId: "unexpectedSpaceAfter", | |
398 | data: { tokenValue: "[" }, | |
399 | type: "MemberExpression", | |
400 | line: 1, | |
401 | column: 5, | |
402 | endLine: 1, | |
403 | endColumn: 9 | |
404 | } | |
405 | ] | |
406 | }, | |
407 | { | |
408 | code: "obj[ foo ]", | |
409 | output: "obj[foo]", | |
410 | options: ["never"], | |
411 | errors: [ | |
412 | { | |
413 | messageId: "unexpectedSpaceAfter", | |
414 | data: { tokenValue: "[" }, | |
415 | type: "MemberExpression", | |
416 | line: 1, | |
417 | column: 5, | |
418 | endLine: 1, | |
419 | endColumn: 7 | |
420 | }, | |
421 | { | |
422 | messageId: "unexpectedSpaceBefore", | |
423 | data: { tokenValue: "]" }, | |
424 | type: "MemberExpression", | |
425 | line: 1, | |
426 | column: 10, | |
427 | endLine: 1, | |
428 | endColumn: 12 | |
429 | } | |
430 | ] | |
431 | }, | |
432 | { | |
433 | code: "obj[ foo ]", | |
434 | output: "obj[foo]", | |
435 | options: ["never"], | |
436 | errors: [ | |
437 | { | |
438 | messageId: "unexpectedSpaceAfter", | |
439 | data: { tokenValue: "[" }, | |
440 | type: "MemberExpression", | |
441 | line: 1, | |
442 | column: 5, | |
443 | endLine: 1, | |
444 | endColumn: 8 | |
445 | }, | |
446 | { | |
447 | messageId: "unexpectedSpaceBefore", | |
448 | data: { tokenValue: "]" }, | |
449 | type: "MemberExpression", | |
450 | line: 1, | |
451 | column: 11, | |
452 | endLine: 1, | |
453 | endColumn: 12 | |
454 | } | |
455 | ] | |
456 | }, | |
457 | { | |
458 | code: "obj[ foo + \n bar ]", | |
459 | output: "obj[foo + \n bar]", | |
460 | options: ["never"], | |
461 | errors: [ | |
462 | { | |
463 | messageId: "unexpectedSpaceAfter", | |
464 | data: { tokenValue: "[" }, | |
465 | type: "MemberExpression", | |
466 | line: 1, | |
467 | column: 5, | |
468 | endLine: 1, | |
469 | endColumn: 6 | |
470 | }, | |
471 | { | |
472 | messageId: "unexpectedSpaceBefore", | |
473 | data: { tokenValue: "]" }, | |
474 | type: "MemberExpression", | |
475 | line: 2, | |
476 | column: 6, | |
477 | endLine: 2, | |
478 | endColumn: 9 | |
479 | } | |
480 | ] | |
481 | }, | |
482 | { | |
483 | code: "obj[\n foo ]", | |
484 | output: "obj[\n foo]", | |
485 | options: ["never"], | |
486 | errors: [ | |
487 | { | |
488 | messageId: "unexpectedSpaceBefore", | |
489 | data: { tokenValue: "]" }, | |
490 | type: "MemberExpression", | |
491 | line: 2, | |
492 | column: 5, | |
493 | endLine: 2, | |
494 | endColumn: 7 | |
495 | } | |
496 | ] | |
497 | }, | |
498 | ||
499 | // always - objectLiteralComputedProperties | |
500 | { | |
501 | code: "var x = {[a]: b}", | |
502 | output: "var x = {[ a ]: b}", | |
503 | options: ["always"], | |
504 | parserOptions: { ecmaVersion: 6 }, | |
505 | errors: [ | |
506 | { | |
507 | messageId: "missingSpaceAfter", | |
508 | data: { tokenValue: "[" }, | |
509 | type: "Property", | |
510 | line: 1, | |
511 | column: 10, | |
512 | endLine: 1, | |
513 | endColumn: 11 | |
514 | }, | |
515 | { | |
516 | messageId: "missingSpaceBefore", | |
517 | data: { tokenValue: "]" }, | |
518 | type: "Property", | |
519 | line: 1, | |
520 | column: 12, | |
521 | endLine: 1, | |
522 | endColumn: 13 | |
523 | } | |
524 | ] | |
525 | }, | |
526 | { | |
527 | code: "var x = {[a ]: b}", | |
528 | output: "var x = {[ a ]: b}", | |
529 | options: ["always"], | |
530 | parserOptions: { ecmaVersion: 6 }, | |
531 | errors: [ | |
532 | { | |
533 | messageId: "missingSpaceAfter", | |
534 | data: { tokenValue: "[" }, | |
535 | type: "Property", | |
536 | line: 1, | |
537 | column: 10, | |
538 | endLine: 1, | |
539 | endColumn: 11 | |
540 | } | |
541 | ] | |
542 | }, | |
543 | { | |
544 | code: "var x = {[ a]: b}", | |
545 | output: "var x = {[ a ]: b}", | |
546 | options: ["always"], | |
547 | parserOptions: { ecmaVersion: 6 }, | |
548 | errors: [ | |
549 | { | |
550 | messageId: "missingSpaceBefore", | |
551 | data: { tokenValue: "]" }, | |
552 | type: "Property", | |
553 | line: 1, | |
554 | column: 13, | |
555 | endLine: 1, | |
556 | endColumn: 14 | |
557 | } | |
558 | ] | |
559 | }, | |
560 | ||
561 | // never - objectLiteralComputedProperties | |
562 | { | |
563 | code: "var x = {[ a ]: b}", | |
564 | output: "var x = {[a]: b}", | |
565 | options: ["never"], | |
566 | parserOptions: { ecmaVersion: 6 }, | |
567 | errors: [ | |
568 | { | |
569 | messageId: "unexpectedSpaceAfter", | |
570 | data: { tokenValue: "[" }, | |
571 | type: "Property", | |
572 | line: 1, | |
573 | column: 11, | |
574 | endLine: 1, | |
575 | endColumn: 12 | |
576 | }, | |
577 | { | |
578 | messageId: "unexpectedSpaceBefore", | |
579 | data: { tokenValue: "]" }, | |
580 | type: "Property", | |
581 | line: 1, | |
582 | column: 13, | |
583 | endLine: 1, | |
584 | endColumn: 14 | |
585 | } | |
586 | ] | |
587 | }, | |
588 | { | |
589 | code: "var x = {[a ]: b}", | |
590 | output: "var x = {[a]: b}", | |
591 | options: ["never"], | |
592 | parserOptions: { ecmaVersion: 6 }, | |
593 | errors: [ | |
594 | { | |
595 | messageId: "unexpectedSpaceBefore", | |
596 | data: { tokenValue: "]" }, | |
597 | type: "Property", | |
598 | line: 1, | |
599 | column: 12, | |
600 | endLine: 1, | |
601 | endColumn: 13 | |
602 | } | |
603 | ] | |
604 | }, | |
605 | { | |
606 | code: "var x = {[ a]: b}", | |
607 | output: "var x = {[a]: b}", | |
608 | options: ["never"], | |
609 | parserOptions: { ecmaVersion: 6 }, | |
610 | errors: [ | |
611 | { | |
612 | messageId: "unexpectedSpaceAfter", | |
613 | data: { tokenValue: "[" }, | |
614 | type: "Property", | |
615 | line: 1, | |
616 | column: 11, | |
617 | endLine: 1, | |
618 | endColumn: 12 | |
619 | } | |
620 | ] | |
621 | }, | |
622 | { | |
623 | code: "var x = {[ a\n]: b}", | |
624 | output: "var x = {[a\n]: b}", | |
625 | options: ["never"], | |
626 | parserOptions: { ecmaVersion: 6 }, | |
627 | errors: [ | |
628 | { | |
629 | messageId: "unexpectedSpaceAfter", | |
630 | data: { tokenValue: "[" }, | |
631 | type: "Property", | |
632 | line: 1, | |
633 | column: 11, | |
634 | endLine: 1, | |
635 | endColumn: 12 | |
636 | } | |
637 | ] | |
638 | }, | |
639 | ||
640 | // test default settings for classes | |
641 | { | |
642 | code: "class A { [ a ](){} }", | |
643 | output: "class A { [a](){} }", | |
644 | parserOptions: { ecmaVersion: 6 }, | |
645 | errors: [ | |
646 | { | |
647 | messageId: "unexpectedSpaceAfter", | |
648 | data: { tokenValue: "[" }, | |
649 | type: "MethodDefinition", | |
650 | line: 1, | |
651 | column: 12, | |
652 | endLine: 1, | |
653 | endColumn: 13 | |
654 | }, | |
655 | { | |
656 | messageId: "unexpectedSpaceBefore", | |
657 | data: { tokenValue: "]" }, | |
658 | type: "MethodDefinition", | |
659 | line: 1, | |
660 | column: 14, | |
661 | endLine: 1, | |
662 | endColumn: 15 | |
663 | } | |
664 | ] | |
665 | }, | |
666 | { | |
667 | code: "class A { [ a ](){} get [ b ](){} set [ c ](foo){} static [ d ](){} static get [ e ](){} static set [ f ](bar){} }", | |
668 | output: "class A { [a](){} get [b](){} set [c](foo){} static [d](){} static get [e](){} static set [f](bar){} }", | |
669 | options: ["never"], | |
670 | parserOptions: { ecmaVersion: 6 }, | |
671 | errors: [ | |
672 | { | |
673 | messageId: "unexpectedSpaceAfter", | |
674 | data: { tokenValue: "[" }, | |
675 | type: "MethodDefinition", | |
676 | line: 1, | |
677 | column: 12, | |
678 | endLine: 1, | |
679 | endColumn: 13 | |
680 | }, | |
681 | { | |
682 | messageId: "unexpectedSpaceBefore", | |
683 | data: { tokenValue: "]" }, | |
684 | type: "MethodDefinition", | |
685 | line: 1, | |
686 | column: 14, | |
687 | endLine: 1, | |
688 | endColumn: 15 | |
689 | }, | |
690 | { | |
691 | messageId: "unexpectedSpaceAfter", | |
692 | data: { tokenValue: "[" }, | |
693 | type: "MethodDefinition", | |
694 | line: 1, | |
695 | column: 26, | |
696 | endLine: 1, | |
697 | endColumn: 27 | |
698 | }, | |
699 | { | |
700 | messageId: "unexpectedSpaceBefore", | |
701 | data: { tokenValue: "]" }, | |
702 | type: "MethodDefinition", | |
703 | line: 1, | |
704 | column: 28, | |
705 | endLine: 1, | |
706 | endColumn: 29 | |
707 | }, | |
708 | { | |
709 | messageId: "unexpectedSpaceAfter", | |
710 | data: { tokenValue: "[" }, | |
711 | type: "MethodDefinition", | |
712 | line: 1, | |
713 | column: 40, | |
714 | endLine: 1, | |
715 | endColumn: 41 | |
716 | }, | |
717 | { | |
718 | messageId: "unexpectedSpaceBefore", | |
719 | data: { tokenValue: "]" }, | |
720 | type: "MethodDefinition", | |
721 | line: 1, | |
722 | column: 42, | |
723 | endLine: 1, | |
724 | endColumn: 43 | |
725 | }, | |
726 | { | |
727 | messageId: "unexpectedSpaceAfter", | |
728 | data: { tokenValue: "[" }, | |
729 | type: "MethodDefinition", | |
730 | line: 1, | |
731 | column: 60, | |
732 | endLine: 1, | |
733 | endColumn: 61 | |
734 | }, | |
735 | { | |
736 | messageId: "unexpectedSpaceBefore", | |
737 | data: { tokenValue: "]" }, | |
738 | type: "MethodDefinition", | |
739 | line: 1, | |
740 | column: 62, | |
741 | endLine: 1, | |
742 | endColumn: 63 | |
743 | }, | |
744 | { | |
745 | messageId: "unexpectedSpaceAfter", | |
746 | data: { tokenValue: "[" }, | |
747 | type: "MethodDefinition", | |
748 | line: 1, | |
749 | column: 81, | |
750 | endLine: 1, | |
751 | endColumn: 82 | |
752 | }, | |
753 | { | |
754 | messageId: "unexpectedSpaceBefore", | |
755 | data: { tokenValue: "]" }, | |
756 | type: "MethodDefinition", | |
757 | line: 1, | |
758 | column: 83, | |
759 | endLine: 1, | |
760 | endColumn: 84 | |
761 | }, | |
762 | { | |
763 | messageId: "unexpectedSpaceAfter", | |
764 | data: { tokenValue: "[" }, | |
765 | type: "MethodDefinition", | |
766 | line: 1, | |
767 | column: 102, | |
768 | endLine: 1, | |
769 | endColumn: 103 | |
770 | }, | |
771 | { | |
772 | messageId: "unexpectedSpaceBefore", | |
773 | data: { tokenValue: "]" }, | |
774 | type: "MethodDefinition", | |
775 | line: 1, | |
776 | column: 104, | |
777 | endLine: 1, | |
778 | endColumn: 105 | |
779 | } | |
780 | ] | |
781 | }, | |
782 | { | |
783 | code: "A = class { [ a ](){} get [ b ](){} set [ c ](foo){} static [ d ](){} static get [ e ](){} static set [ f ](bar){} }", | |
784 | output: "A = class { [a](){} get [b](){} set [c](foo){} static [d](){} static get [e](){} static set [f](bar){} }", | |
785 | options: ["never", {}], | |
786 | parserOptions: { ecmaVersion: 6 }, | |
787 | errors: [ | |
788 | { | |
789 | messageId: "unexpectedSpaceAfter", | |
790 | data: { tokenValue: "[" }, | |
791 | type: "MethodDefinition", | |
792 | line: 1, | |
793 | column: 14, | |
794 | endLine: 1, | |
795 | endColumn: 15 | |
796 | }, | |
797 | { | |
798 | messageId: "unexpectedSpaceBefore", | |
799 | data: { tokenValue: "]" }, | |
800 | type: "MethodDefinition", | |
801 | line: 1, | |
802 | column: 16, | |
803 | endLine: 1, | |
804 | endColumn: 17 | |
805 | }, | |
806 | { | |
807 | messageId: "unexpectedSpaceAfter", | |
808 | data: { tokenValue: "[" }, | |
809 | type: "MethodDefinition", | |
810 | line: 1, | |
811 | column: 28, | |
812 | endLine: 1, | |
813 | endColumn: 29 | |
814 | }, | |
815 | { | |
816 | messageId: "unexpectedSpaceBefore", | |
817 | data: { tokenValue: "]" }, | |
818 | type: "MethodDefinition", | |
819 | line: 1, | |
820 | column: 30, | |
821 | endLine: 1, | |
822 | endColumn: 31 | |
823 | }, | |
824 | { | |
825 | messageId: "unexpectedSpaceAfter", | |
826 | data: { tokenValue: "[" }, | |
827 | type: "MethodDefinition", | |
828 | line: 1, | |
829 | column: 42, | |
830 | endLine: 1, | |
831 | endColumn: 43 | |
832 | }, | |
833 | { | |
834 | messageId: "unexpectedSpaceBefore", | |
835 | data: { tokenValue: "]" }, | |
836 | type: "MethodDefinition", | |
837 | line: 1, | |
838 | column: 44, | |
839 | endLine: 1, | |
840 | endColumn: 45 | |
841 | }, | |
842 | { | |
843 | messageId: "unexpectedSpaceAfter", | |
844 | data: { tokenValue: "[" }, | |
845 | type: "MethodDefinition", | |
846 | line: 1, | |
847 | column: 62, | |
848 | endLine: 1, | |
849 | endColumn: 63 | |
850 | }, | |
851 | { | |
852 | messageId: "unexpectedSpaceBefore", | |
853 | data: { tokenValue: "]" }, | |
854 | type: "MethodDefinition", | |
855 | line: 1, | |
856 | column: 64, | |
857 | endLine: 1, | |
858 | endColumn: 65 | |
859 | }, | |
860 | { | |
861 | messageId: "unexpectedSpaceAfter", | |
862 | data: { tokenValue: "[" }, | |
863 | type: "MethodDefinition", | |
864 | line: 1, | |
865 | column: 83, | |
866 | endLine: 1, | |
867 | endColumn: 84 | |
868 | }, | |
869 | { | |
870 | messageId: "unexpectedSpaceBefore", | |
871 | data: { tokenValue: "]" }, | |
872 | type: "MethodDefinition", | |
873 | line: 1, | |
874 | column: 85, | |
875 | endLine: 1, | |
876 | endColumn: 86 | |
877 | }, | |
878 | { | |
879 | messageId: "unexpectedSpaceAfter", | |
880 | data: { tokenValue: "[" }, | |
881 | type: "MethodDefinition", | |
882 | line: 1, | |
883 | column: 104, | |
884 | endLine: 1, | |
885 | endColumn: 105 | |
886 | }, | |
887 | { | |
888 | messageId: "unexpectedSpaceBefore", | |
889 | data: { tokenValue: "]" }, | |
890 | type: "MethodDefinition", | |
891 | line: 1, | |
892 | column: 106, | |
893 | endLine: 1, | |
894 | endColumn: 107 | |
895 | } | |
896 | ] | |
897 | }, | |
898 | { | |
899 | code: "A = class { [a](){} }", | |
900 | output: "A = class { [ a ](){} }", | |
901 | options: ["always"], | |
902 | parserOptions: { ecmaVersion: 6 }, | |
903 | errors: [ | |
904 | { | |
905 | messageId: "missingSpaceAfter", | |
906 | data: { tokenValue: "[" }, | |
907 | type: "MethodDefinition", | |
908 | line: 1, | |
909 | column: 13, | |
910 | endLine: 1, | |
911 | endColumn: 14 | |
912 | }, | |
913 | { | |
914 | messageId: "missingSpaceBefore", | |
915 | data: { tokenValue: "]" }, | |
916 | type: "MethodDefinition", | |
917 | line: 1, | |
918 | column: 15, | |
919 | endLine: 1, | |
920 | endColumn: 16 | |
921 | } | |
922 | ] | |
923 | }, | |
924 | { | |
925 | code: "A = class { [a](){} get [b](){} set [c](foo){} static [d](){} static get [e](){} static set [f](bar){} }", | |
926 | output: "A = class { [ a ](){} get [ b ](){} set [ c ](foo){} static [ d ](){} static get [ e ](){} static set [ f ](bar){} }", | |
927 | options: ["always"], | |
928 | parserOptions: { ecmaVersion: 6 }, | |
929 | errors: [ | |
930 | { | |
931 | messageId: "missingSpaceAfter", | |
932 | data: { tokenValue: "[" }, | |
933 | type: "MethodDefinition", | |
934 | line: 1, | |
935 | column: 13, | |
936 | endLine: 1, | |
937 | endColumn: 14 | |
938 | }, | |
939 | { | |
940 | messageId: "missingSpaceBefore", | |
941 | data: { tokenValue: "]" }, | |
942 | type: "MethodDefinition", | |
943 | line: 1, | |
944 | column: 15, | |
945 | endLine: 1, | |
946 | endColumn: 16 | |
947 | }, | |
948 | { | |
949 | messageId: "missingSpaceAfter", | |
950 | data: { tokenValue: "[" }, | |
951 | type: "MethodDefinition", | |
952 | line: 1, | |
953 | column: 25, | |
954 | endLine: 1, | |
955 | endColumn: 26 | |
956 | }, | |
957 | { | |
958 | messageId: "missingSpaceBefore", | |
959 | data: { tokenValue: "]" }, | |
960 | type: "MethodDefinition", | |
961 | line: 1, | |
962 | column: 27, | |
963 | endLine: 1, | |
964 | endColumn: 28 | |
965 | }, | |
966 | { | |
967 | messageId: "missingSpaceAfter", | |
968 | data: { tokenValue: "[" }, | |
969 | type: "MethodDefinition", | |
970 | line: 1, | |
971 | column: 37, | |
972 | endLine: 1, | |
973 | endColumn: 38 | |
974 | }, | |
975 | { | |
976 | messageId: "missingSpaceBefore", | |
977 | data: { tokenValue: "]" }, | |
978 | type: "MethodDefinition", | |
979 | line: 1, | |
980 | column: 39, | |
981 | endLine: 1, | |
982 | endColumn: 40 | |
983 | }, | |
984 | { | |
985 | messageId: "missingSpaceAfter", | |
986 | data: { tokenValue: "[" }, | |
987 | type: "MethodDefinition", | |
988 | line: 1, | |
989 | column: 55, | |
990 | endLine: 1, | |
991 | endColumn: 56 | |
992 | }, | |
993 | { | |
994 | messageId: "missingSpaceBefore", | |
995 | data: { tokenValue: "]" }, | |
996 | type: "MethodDefinition", | |
997 | line: 1, | |
998 | column: 57, | |
999 | endLine: 1, | |
1000 | endColumn: 58 | |
1001 | }, | |
1002 | { | |
1003 | messageId: "missingSpaceAfter", | |
1004 | data: { tokenValue: "[" }, | |
1005 | type: "MethodDefinition", | |
1006 | line: 1, | |
1007 | column: 74, | |
1008 | endLine: 1, | |
1009 | endColumn: 75 | |
1010 | }, | |
1011 | { | |
1012 | messageId: "missingSpaceBefore", | |
1013 | data: { tokenValue: "]" }, | |
1014 | type: "MethodDefinition", | |
1015 | line: 1, | |
1016 | column: 76, | |
1017 | endLine: 1, | |
1018 | endColumn: 77 | |
1019 | }, | |
1020 | { | |
1021 | messageId: "missingSpaceAfter", | |
1022 | data: { tokenValue: "[" }, | |
1023 | type: "MethodDefinition", | |
1024 | line: 1, | |
1025 | column: 93, | |
1026 | endLine: 1, | |
1027 | endColumn: 94 | |
1028 | }, | |
1029 | { | |
1030 | messageId: "missingSpaceBefore", | |
1031 | data: { tokenValue: "]" }, | |
1032 | type: "MethodDefinition", | |
1033 | line: 1, | |
1034 | column: 95, | |
1035 | endLine: 1, | |
1036 | endColumn: 96 | |
1037 | } | |
1038 | ] | |
1039 | }, | |
1040 | { | |
1041 | code: "class A { [a](){} get [b](){} set [c](foo){} static [d](){} static get [e](){} static set [f](bar){} }", | |
1042 | output: "class A { [ a ](){} get [ b ](){} set [ c ](foo){} static [ d ](){} static get [ e ](){} static set [ f ](bar){} }", | |
1043 | options: ["always", {}], | |
1044 | parserOptions: { ecmaVersion: 6 }, | |
1045 | errors: [ | |
1046 | { | |
1047 | messageId: "missingSpaceAfter", | |
1048 | data: { tokenValue: "[" }, | |
1049 | type: "MethodDefinition", | |
1050 | line: 1, | |
1051 | column: 11, | |
1052 | endLine: 1, | |
1053 | endColumn: 12 | |
1054 | }, | |
1055 | { | |
1056 | messageId: "missingSpaceBefore", | |
1057 | data: { tokenValue: "]" }, | |
1058 | type: "MethodDefinition", | |
1059 | line: 1, | |
1060 | column: 13, | |
1061 | endLine: 1, | |
1062 | endColumn: 14 | |
1063 | }, | |
1064 | { | |
1065 | messageId: "missingSpaceAfter", | |
1066 | data: { tokenValue: "[" }, | |
1067 | type: "MethodDefinition", | |
1068 | line: 1, | |
1069 | column: 23, | |
1070 | endLine: 1, | |
1071 | endColumn: 24 | |
1072 | }, | |
1073 | { | |
1074 | messageId: "missingSpaceBefore", | |
1075 | data: { tokenValue: "]" }, | |
1076 | type: "MethodDefinition", | |
1077 | line: 1, | |
1078 | column: 25, | |
1079 | endLine: 1, | |
1080 | endColumn: 26 | |
1081 | }, | |
1082 | { | |
1083 | messageId: "missingSpaceAfter", | |
1084 | data: { tokenValue: "[" }, | |
1085 | type: "MethodDefinition", | |
1086 | line: 1, | |
1087 | column: 35, | |
1088 | endLine: 1, | |
1089 | endColumn: 36 | |
1090 | }, | |
1091 | { | |
1092 | messageId: "missingSpaceBefore", | |
1093 | data: { tokenValue: "]" }, | |
1094 | type: "MethodDefinition", | |
1095 | line: 1, | |
1096 | column: 37, | |
1097 | endLine: 1, | |
1098 | endColumn: 38 | |
1099 | }, | |
1100 | { | |
1101 | messageId: "missingSpaceAfter", | |
1102 | data: { tokenValue: "[" }, | |
1103 | type: "MethodDefinition", | |
1104 | line: 1, | |
1105 | column: 53, | |
1106 | endLine: 1, | |
1107 | endColumn: 54 | |
1108 | }, | |
1109 | { | |
1110 | messageId: "missingSpaceBefore", | |
1111 | data: { tokenValue: "]" }, | |
1112 | type: "MethodDefinition", | |
1113 | line: 1, | |
1114 | column: 55, | |
1115 | endLine: 1, | |
1116 | endColumn: 56 | |
1117 | }, | |
1118 | { | |
1119 | messageId: "missingSpaceAfter", | |
1120 | data: { tokenValue: "[" }, | |
1121 | type: "MethodDefinition", | |
1122 | line: 1, | |
1123 | column: 72, | |
1124 | endLine: 1, | |
1125 | endColumn: 73 | |
1126 | }, | |
1127 | { | |
1128 | messageId: "missingSpaceBefore", | |
1129 | data: { tokenValue: "]" }, | |
1130 | type: "MethodDefinition", | |
1131 | line: 1, | |
1132 | column: 74, | |
1133 | endLine: 1, | |
1134 | endColumn: 75 | |
1135 | }, | |
1136 | { | |
1137 | messageId: "missingSpaceAfter", | |
1138 | data: { tokenValue: "[" }, | |
1139 | type: "MethodDefinition", | |
1140 | line: 1, | |
1141 | column: 91, | |
1142 | endLine: 1, | |
1143 | endColumn: 92 | |
1144 | }, | |
1145 | { | |
1146 | messageId: "missingSpaceBefore", | |
1147 | data: { tokenValue: "]" }, | |
1148 | type: "MethodDefinition", | |
1149 | line: 1, | |
1150 | column: 93, | |
1151 | endLine: 1, | |
1152 | endColumn: 94 | |
1153 | } | |
1154 | ] | |
1155 | }, | |
1156 | ||
1157 | // never - classes | |
1158 | { | |
1159 | code: "class A { [ a](){} }", | |
1160 | output: "class A { [a](){} }", | |
1161 | options: ["never", { enforceForClassMembers: true }], | |
1162 | parserOptions: { ecmaVersion: 6 }, | |
1163 | errors: [ | |
1164 | { | |
1165 | messageId: "unexpectedSpaceAfter", | |
1166 | data: { tokenValue: "[" }, | |
1167 | type: "MethodDefinition", | |
1168 | line: 1, | |
1169 | column: 12, | |
1170 | endLine: 1, | |
1171 | endColumn: 13 | |
1172 | } | |
1173 | ] | |
1174 | }, | |
1175 | { | |
1176 | code: "A = class { [a](){} b(){} static [c ](){} static [d](){}}", | |
1177 | output: "A = class { [a](){} b(){} static [c](){} static [d](){}}", | |
1178 | options: ["never", { enforceForClassMembers: true }], | |
1179 | parserOptions: { ecmaVersion: 6 }, | |
1180 | errors: [ | |
1181 | { | |
1182 | messageId: "unexpectedSpaceBefore", | |
1183 | data: { tokenValue: "]" }, | |
1184 | type: "MethodDefinition", | |
1185 | line: 1, | |
1186 | column: 36, | |
1187 | endLine: 1, | |
1188 | endColumn: 37 | |
1189 | } | |
1190 | ] | |
1191 | }, | |
1192 | { | |
1193 | code: "class A { get [a ](){} set [ a](foo){} get b(){} static set b(bar){} static get [ a](){} static set [a ](baz){} }", | |
1194 | output: "class A { get [a](){} set [a](foo){} get b(){} static set b(bar){} static get [a](){} static set [a](baz){} }", | |
1195 | options: ["never", { enforceForClassMembers: true }], | |
1196 | parserOptions: { ecmaVersion: 6 }, | |
1197 | errors: [ | |
1198 | { | |
1199 | messageId: "unexpectedSpaceBefore", | |
1200 | data: { tokenValue: "]" }, | |
1201 | type: "MethodDefinition", | |
1202 | line: 1, | |
1203 | column: 17, | |
1204 | endLine: 1, | |
1205 | endColumn: 18 | |
1206 | }, | |
1207 | { | |
1208 | messageId: "unexpectedSpaceAfter", | |
1209 | data: { tokenValue: "[" }, | |
1210 | type: "MethodDefinition", | |
1211 | line: 1, | |
1212 | column: 29, | |
1213 | endLine: 1, | |
1214 | endColumn: 30 | |
1215 | }, | |
1216 | { | |
1217 | messageId: "unexpectedSpaceAfter", | |
1218 | data: { tokenValue: "[" }, | |
1219 | type: "MethodDefinition", | |
1220 | line: 1, | |
1221 | column: 82, | |
1222 | endLine: 1, | |
1223 | endColumn: 83 | |
1224 | }, | |
1225 | { | |
1226 | messageId: "unexpectedSpaceBefore", | |
1227 | data: { tokenValue: "]" }, | |
1228 | type: "MethodDefinition", | |
1229 | line: 1, | |
1230 | column: 103, | |
1231 | endLine: 1, | |
1232 | endColumn: 104 | |
1233 | } | |
1234 | ] | |
1235 | }, | |
1236 | { | |
1237 | code: "A = class { [ a ](){} get [ b ](){} set [ c ](foo){} static [ d ](){} static get [ e ](){} static set [ f ](bar){} }", | |
1238 | output: "A = class { [a](){} get [b](){} set [c](foo){} static [d](){} static get [e](){} static set [f](bar){} }", | |
1239 | options: ["never", { enforceForClassMembers: true }], | |
1240 | parserOptions: { ecmaVersion: 6 }, | |
1241 | errors: [ | |
1242 | { | |
1243 | messageId: "unexpectedSpaceAfter", | |
1244 | data: { tokenValue: "[" }, | |
1245 | type: "MethodDefinition", | |
1246 | line: 1, | |
1247 | column: 14, | |
1248 | endLine: 1, | |
1249 | endColumn: 15 | |
1250 | }, | |
1251 | { | |
1252 | messageId: "unexpectedSpaceBefore", | |
1253 | data: { tokenValue: "]" }, | |
1254 | type: "MethodDefinition", | |
1255 | line: 1, | |
1256 | column: 16, | |
1257 | endLine: 1, | |
1258 | endColumn: 17 | |
1259 | }, | |
1260 | { | |
1261 | messageId: "unexpectedSpaceAfter", | |
1262 | data: { tokenValue: "[" }, | |
1263 | type: "MethodDefinition", | |
1264 | line: 1, | |
1265 | column: 28, | |
1266 | endLine: 1, | |
1267 | endColumn: 29 | |
1268 | }, | |
1269 | { | |
1270 | messageId: "unexpectedSpaceBefore", | |
1271 | data: { tokenValue: "]" }, | |
1272 | type: "MethodDefinition", | |
1273 | line: 1, | |
1274 | column: 30, | |
1275 | endLine: 1, | |
1276 | endColumn: 31 | |
1277 | }, | |
1278 | { | |
1279 | messageId: "unexpectedSpaceAfter", | |
1280 | data: { tokenValue: "[" }, | |
1281 | type: "MethodDefinition", | |
1282 | line: 1, | |
1283 | column: 42, | |
1284 | endLine: 1, | |
1285 | endColumn: 43 | |
1286 | }, | |
1287 | { | |
1288 | messageId: "unexpectedSpaceBefore", | |
1289 | data: { tokenValue: "]" }, | |
1290 | type: "MethodDefinition", | |
1291 | line: 1, | |
1292 | column: 44, | |
1293 | endLine: 1, | |
1294 | endColumn: 45 | |
1295 | }, | |
1296 | { | |
1297 | messageId: "unexpectedSpaceAfter", | |
1298 | data: { tokenValue: "[" }, | |
1299 | type: "MethodDefinition", | |
1300 | line: 1, | |
1301 | column: 62, | |
1302 | endLine: 1, | |
1303 | endColumn: 63 | |
1304 | }, | |
1305 | { | |
1306 | messageId: "unexpectedSpaceBefore", | |
1307 | data: { tokenValue: "]" }, | |
1308 | type: "MethodDefinition", | |
1309 | line: 1, | |
1310 | column: 64, | |
1311 | endLine: 1, | |
1312 | endColumn: 65 | |
1313 | }, | |
1314 | { | |
1315 | messageId: "unexpectedSpaceAfter", | |
1316 | data: { tokenValue: "[" }, | |
1317 | type: "MethodDefinition", | |
1318 | line: 1, | |
1319 | column: 83, | |
1320 | endLine: 1, | |
1321 | endColumn: 84 | |
1322 | }, | |
1323 | { | |
1324 | messageId: "unexpectedSpaceBefore", | |
1325 | data: { tokenValue: "]" }, | |
1326 | type: "MethodDefinition", | |
1327 | line: 1, | |
1328 | column: 85, | |
1329 | endLine: 1, | |
1330 | endColumn: 86 | |
1331 | }, | |
1332 | { | |
1333 | messageId: "unexpectedSpaceAfter", | |
1334 | data: { tokenValue: "[" }, | |
1335 | type: "MethodDefinition", | |
1336 | line: 1, | |
1337 | column: 104, | |
1338 | endLine: 1, | |
1339 | endColumn: 105 | |
1340 | }, | |
1341 | { | |
1342 | messageId: "unexpectedSpaceBefore", | |
1343 | data: { tokenValue: "]" }, | |
1344 | type: "MethodDefinition", | |
1345 | line: 1, | |
1346 | column: 106, | |
1347 | endLine: 1, | |
1348 | endColumn: 107 | |
1349 | } | |
1350 | ] | |
1351 | }, | |
1352 | ||
1353 | // always - classes | |
1354 | { | |
1355 | code: "class A { [ a](){} }", | |
1356 | output: "class A { [ a ](){} }", | |
1357 | options: ["always", { enforceForClassMembers: true }], | |
1358 | parserOptions: { ecmaVersion: 6 }, | |
1359 | errors: [ | |
1360 | { | |
1361 | messageId: "missingSpaceBefore", | |
1362 | data: { tokenValue: "]" }, | |
1363 | type: "MethodDefinition", | |
1364 | line: 1, | |
1365 | column: 14, | |
1366 | endLine: 1, | |
1367 | endColumn: 15 | |
1368 | } | |
1369 | ] | |
1370 | }, | |
1371 | { | |
1372 | code: "A = class { [ a ](){} b(){} static [c ](){} static [ d ](){}}", | |
1373 | output: "A = class { [ a ](){} b(){} static [ c ](){} static [ d ](){}}", | |
1374 | options: ["always", { enforceForClassMembers: true }], | |
1375 | parserOptions: { ecmaVersion: 6 }, | |
1376 | errors: [ | |
1377 | { | |
1378 | messageId: "missingSpaceAfter", | |
1379 | data: { tokenValue: "[" }, | |
1380 | type: "MethodDefinition", | |
1381 | line: 1, | |
1382 | column: 36, | |
1383 | endLine: 1, | |
1384 | endColumn: 37 | |
1385 | } | |
1386 | ] | |
1387 | }, | |
1388 | { | |
1389 | code: "class A { get [a ](){} set [ a](foo){} get b(){} static set b(bar){} static get [ a](){} static set [a ](baz){} }", | |
1390 | output: "class A { get [ a ](){} set [ a ](foo){} get b(){} static set b(bar){} static get [ a ](){} static set [ a ](baz){} }", | |
1391 | options: ["always", { enforceForClassMembers: true }], | |
1392 | parserOptions: { ecmaVersion: 6 }, | |
1393 | errors: [ | |
1394 | { | |
1395 | messageId: "missingSpaceAfter", | |
1396 | data: { tokenValue: "[" }, | |
1397 | type: "MethodDefinition", | |
1398 | line: 1, | |
1399 | column: 15, | |
1400 | endLine: 1, | |
1401 | endColumn: 16 | |
1402 | }, | |
1403 | { | |
1404 | messageId: "missingSpaceBefore", | |
1405 | data: { tokenValue: "]" }, | |
1406 | type: "MethodDefinition", | |
1407 | line: 1, | |
1408 | column: 31, | |
1409 | endLine: 1, | |
1410 | endColumn: 32 | |
1411 | }, | |
1412 | { | |
1413 | messageId: "missingSpaceBefore", | |
1414 | data: { tokenValue: "]" }, | |
1415 | type: "MethodDefinition", | |
1416 | line: 1, | |
1417 | column: 84, | |
1418 | endLine: 1, | |
1419 | endColumn: 85 | |
1420 | }, | |
1421 | { | |
1422 | messageId: "missingSpaceAfter", | |
1423 | data: { tokenValue: "[" }, | |
1424 | type: "MethodDefinition", | |
1425 | line: 1, | |
1426 | column: 101, | |
1427 | endLine: 1, | |
1428 | endColumn: 102 | |
1429 | } | |
1430 | ] | |
1431 | }, | |
1432 | { | |
1433 | code: "A = class { [a](){} get [b](){} set [c](foo){} static [d](){} static get [e](){} static set [f](bar){} }", | |
1434 | output: "A = class { [ a ](){} get [ b ](){} set [ c ](foo){} static [ d ](){} static get [ e ](){} static set [ f ](bar){} }", | |
1435 | options: ["always", { enforceForClassMembers: true }], | |
1436 | parserOptions: { ecmaVersion: 6 }, | |
1437 | errors: [ | |
1438 | { | |
1439 | messageId: "missingSpaceAfter", | |
1440 | data: { tokenValue: "[" }, | |
1441 | type: "MethodDefinition", | |
1442 | line: 1, | |
1443 | column: 13, | |
1444 | endLine: 1, | |
1445 | endColumn: 14 | |
1446 | }, | |
1447 | { | |
1448 | messageId: "missingSpaceBefore", | |
1449 | data: { tokenValue: "]" }, | |
1450 | type: "MethodDefinition", | |
1451 | line: 1, | |
1452 | column: 15, | |
1453 | endLine: 1, | |
1454 | endColumn: 16 | |
1455 | }, | |
1456 | { | |
1457 | messageId: "missingSpaceAfter", | |
1458 | data: { tokenValue: "[" }, | |
1459 | type: "MethodDefinition", | |
1460 | line: 1, | |
1461 | column: 25, | |
1462 | endLine: 1, | |
1463 | endColumn: 26 | |
1464 | }, | |
1465 | { | |
1466 | messageId: "missingSpaceBefore", | |
1467 | data: { tokenValue: "]" }, | |
1468 | type: "MethodDefinition", | |
1469 | line: 1, | |
1470 | column: 27, | |
1471 | endLine: 1, | |
1472 | endColumn: 28 | |
1473 | }, | |
1474 | { | |
1475 | messageId: "missingSpaceAfter", | |
1476 | data: { tokenValue: "[" }, | |
1477 | type: "MethodDefinition", | |
1478 | line: 1, | |
1479 | column: 37, | |
1480 | endLine: 1, | |
1481 | endColumn: 38 | |
1482 | }, | |
1483 | { | |
1484 | messageId: "missingSpaceBefore", | |
1485 | data: { tokenValue: "]" }, | |
1486 | type: "MethodDefinition", | |
1487 | line: 1, | |
1488 | column: 39, | |
1489 | endLine: 1, | |
1490 | endColumn: 40 | |
1491 | }, | |
1492 | { | |
1493 | messageId: "missingSpaceAfter", | |
1494 | data: { tokenValue: "[" }, | |
1495 | type: "MethodDefinition", | |
1496 | line: 1, | |
1497 | column: 55, | |
1498 | endLine: 1, | |
1499 | endColumn: 56 | |
1500 | }, | |
1501 | { | |
1502 | messageId: "missingSpaceBefore", | |
1503 | data: { tokenValue: "]" }, | |
1504 | type: "MethodDefinition", | |
1505 | line: 1, | |
1506 | column: 57, | |
1507 | endLine: 1, | |
1508 | endColumn: 58 | |
1509 | }, | |
1510 | { | |
1511 | messageId: "missingSpaceAfter", | |
1512 | data: { tokenValue: "[" }, | |
1513 | type: "MethodDefinition", | |
1514 | line: 1, | |
1515 | column: 74, | |
1516 | endLine: 1, | |
1517 | endColumn: 75 | |
1518 | }, | |
1519 | { | |
1520 | messageId: "missingSpaceBefore", | |
1521 | data: { tokenValue: "]" }, | |
1522 | type: "MethodDefinition", | |
1523 | line: 1, | |
1524 | column: 76, | |
1525 | endLine: 1, | |
1526 | endColumn: 77 | |
1527 | }, | |
1528 | { | |
1529 | messageId: "missingSpaceAfter", | |
1530 | data: { tokenValue: "[" }, | |
1531 | type: "MethodDefinition", | |
1532 | line: 1, | |
1533 | column: 93, | |
1534 | endLine: 1, | |
1535 | endColumn: 94 | |
1536 | }, | |
1537 | { | |
1538 | messageId: "missingSpaceBefore", | |
1539 | data: { tokenValue: "]" }, | |
1540 | type: "MethodDefinition", | |
1541 | line: 1, | |
1542 | column: 95, | |
1543 | endLine: 1, | |
1544 | endColumn: 96 | |
1545 | } | |
1546 | ] | |
1547 | }, | |
1548 | ||
1549 | // handling of parens and comments | |
1550 | { | |
1551 | code: [ | |
1552 | "const foo = {", | |
1553 | " [(a)]: 1", | |
1554 | "}" | |
1555 | ].join("\n"), | |
1556 | output: [ | |
1557 | "const foo = {", | |
1558 | " [ (a) ]: 1", | |
1559 | "}" | |
1560 | ].join("\n"), | |
1561 | options: ["always"], | |
1562 | parserOptions: { ecmaVersion: 6 }, | |
1563 | errors: [ | |
1564 | { | |
1565 | messageId: "missingSpaceAfter", | |
1566 | data: { tokenValue: "[" }, | |
1567 | type: "Property", | |
1568 | line: 2, | |
1569 | column: 3, | |
1570 | endLine: 2, | |
1571 | endColumn: 4 | |
1572 | }, | |
1573 | { | |
1574 | messageId: "missingSpaceBefore", | |
1575 | data: { tokenValue: "]" }, | |
1576 | type: "Property", | |
1577 | line: 2, | |
1578 | column: 7, | |
1579 | endLine: 2, | |
1580 | endColumn: 8 | |
1581 | } | |
1582 | ] | |
1583 | }, | |
1584 | { | |
1585 | code: [ | |
1586 | "const foo = {", | |
1587 | " [( a )]: 1", | |
1588 | "}" | |
1589 | ].join("\n"), | |
1590 | output: [ | |
1591 | "const foo = {", | |
1592 | " [ ( a ) ]: 1", | |
1593 | "}" | |
1594 | ].join("\n"), | |
1595 | options: ["always"], | |
1596 | parserOptions: { ecmaVersion: 6 }, | |
1597 | errors: [ | |
1598 | { | |
1599 | messageId: "missingSpaceAfter", | |
1600 | data: { tokenValue: "[" }, | |
1601 | type: "Property", | |
1602 | line: 2, | |
1603 | column: 3, | |
1604 | endLine: 2, | |
1605 | endColumn: 4 | |
1606 | }, | |
1607 | { | |
1608 | messageId: "missingSpaceBefore", | |
1609 | data: { tokenValue: "]" }, | |
1610 | type: "Property", | |
1611 | line: 2, | |
1612 | column: 9, | |
1613 | endLine: 2, | |
1614 | endColumn: 10 | |
1615 | } | |
1616 | ] | |
1617 | }, | |
1618 | { | |
1619 | code: [ | |
1620 | "const foo = {", | |
1621 | " [ ( a ) ]: 1", | |
1622 | "}" | |
1623 | ].join("\n"), | |
1624 | output: [ | |
1625 | "const foo = {", | |
1626 | " [( a )]: 1", | |
1627 | "}" | |
1628 | ].join("\n"), | |
1629 | options: ["never"], | |
1630 | parserOptions: { ecmaVersion: 6 }, | |
1631 | errors: [ | |
1632 | { | |
1633 | messageId: "unexpectedSpaceAfter", | |
1634 | data: { tokenValue: "[" }, | |
1635 | type: "Property", | |
1636 | line: 2, | |
1637 | column: 4, | |
1638 | endLine: 2, | |
1639 | endColumn: 5 | |
1640 | }, | |
1641 | { | |
1642 | messageId: "unexpectedSpaceBefore", | |
1643 | data: { tokenValue: "]" }, | |
1644 | type: "Property", | |
1645 | line: 2, | |
1646 | column: 10, | |
1647 | endLine: 2, | |
1648 | endColumn: 11 | |
1649 | } | |
1650 | ] | |
1651 | }, | |
1652 | { | |
1653 | code: [ | |
1654 | "const foo = {", | |
1655 | " [/**/ a /**/]: 1", | |
1656 | "}" | |
1657 | ].join("\n"), | |
1658 | output: [ | |
1659 | "const foo = {", | |
1660 | " [ /**/ a /**/ ]: 1", | |
1661 | "}" | |
1662 | ].join("\n"), | |
1663 | options: ["always"], | |
1664 | parserOptions: { ecmaVersion: 6 }, | |
1665 | errors: [ | |
1666 | { | |
1667 | messageId: "missingSpaceAfter", | |
1668 | data: { tokenValue: "[" }, | |
1669 | type: "Property", | |
1670 | line: 2, | |
1671 | column: 3, | |
1672 | endLine: 2, | |
1673 | endColumn: 4 | |
1674 | }, | |
1675 | { | |
1676 | messageId: "missingSpaceBefore", | |
1677 | data: { tokenValue: "]" }, | |
1678 | type: "Property", | |
1679 | line: 2, | |
1680 | column: 15, | |
1681 | endLine: 2, | |
1682 | endColumn: 16 | |
1683 | } | |
1684 | ] | |
1685 | }, | |
1686 | { | |
1687 | code: [ | |
1688 | "const foo = {", | |
1689 | " [ /**/ a /**/ ]: 1", | |
1690 | "}" | |
1691 | ].join("\n"), | |
1692 | output: [ | |
1693 | "const foo = {", | |
1694 | " [/**/ a /**/]: 1", | |
1695 | "}" | |
1696 | ].join("\n"), | |
1697 | options: ["never"], | |
1698 | parserOptions: { ecmaVersion: 6 }, | |
1699 | errors: [ | |
1700 | { | |
1701 | messageId: "unexpectedSpaceAfter", | |
1702 | data: { tokenValue: "[" }, | |
1703 | type: "Property", | |
1704 | line: 2, | |
1705 | column: 4, | |
1706 | endLine: 2, | |
1707 | endColumn: 5 | |
1708 | }, | |
1709 | { | |
1710 | messageId: "unexpectedSpaceBefore", | |
1711 | data: { tokenValue: "]" }, | |
1712 | type: "Property", | |
1713 | line: 2, | |
1714 | column: 16, | |
1715 | endLine: 2, | |
1716 | endColumn: 17 | |
1717 | } | |
1718 | ] | |
1719 | }, | |
1720 | { | |
1721 | code: [ | |
1722 | "const foo = {", | |
1723 | " [a[b]]: 1", | |
1724 | "}" | |
1725 | ].join("\n"), | |
1726 | output: [ | |
1727 | "const foo = {", | |
1728 | " [ a[ b ] ]: 1", | |
1729 | "}" | |
1730 | ].join("\n"), | |
1731 | options: ["always"], | |
1732 | parserOptions: { ecmaVersion: 6 }, | |
1733 | errors: [ | |
1734 | { | |
1735 | messageId: "missingSpaceAfter", | |
1736 | data: { tokenValue: "[" }, | |
1737 | type: "Property", | |
1738 | line: 2, | |
1739 | column: 3, | |
1740 | endLine: 2, | |
1741 | endColumn: 4 | |
1742 | }, | |
1743 | { | |
1744 | messageId: "missingSpaceAfter", | |
1745 | data: { tokenValue: "[" }, | |
1746 | type: "MemberExpression", | |
1747 | line: 2, | |
1748 | column: 5, | |
1749 | endLine: 2, | |
1750 | endColumn: 6 | |
1751 | }, | |
1752 | { | |
1753 | messageId: "missingSpaceBefore", | |
1754 | data: { tokenValue: "]" }, | |
1755 | type: "MemberExpression", | |
1756 | line: 2, | |
1757 | column: 7, | |
1758 | endLine: 2, | |
1759 | endColumn: 8 | |
1760 | }, | |
1761 | { | |
1762 | messageId: "missingSpaceBefore", | |
1763 | data: { tokenValue: "]" }, | |
1764 | type: "Property", | |
1765 | line: 2, | |
1766 | column: 8, | |
1767 | endLine: 2, | |
1768 | endColumn: 9 | |
1769 | } | |
1770 | ] | |
1771 | }, | |
1772 | { | |
1773 | code: [ | |
1774 | "const foo = {", | |
1775 | " [ a[ b ] ]: 1", | |
1776 | "}" | |
1777 | ].join("\n"), | |
1778 | output: [ | |
1779 | "const foo = {", | |
1780 | " [a[b]]: 1", | |
1781 | "}" | |
1782 | ].join("\n"), | |
1783 | options: ["never"], | |
1784 | parserOptions: { ecmaVersion: 6 }, | |
1785 | errors: [ | |
1786 | { | |
1787 | messageId: "unexpectedSpaceAfter", | |
1788 | data: { tokenValue: "[" }, | |
1789 | type: "Property", | |
1790 | line: 2, | |
1791 | column: 4, | |
1792 | endLine: 2, | |
1793 | endColumn: 5 | |
1794 | }, | |
1795 | { | |
1796 | messageId: "unexpectedSpaceAfter", | |
1797 | data: { tokenValue: "[" }, | |
1798 | type: "MemberExpression", | |
1799 | line: 2, | |
1800 | column: 7, | |
1801 | endLine: 2, | |
1802 | endColumn: 8 | |
1803 | }, | |
1804 | { | |
1805 | messageId: "unexpectedSpaceBefore", | |
1806 | data: { tokenValue: "]" }, | |
1807 | type: "MemberExpression", | |
1808 | line: 2, | |
1809 | column: 9, | |
1810 | endLine: 2, | |
1811 | endColumn: 10 | |
1812 | }, | |
1813 | { | |
1814 | messageId: "unexpectedSpaceBefore", | |
1815 | data: { tokenValue: "]" }, | |
1816 | type: "Property", | |
1817 | line: 2, | |
1818 | column: 11, | |
1819 | endLine: 2, | |
1820 | endColumn: 12 | |
1821 | } | |
1822 | ] | |
1823 | }, | |
1824 | { | |
1825 | code: [ | |
1826 | "const foo = {", | |
1827 | " [a[/**/ b ]/**/]: 1", | |
1828 | "}" | |
1829 | ].join("\n"), | |
1830 | output: [ | |
1831 | "const foo = {", | |
1832 | " [ a[ /**/ b ]/**/ ]: 1", | |
1833 | "}" | |
1834 | ].join("\n"), | |
1835 | options: ["always"], | |
1836 | parserOptions: { ecmaVersion: 6 }, | |
1837 | errors: [ | |
1838 | { | |
1839 | messageId: "missingSpaceAfter", | |
1840 | data: { tokenValue: "[" }, | |
1841 | type: "Property", | |
1842 | line: 2, | |
1843 | column: 3, | |
1844 | endLine: 2, | |
1845 | endColumn: 4 | |
1846 | }, | |
1847 | { | |
1848 | messageId: "missingSpaceAfter", | |
1849 | data: { tokenValue: "[" }, | |
1850 | type: "MemberExpression", | |
1851 | line: 2, | |
1852 | column: 5, | |
1853 | endLine: 2, | |
1854 | endColumn: 6 | |
1855 | }, | |
1856 | { | |
1857 | messageId: "missingSpaceBefore", | |
1858 | data: { tokenValue: "]" }, | |
1859 | type: "Property", | |
1860 | line: 2, | |
1861 | column: 18, | |
1862 | endLine: 2, | |
1863 | endColumn: 19 | |
1864 | } | |
1865 | ] | |
1866 | }, | |
1867 | { | |
1868 | code: [ | |
1869 | "const foo = {", | |
1870 | " [ /**/a[ b /**/ ] /**/]: 1", | |
1871 | "}" | |
1872 | ].join("\n"), | |
1873 | output: [ | |
1874 | "const foo = {", | |
1875 | " [/**/a[b /**/] /**/]: 1", | |
1876 | "}" | |
1877 | ].join("\n"), | |
1878 | options: ["never"], | |
1879 | parserOptions: { ecmaVersion: 6 }, | |
1880 | errors: [ | |
1881 | { | |
1882 | messageId: "unexpectedSpaceAfter", | |
1883 | data: { tokenValue: "[" }, | |
1884 | type: "Property", | |
1885 | line: 2, | |
1886 | column: 4, | |
1887 | endLine: 2, | |
1888 | endColumn: 5 | |
1889 | }, | |
1890 | { | |
1891 | messageId: "unexpectedSpaceAfter", | |
1892 | data: { tokenValue: "[" }, | |
1893 | type: "MemberExpression", | |
1894 | line: 2, | |
1895 | column: 11, | |
1896 | endLine: 2, | |
1897 | endColumn: 12 | |
1898 | }, | |
1899 | { | |
1900 | messageId: "unexpectedSpaceBefore", | |
1901 | data: { tokenValue: "]" }, | |
1902 | type: "MemberExpression", | |
1903 | line: 2, | |
1904 | column: 18, | |
1905 | endLine: 2, | |
1906 | endColumn: 19 | |
1907 | } | |
1908 | ] | |
1909 | } | |
1910 | ] | |
1911 | }); |