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