]>
Commit | Line | Data |
---|---|---|
eb39fafa DC |
1 | /** |
2 | * @fileoverview Tests for padded-blocks rule. | |
3 | * @author Mathias Schreck <https://github.com/lo1tuma> | |
4 | */ | |
5 | ||
6 | "use strict"; | |
7 | ||
8 | //------------------------------------------------------------------------------ | |
9 | // Requirements | |
10 | //------------------------------------------------------------------------------ | |
11 | ||
12 | const rule = require("../../../lib/rules/padded-blocks"), | |
13 | { RuleTester } = require("../../../lib/rule-tester"); | |
14 | ||
15 | //------------------------------------------------------------------------------ | |
16 | // Tests | |
17 | //------------------------------------------------------------------------------ | |
18 | ||
19 | const ruleTester = new RuleTester(); | |
20 | ||
21 | ruleTester.run("padded-blocks", rule, { | |
22 | valid: [ | |
23 | "{\n\na();\n\n}", | |
24 | "{\n\n\na();\n\n\n}", | |
25 | "{\n\n//comment\na();\n\n}", | |
26 | "{\n\na();\n//comment\n\n}", | |
27 | "{\n\na()\n//comment\n\n}", | |
28 | "{\n\na = 1\n\n}", | |
29 | "{//comment\n\na();\n\n}", | |
30 | "{ /* comment */\n\na();\n\n}", | |
31 | "{ /* comment \n */\n\na();\n\n}", | |
32 | "{ /* comment \n */ /* another comment \n */\n\na();\n\n}", | |
33 | "{ /* comment \n */ /* another comment \n */\n\na();\n\n/* comment \n */ /* another comment \n */}", | |
34 | ||
35 | "{\n\na();\n\n/* comment */ }", | |
36 | { code: "{\n\na();\n\n/* comment */ }", options: ["always"] }, | |
37 | { code: "{\n\na();\n\n/* comment */ }", options: [{ blocks: "always" }] }, | |
38 | ||
ebb53d86 | 39 | |
eb39fafa DC |
40 | { code: "switch (a) {}", options: [{ switches: "always" }] }, |
41 | { code: "switch (a) {\n\ncase 0: foo();\ncase 1: bar();\n\n}", options: ["always"] }, | |
42 | { code: "switch (a) {\n\ncase 0: foo();\ncase 1: bar();\n\n}", options: [{ switches: "always" }] }, | |
43 | { code: "switch (a) {\n\n//comment\ncase 0: foo();//comment\n\n}", options: [{ switches: "always" }] }, | |
44 | { code: "switch (a) {//comment\n\ncase 0: foo();\ncase 1: bar();\n\n/* comment */}", options: [{ switches: "always" }] }, | |
45 | ||
46 | { code: "class A{\n\nfoo(){}\n\n}", parserOptions: { ecmaVersion: 6 } }, | |
47 | { code: "class A{\n\nfoo(){}\n\n}", options: ["always"], parserOptions: { ecmaVersion: 6 } }, | |
48 | { code: "class A{}", options: [{ classes: "always" }], parserOptions: { ecmaVersion: 6 } }, | |
49 | { code: "class A{\n\n}", options: [{ classes: "always" }], parserOptions: { ecmaVersion: 6 } }, | |
50 | { code: "class A{\n\nfoo(){}\n\n}", options: [{ classes: "always" }], parserOptions: { ecmaVersion: 6 } }, | |
51 | ||
52 | { code: "{\na();\n}", options: ["never"] }, | |
53 | { code: "{\na();}", options: ["never"] }, | |
54 | { code: "{a();\n}", options: ["never"] }, | |
55 | { code: "{a();}", options: ["never"] }, | |
56 | { code: "{a();}", options: ["always", { allowSingleLineBlocks: true }] }, | |
57 | { code: "{\n\na();\n\n}", options: ["always", { allowSingleLineBlocks: true }] }, | |
58 | { code: "{//comment\na();}", options: ["never"] }, | |
59 | { code: "{\n//comment\na()\n}", options: ["never"] }, | |
60 | { code: "{a();//comment\n}", options: ["never"] }, | |
61 | { code: "{\na();\n//comment\n}", options: ["never"] }, | |
62 | { code: "{\na()\n//comment\n}", options: ["never"] }, | |
63 | { code: "{\na()\n//comment\nb()\n}", options: ["never"] }, | |
64 | { code: "function a() {\n/* comment */\nreturn;\n/* comment*/\n}", options: ["never"] }, | |
65 | { code: "{\n// comment\ndebugger;\n// comment\n}", options: ["never"] }, | |
66 | { code: "{\n\n// comment\nif (\n// comment\n a) {}\n\n }", options: ["always"] }, | |
67 | { code: "{\n// comment\nif (\n// comment\n a) {}\n }", options: ["never"] }, | |
68 | { code: "{\n// comment\nif (\n// comment\n a) {}\n }", options: [{ blocks: "never" }] }, | |
69 | ||
70 | { code: "switch (a) {\ncase 0: foo();\n}", options: ["never"] }, | |
71 | { code: "switch (a) {\ncase 0: foo();\n}", options: [{ switches: "never" }] }, | |
72 | ||
73 | ||
74 | { code: "class A{\nfoo(){}\n}", options: ["never"], parserOptions: { ecmaVersion: 6 } }, | |
75 | { code: "class A{\nfoo(){}\n}", options: [{ classes: "never" }], parserOptions: { ecmaVersion: 6 } }, | |
76 | ||
77 | // Ignore block statements if not configured | |
78 | { code: "{\na();\n}", options: [{ switches: "always" }] }, | |
79 | { code: "{\n\na();\n\n}", options: [{ switches: "never" }] }, | |
80 | ||
81 | // Ignore switch statements if not configured | |
82 | { code: "switch (a) {\ncase 0: foo();\ncase 1: bar();\n}", options: [{ blocks: "always", classes: "always" }] }, | |
83 | { code: "switch (a) {\n\ncase 0: foo();\ncase 1: bar();\n\n}", options: [{ blocks: "never", classes: "never" }] }, | |
84 | ||
85 | ||
86 | // Ignore class statements if not configured | |
87 | { code: "class A{\nfoo(){}\n}", options: [{ blocks: "always" }], parserOptions: { ecmaVersion: 6 } }, | |
88 | { code: "class A{\n\nfoo(){}\n\n}", options: [{ blocks: "never" }], parserOptions: { ecmaVersion: 6 } } | |
89 | ||
90 | ], | |
91 | invalid: [ | |
92 | { | |
93 | code: "{\n//comment\na();\n\n}", | |
94 | output: "{\n\n//comment\na();\n\n}", | |
95 | errors: [ | |
96 | { | |
97 | messageId: "alwaysPadBlock", | |
98 | line: 1, | |
ebb53d86 TL |
99 | column: 1, |
100 | endLine: 2, | |
101 | endColumn: 1 | |
eb39fafa DC |
102 | } |
103 | ] | |
104 | }, | |
105 | { | |
106 | code: "{ //comment\na();\n\n}", | |
107 | output: "{ //comment\n\na();\n\n}", | |
108 | errors: [ | |
109 | { | |
110 | messageId: "alwaysPadBlock", | |
111 | line: 1, | |
ebb53d86 TL |
112 | column: 3, |
113 | endLine: 2, | |
114 | endColumn: 1 | |
eb39fafa DC |
115 | } |
116 | ] | |
117 | }, | |
118 | { | |
119 | code: "{\n\na();\n//comment\n}", | |
120 | output: "{\n\na();\n//comment\n\n}", | |
121 | errors: [ | |
122 | { | |
123 | messageId: "alwaysPadBlock", | |
ebb53d86 TL |
124 | line: 4, |
125 | column: 10, | |
126 | endLine: 5, | |
127 | endColumn: 1 | |
eb39fafa DC |
128 | } |
129 | ] | |
130 | }, | |
131 | { | |
132 | code: "{\n\na()\n//comment\n}", | |
133 | output: "{\n\na()\n//comment\n\n}", | |
134 | errors: [ | |
135 | { | |
136 | messageId: "alwaysPadBlock", | |
ebb53d86 TL |
137 | line: 4, |
138 | column: 10, | |
139 | endLine: 5, | |
140 | endColumn: 1 | |
eb39fafa DC |
141 | } |
142 | ] | |
143 | }, | |
144 | { | |
145 | code: "{\na();\n\n}", | |
146 | output: "{\n\na();\n\n}", | |
147 | errors: [ | |
148 | { | |
149 | messageId: "alwaysPadBlock", | |
ebb53d86 TL |
150 | line: 1, |
151 | column: 1, | |
152 | endLine: 2, | |
153 | endColumn: 1 | |
eb39fafa DC |
154 | } |
155 | ] | |
156 | }, | |
157 | { | |
158 | code: "{\n\na();\n}", | |
159 | output: "{\n\na();\n\n}", | |
160 | errors: [ | |
161 | { | |
162 | messageId: "alwaysPadBlock", | |
ebb53d86 TL |
163 | line: 3, |
164 | column: 5, | |
165 | endLine: 4, | |
166 | endColumn: 1 | |
eb39fafa DC |
167 | } |
168 | ] | |
169 | }, | |
170 | { | |
171 | code: "{\na();\n}", | |
172 | output: "{\n\na();\n\n}", | |
173 | errors: [ | |
174 | { | |
175 | messageId: "alwaysPadBlock", | |
ebb53d86 TL |
176 | line: 1, |
177 | column: 1, | |
178 | endLine: 2, | |
179 | endColumn: 1 | |
eb39fafa DC |
180 | }, |
181 | { | |
182 | messageId: "alwaysPadBlock", | |
ebb53d86 TL |
183 | line: 2, |
184 | column: 5, | |
185 | endLine: 3, | |
186 | endColumn: 1 | |
eb39fafa DC |
187 | } |
188 | ] | |
189 | }, | |
190 | { | |
191 | code: "{\r\na();\r\n}", | |
192 | output: "{\n\r\na();\r\n\n}", | |
193 | errors: [ | |
194 | { | |
195 | messageId: "alwaysPadBlock", | |
ebb53d86 TL |
196 | line: 1, |
197 | column: 1, | |
198 | endLine: 2, | |
199 | endColumn: 1 | |
eb39fafa DC |
200 | }, |
201 | { | |
202 | messageId: "alwaysPadBlock", | |
ebb53d86 TL |
203 | line: 2, |
204 | column: 5, | |
205 | endLine: 3, | |
206 | endColumn: 1 | |
eb39fafa DC |
207 | } |
208 | ] | |
209 | }, | |
210 | { | |
211 | code: "{\na();}", | |
212 | output: "{\n\na();\n}", | |
213 | errors: [ | |
214 | { | |
215 | messageId: "alwaysPadBlock", | |
ebb53d86 TL |
216 | line: 1, |
217 | column: 1, | |
218 | endLine: 2, | |
219 | endColumn: 1 | |
eb39fafa DC |
220 | }, |
221 | { | |
222 | messageId: "alwaysPadBlock", | |
ebb53d86 TL |
223 | line: 2, |
224 | column: 5, | |
225 | endLine: 2, | |
226 | endColumn: 5 | |
eb39fafa DC |
227 | } |
228 | ] | |
229 | }, | |
230 | { | |
231 | code: "{a();\n}", | |
232 | output: "{\na();\n\n}", | |
233 | errors: [ | |
234 | { | |
235 | messageId: "alwaysPadBlock", | |
ebb53d86 TL |
236 | line: 1, |
237 | column: 1, | |
238 | endLine: 1, | |
239 | endColumn: 2 | |
eb39fafa DC |
240 | }, |
241 | { | |
242 | messageId: "alwaysPadBlock", | |
ebb53d86 TL |
243 | line: 1, |
244 | column: 6, | |
245 | endLine: 2, | |
246 | endColumn: 1 | |
eb39fafa DC |
247 | } |
248 | ] | |
249 | }, | |
250 | { | |
251 | code: "{a();\n}", | |
252 | output: "{\na();\n\n}", | |
253 | options: [{ blocks: "always" }], | |
254 | errors: [ | |
255 | { | |
256 | messageId: "alwaysPadBlock", | |
ebb53d86 TL |
257 | line: 1, |
258 | column: 1, | |
259 | endLine: 1, | |
260 | endColumn: 2 | |
eb39fafa DC |
261 | }, |
262 | { | |
263 | messageId: "alwaysPadBlock", | |
ebb53d86 TL |
264 | line: 1, |
265 | column: 6, | |
266 | endLine: 2, | |
267 | endColumn: 1 | |
eb39fafa DC |
268 | } |
269 | ] | |
270 | }, | |
271 | { | |
272 | code: "switch (a) {\ncase 0: foo();\ncase 1: bar();\n}", | |
273 | output: "switch (a) {\n\ncase 0: foo();\ncase 1: bar();\n\n}", | |
274 | options: ["always"], | |
275 | errors: [ | |
276 | { | |
277 | messageId: "alwaysPadBlock", | |
278 | line: 1, | |
ebb53d86 TL |
279 | column: 12, |
280 | endLine: 2, | |
281 | endColumn: 1 | |
eb39fafa DC |
282 | }, |
283 | { | |
284 | messageId: "alwaysPadBlock", | |
ebb53d86 TL |
285 | line: 3, |
286 | column: 15, | |
287 | endLine: 4, | |
288 | endColumn: 1 | |
eb39fafa DC |
289 | } |
290 | ] | |
291 | }, | |
292 | { | |
293 | code: "switch (a) {\ncase 0: foo();\ncase 1: bar();\n}", | |
294 | output: "switch (a) {\n\ncase 0: foo();\ncase 1: bar();\n\n}", | |
295 | options: [{ switches: "always" }], | |
296 | errors: [ | |
297 | { | |
298 | messageId: "alwaysPadBlock", | |
299 | line: 1, | |
ebb53d86 TL |
300 | column: 12, |
301 | endLine: 2, | |
302 | endColumn: 1 | |
eb39fafa DC |
303 | }, |
304 | { | |
305 | messageId: "alwaysPadBlock", | |
ebb53d86 TL |
306 | line: 3, |
307 | column: 15, | |
308 | endLine: 4, | |
309 | endColumn: 1 | |
eb39fafa DC |
310 | } |
311 | ] | |
312 | }, | |
313 | { | |
314 | code: "switch (a) {\n//comment\ncase 0: foo();//comment\n}", | |
315 | output: "switch (a) {\n\n//comment\ncase 0: foo();//comment\n\n}", | |
316 | options: [{ switches: "always" }], | |
317 | errors: [ | |
318 | { | |
319 | messageId: "alwaysPadBlock", | |
320 | line: 1, | |
ebb53d86 TL |
321 | column: 12, |
322 | endLine: 2, | |
323 | endColumn: 1 | |
eb39fafa DC |
324 | }, |
325 | { | |
326 | messageId: "alwaysPadBlock", | |
ebb53d86 TL |
327 | line: 3, |
328 | column: 24, | |
329 | endLine: 4, | |
330 | endColumn: 1 | |
eb39fafa DC |
331 | } |
332 | ] | |
333 | }, | |
334 | { | |
335 | code: "class A {\nconstructor(){}\n}", | |
336 | output: "class A {\n\nconstructor(){}\n\n}", | |
337 | options: ["always"], | |
338 | parserOptions: { ecmaVersion: 6 }, | |
339 | errors: [ | |
340 | { | |
341 | messageId: "alwaysPadBlock", | |
342 | line: 1, | |
ebb53d86 TL |
343 | column: 9, |
344 | endLine: 2, | |
345 | endColumn: 1 | |
eb39fafa DC |
346 | }, |
347 | { | |
348 | messageId: "alwaysPadBlock", | |
ebb53d86 TL |
349 | line: 2, |
350 | column: 16, | |
351 | endLine: 3, | |
352 | endColumn: 1 | |
eb39fafa DC |
353 | } |
354 | ] | |
355 | }, | |
356 | { | |
357 | code: "class A {\nconstructor(){}\n}", | |
358 | output: "class A {\n\nconstructor(){}\n\n}", | |
359 | options: [{ classes: "always" }], | |
360 | parserOptions: { ecmaVersion: 6 }, | |
361 | errors: [ | |
362 | { | |
363 | messageId: "alwaysPadBlock", | |
364 | line: 1, | |
ebb53d86 TL |
365 | column: 9, |
366 | endLine: 2, | |
367 | endColumn: 1 | |
eb39fafa DC |
368 | }, |
369 | { | |
370 | messageId: "alwaysPadBlock", | |
ebb53d86 TL |
371 | line: 2, |
372 | column: 16, | |
373 | endLine: 3, | |
374 | endColumn: 1 | |
eb39fafa DC |
375 | } |
376 | ] | |
377 | }, | |
378 | { | |
379 | code: "{a();}", | |
380 | output: "{\na();\n}", | |
381 | errors: [ | |
382 | { | |
383 | messageId: "alwaysPadBlock", | |
ebb53d86 TL |
384 | line: 1, |
385 | column: 1, | |
386 | endLine: 1, | |
387 | endColumn: 2 | |
eb39fafa DC |
388 | }, |
389 | { | |
390 | messageId: "alwaysPadBlock", | |
ebb53d86 TL |
391 | line: 1, |
392 | column: 6, | |
393 | endLine: 1, | |
394 | endColumn: 6 | |
eb39fafa DC |
395 | } |
396 | ] | |
397 | }, | |
398 | { | |
399 | code: "{\na()\n//comment\n\n}", | |
400 | output: "{\na()\n//comment\n}", | |
401 | options: ["never"], | |
402 | errors: [ | |
403 | { | |
404 | messageId: "neverPadBlock", | |
ebb53d86 TL |
405 | line: 3, |
406 | column: 10, | |
407 | endLine: 5, | |
408 | endColumn: 1 | |
eb39fafa DC |
409 | } |
410 | ] | |
411 | }, | |
412 | { | |
413 | code: "{\n\na();\n\n}", | |
414 | output: "{\na();\n}", | |
415 | options: ["never"], | |
416 | errors: [ | |
417 | { | |
418 | messageId: "neverPadBlock", | |
ebb53d86 TL |
419 | line: 1, |
420 | column: 1, | |
421 | endLine: 3, | |
422 | endColumn: 1 | |
eb39fafa DC |
423 | }, |
424 | { | |
425 | messageId: "neverPadBlock", | |
ebb53d86 TL |
426 | line: 3, |
427 | column: 5, | |
428 | endLine: 5, | |
429 | endColumn: 1 | |
eb39fafa DC |
430 | } |
431 | ] | |
432 | }, | |
433 | { | |
434 | code: "{\r\n\r\na();\r\n\r\n}", | |
435 | output: "{\na();\n}", | |
436 | options: ["never"], | |
437 | errors: [ | |
438 | { | |
439 | messageId: "neverPadBlock", | |
ebb53d86 TL |
440 | line: 1, |
441 | column: 1, | |
442 | endLine: 3, | |
443 | endColumn: 1 | |
eb39fafa DC |
444 | }, |
445 | { | |
446 | messageId: "neverPadBlock", | |
ebb53d86 TL |
447 | line: 3, |
448 | column: 5, | |
449 | endLine: 5, | |
450 | endColumn: 1 | |
eb39fafa DC |
451 | } |
452 | ] | |
453 | }, | |
454 | { | |
455 | code: "{\n\n\n a();\n\n\n}", | |
456 | output: "{\n a();\n}", | |
457 | options: ["never"], | |
458 | errors: [ | |
459 | { | |
460 | messageId: "neverPadBlock", | |
ebb53d86 TL |
461 | line: 1, |
462 | column: 1, | |
463 | endLine: 4, | |
464 | endColumn: 3 | |
eb39fafa DC |
465 | }, |
466 | { | |
467 | messageId: "neverPadBlock", | |
ebb53d86 TL |
468 | line: 4, |
469 | column: 7, | |
470 | endLine: 7, | |
471 | endColumn: 1 | |
eb39fafa DC |
472 | } |
473 | ] | |
474 | }, | |
475 | { | |
476 | code: "{\n\na();\n}", | |
477 | output: "{\na();\n}", | |
478 | options: ["never"], | |
479 | errors: [ | |
480 | { | |
481 | messageId: "neverPadBlock", | |
ebb53d86 TL |
482 | line: 1, |
483 | column: 1, | |
484 | endLine: 3, | |
485 | endColumn: 1 | |
eb39fafa DC |
486 | } |
487 | ] | |
488 | }, | |
489 | { | |
490 | code: "{\n\n\ta();\n}", | |
491 | output: "{\n\ta();\n}", | |
492 | options: ["never"], | |
493 | errors: [ | |
494 | { | |
495 | messageId: "neverPadBlock", | |
ebb53d86 TL |
496 | line: 1, |
497 | column: 1, | |
498 | endLine: 3, | |
499 | endColumn: 2 | |
eb39fafa DC |
500 | } |
501 | ] | |
502 | }, | |
503 | { | |
504 | code: "{\na();\n\n}", | |
505 | output: "{\na();\n}", | |
506 | options: ["never"], | |
507 | errors: [ | |
508 | { | |
509 | messageId: "neverPadBlock", | |
ebb53d86 TL |
510 | line: 2, |
511 | column: 5, | |
512 | endLine: 4, | |
513 | endColumn: 1 | |
eb39fafa DC |
514 | } |
515 | ] | |
516 | }, | |
517 | { | |
518 | code: " {\n a();\n\n }", | |
519 | output: " {\n a();\n }", | |
520 | options: ["never"], | |
521 | errors: [ | |
522 | { | |
523 | messageId: "neverPadBlock", | |
ebb53d86 TL |
524 | line: 2, |
525 | column: 9, | |
526 | endLine: 4, | |
527 | endColumn: 3 | |
eb39fafa DC |
528 | } |
529 | ] | |
530 | }, | |
531 | { | |
532 | code: "{\n// comment\nif (\n// comment\n a) {}\n\n}", | |
533 | output: "{\n\n// comment\nif (\n// comment\n a) {}\n\n}", | |
534 | options: ["always"], | |
535 | errors: [ | |
536 | { | |
537 | messageId: "alwaysPadBlock", | |
538 | line: 1, | |
ebb53d86 TL |
539 | column: 1, |
540 | endLine: 2, | |
541 | endColumn: 1 | |
eb39fafa DC |
542 | } |
543 | ] | |
544 | }, | |
545 | { | |
546 | code: "{\n\n// comment\nif (\n// comment\n a) {}\n}", | |
547 | output: "{\n// comment\nif (\n// comment\n a) {}\n}", | |
548 | options: ["never"], | |
549 | errors: [ | |
550 | { | |
551 | messageId: "neverPadBlock", | |
552 | line: 1, | |
ebb53d86 TL |
553 | column: 1, |
554 | endLine: 3, | |
555 | endColumn: 1 | |
eb39fafa DC |
556 | } |
557 | ] | |
558 | }, | |
559 | { | |
560 | code: "{\n\n// comment\nif (\n// comment\n a) {}\n}", | |
561 | output: "{\n// comment\nif (\n// comment\n a) {}\n}", | |
562 | options: [{ blocks: "never" }], | |
563 | errors: [ | |
564 | { | |
565 | messageId: "neverPadBlock", | |
566 | line: 1, | |
ebb53d86 TL |
567 | column: 1, |
568 | endLine: 3, | |
569 | endColumn: 1 | |
eb39fafa DC |
570 | } |
571 | ] | |
572 | }, | |
573 | { | |
574 | code: "switch (a) {\n\ncase 0: foo();\n\n}", | |
575 | output: "switch (a) {\ncase 0: foo();\n}", | |
576 | options: ["never"], | |
577 | errors: [ | |
578 | { | |
579 | messageId: "neverPadBlock", | |
580 | line: 1, | |
ebb53d86 TL |
581 | column: 12, |
582 | endLine: 3, | |
583 | endColumn: 1 | |
eb39fafa DC |
584 | }, |
585 | { | |
586 | messageId: "neverPadBlock", | |
ebb53d86 TL |
587 | line: 3, |
588 | column: 15, | |
589 | endLine: 5, | |
590 | endColumn: 1 | |
eb39fafa DC |
591 | } |
592 | ] | |
593 | }, | |
594 | { | |
595 | code: "switch (a) {\n\ncase 0: foo();\n}", | |
596 | output: "switch (a) {\ncase 0: foo();\n}", | |
597 | options: [{ switches: "never" }], | |
598 | errors: [ | |
599 | { | |
600 | messageId: "neverPadBlock", | |
601 | line: 1, | |
ebb53d86 TL |
602 | column: 12, |
603 | endLine: 3, | |
604 | endColumn: 1 | |
eb39fafa DC |
605 | } |
606 | ] | |
607 | }, | |
608 | { | |
609 | code: "switch (a) {\ncase 0: foo();\n\n }", | |
610 | output: "switch (a) {\ncase 0: foo();\n }", | |
611 | options: [{ switches: "never" }], | |
612 | errors: [ | |
613 | { | |
614 | messageId: "neverPadBlock", | |
ebb53d86 TL |
615 | line: 2, |
616 | column: 15, | |
617 | endLine: 4, | |
618 | endColumn: 3 | |
eb39fafa DC |
619 | } |
620 | ] | |
621 | }, | |
622 | { | |
623 | code: "class A {\n\nconstructor(){\n\nfoo();\n\n}\n\n}", | |
624 | output: "class A {\nconstructor(){\nfoo();\n}\n}", | |
625 | options: ["never"], | |
626 | parserOptions: { ecmaVersion: 6 }, | |
627 | errors: [ | |
628 | { | |
629 | messageId: "neverPadBlock", | |
ebb53d86 TL |
630 | line: 1, |
631 | column: 9, | |
632 | endLine: 3, | |
633 | endColumn: 1 | |
eb39fafa DC |
634 | }, |
635 | { | |
636 | messageId: "neverPadBlock", | |
ebb53d86 TL |
637 | line: 3, |
638 | column: 14, | |
639 | endLine: 5, | |
640 | endColumn: 1 | |
eb39fafa DC |
641 | }, |
642 | { | |
643 | messageId: "neverPadBlock", | |
ebb53d86 TL |
644 | line: 5, |
645 | column: 7, | |
646 | endLine: 7, | |
647 | endColumn: 1 | |
eb39fafa DC |
648 | }, |
649 | { | |
650 | messageId: "neverPadBlock", | |
ebb53d86 TL |
651 | line: 7, |
652 | column: 2, | |
653 | endLine: 9, | |
654 | endColumn: 1 | |
eb39fafa DC |
655 | } |
656 | ] | |
657 | }, | |
658 | { | |
659 | code: "class A {\n\nconstructor(){\n\nfoo();\n\n}\n\n}", | |
660 | output: "class A {\nconstructor(){\n\nfoo();\n\n}\n}", | |
661 | options: [{ classes: "never" }], | |
662 | parserOptions: { ecmaVersion: 6 }, | |
663 | errors: [ | |
664 | { | |
665 | messageId: "neverPadBlock", | |
ebb53d86 TL |
666 | line: 1, |
667 | column: 9, | |
668 | endLine: 3, | |
669 | endColumn: 1 | |
eb39fafa DC |
670 | }, |
671 | { | |
672 | messageId: "neverPadBlock", | |
ebb53d86 TL |
673 | line: 7, |
674 | column: 2, | |
675 | endLine: 9, | |
676 | endColumn: 1 | |
eb39fafa DC |
677 | } |
678 | ] | |
679 | }, | |
680 | { | |
681 | code: "class A {\n\nconstructor(){\n\nfoo();\n\n}\n\n}", | |
682 | output: "class A {\nconstructor(){\nfoo();\n}\n}", | |
683 | options: [{ blocks: "never", classes: "never" }], | |
684 | parserOptions: { ecmaVersion: 6 }, | |
685 | errors: [ | |
686 | { | |
687 | messageId: "neverPadBlock", | |
ebb53d86 TL |
688 | line: 1, |
689 | column: 9, | |
690 | endLine: 3, | |
691 | endColumn: 1 | |
eb39fafa DC |
692 | }, |
693 | { | |
694 | messageId: "neverPadBlock", | |
ebb53d86 TL |
695 | line: 3, |
696 | column: 14, | |
697 | endLine: 5, | |
698 | endColumn: 1 | |
eb39fafa DC |
699 | }, |
700 | { | |
701 | messageId: "neverPadBlock", | |
ebb53d86 TL |
702 | line: 5, |
703 | column: 7, | |
704 | endLine: 7, | |
705 | endColumn: 1 | |
eb39fafa DC |
706 | }, |
707 | { | |
708 | messageId: "neverPadBlock", | |
ebb53d86 TL |
709 | line: 7, |
710 | column: 2, | |
711 | endLine: 9, | |
712 | endColumn: 1 | |
eb39fafa DC |
713 | } |
714 | ] | |
715 | }, | |
716 | { | |
717 | code: "function foo() { // a\n\n b;\n}", | |
718 | output: "function foo() { // a\n b;\n}", | |
719 | options: ["never"], | |
720 | errors: [{ messageId: "neverPadBlock" }] | |
721 | }, | |
722 | { | |
723 | code: "function foo() { /* a\n */\n\n bar;\n}", | |
724 | output: "function foo() { /* a\n */\n bar;\n}", | |
725 | options: ["never"], | |
726 | errors: [{ messageId: "neverPadBlock" }] | |
727 | }, | |
728 | { | |
729 | code: "function foo() {\n\n bar;\n/* a\n */}", | |
730 | output: "function foo() {\n\n bar;\n\n/* a\n */}", | |
731 | options: ["always"], | |
732 | errors: [{ messageId: "alwaysPadBlock" }] | |
733 | }, | |
734 | { | |
735 | code: "function foo() { /* a\n */\n/* b\n */\n bar;\n}", | |
736 | output: "function foo() { /* a\n */\n\n/* b\n */\n bar;\n\n}", | |
737 | options: ["always"], | |
738 | errors: [{ messageId: "alwaysPadBlock" }, { messageId: "alwaysPadBlock" }] | |
739 | }, | |
740 | { | |
741 | code: "function foo() { /* a\n */ /* b\n */\n bar;\n}", | |
742 | output: "function foo() { /* a\n */ /* b\n */\n\n bar;\n\n}", | |
743 | options: ["always"], | |
744 | errors: [{ messageId: "alwaysPadBlock" }, { messageId: "alwaysPadBlock" }] | |
745 | }, | |
746 | { | |
747 | code: "function foo() { /* a\n */ /* b\n */\n bar;\n/* c\n *//* d\n */}", | |
748 | output: "function foo() { /* a\n */ /* b\n */\n\n bar;\n\n/* c\n *//* d\n */}", | |
749 | options: ["always"], | |
750 | errors: [{ messageId: "alwaysPadBlock" }, { messageId: "alwaysPadBlock" }] | |
751 | } | |
752 | ] | |
753 | }); |