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