]>
Commit | Line | Data |
---|---|---|
eb39fafa DC |
1 | /** |
2 | * @fileoverview Operator linebreak rule tests | |
3 | * @author BenoƮt Zugmeyer | |
4 | */ | |
5 | "use strict"; | |
6 | ||
7 | //------------------------------------------------------------------------------ | |
8 | // Requirements | |
9 | //------------------------------------------------------------------------------ | |
10 | ||
11 | const rule = require("../../../lib/rules/operator-linebreak"), | |
12 | { RuleTester } = require("../../../lib/rule-tester"); | |
13 | ||
14 | //------------------------------------------------------------------------------ | |
15 | // Tests | |
16 | //------------------------------------------------------------------------------ | |
17 | ||
18 | const ruleTester = new RuleTester(); | |
19 | ||
20 | ruleTester.run("operator-linebreak", rule, { | |
21 | ||
22 | valid: [ | |
23 | "1 + 1", | |
24 | "1 + 1 + 1", | |
25 | "1 +\n1", | |
26 | "1 + (1 +\n1)", | |
27 | "f(1 +\n1)", | |
28 | "1 || 1", | |
29 | "1 || \n1", | |
30 | "a += 1", | |
31 | "var a;", | |
32 | "var o = \nsomething", | |
33 | "o = \nsomething", | |
34 | "'a\\\n' +\n 'c'", | |
35 | "'a' +\n 'b\\\n'", | |
36 | "(a\n) + b", | |
37 | "answer = everything \n? 42 \n: foo;", | |
38 | { code: "answer = everything ?\n 42 :\n foo;", options: ["after"] }, | |
39 | ||
40 | { code: "a ? 1 + 1\n:2", options: [null, { overrides: { "?": "after" } }] }, | |
41 | { code: "a ?\n1 +\n 1\n:2", options: [null, { overrides: { "?": "after" } }] }, | |
42 | { code: "o = 1 \n+ 1 - foo", options: [null, { overrides: { "+": "before" } }] }, | |
43 | ||
44 | { code: "1\n+ 1", options: ["before"] }, | |
45 | { code: "1 + 1\n+ 1", options: ["before"] }, | |
46 | { code: "f(1\n+ 1)", options: ["before"] }, | |
47 | { code: "1 \n|| 1", options: ["before"] }, | |
48 | { code: "a += 1", options: ["before"] }, | |
49 | { code: "answer = everything \n? 42 \n: foo;", options: ["before"] }, | |
50 | ||
51 | { code: "1 + 1", options: ["none"] }, | |
52 | { code: "1 + 1 + 1", options: ["none"] }, | |
53 | { code: "1 || 1", options: ["none"] }, | |
54 | { code: "a += 1", options: ["none"] }, | |
55 | { code: "var a;", options: ["none"] }, | |
56 | { code: "\n1 + 1", options: ["none"] }, | |
57 | { code: "1 + 1\n", options: ["none"] }, | |
58 | { code: "answer = everything ? 42 : foo;", options: ["none"] }, | |
609c276f | 59 | { code: "(a\n) + (\nb)", options: ["none"] }, |
eb39fafa | 60 | { code: "answer = everything \n?\n 42 : foo;", options: [null, { overrides: { "?": "ignore" } }] }, |
6f036462 TL |
61 | { code: "answer = everything ? 42 \n:\n foo;", options: [null, { overrides: { ":": "ignore" } }] }, |
62 | ||
63 | { | |
64 | code: "a \n &&= b", | |
65 | options: ["after", { overrides: { "&&=": "ignore" } }], | |
66 | parserOptions: { ecmaVersion: 2021 } | |
67 | }, | |
68 | { | |
69 | code: "a ??= \n b", | |
70 | options: ["before", { overrides: { "??=": "ignore" } }], | |
71 | parserOptions: { ecmaVersion: 2021 } | |
72 | }, | |
73 | { | |
74 | code: "a ||= \n b", | |
75 | options: ["after", { overrides: { "=": "before" } }], | |
76 | parserOptions: { ecmaVersion: 2021 } | |
77 | }, | |
78 | { | |
79 | code: "a \n &&= b", | |
80 | options: ["before", { overrides: { "&=": "after" } }], | |
81 | parserOptions: { ecmaVersion: 2021 } | |
82 | }, | |
83 | { | |
84 | code: "a \n ||= b", | |
85 | options: ["before", { overrides: { "|=": "after" } }], | |
86 | parserOptions: { ecmaVersion: 2021 } | |
87 | }, | |
88 | { | |
89 | code: "a &&= \n b", | |
90 | options: ["after", { overrides: { "&&": "before" } }], | |
91 | parserOptions: { ecmaVersion: 2021 } | |
92 | }, | |
93 | { | |
94 | code: "a ||= \n b", | |
95 | options: ["after", { overrides: { "||": "before" } }], | |
96 | parserOptions: { ecmaVersion: 2021 } | |
97 | }, | |
98 | { | |
99 | code: "a ??= \n b", | |
100 | options: ["after", { overrides: { "??": "before" } }], | |
101 | parserOptions: { ecmaVersion: 2021 } | |
609c276f TL |
102 | }, |
103 | ||
104 | // class fields | |
105 | { | |
106 | code: "class C { foo =\n0 }", | |
107 | parserOptions: { ecmaVersion: 2022 } | |
108 | }, | |
109 | { | |
110 | code: "class C { foo\n= 0 }", | |
111 | options: ["before"], | |
112 | parserOptions: { ecmaVersion: 2022 } | |
113 | }, | |
114 | { | |
115 | code: "class C { [foo\n]= 0 }", | |
116 | options: ["before"], | |
117 | parserOptions: { ecmaVersion: 2022 } | |
118 | }, | |
119 | { | |
120 | code: "class C { [foo]\n= 0 }", | |
121 | options: ["before"], | |
122 | parserOptions: { ecmaVersion: 2022 } | |
123 | }, | |
124 | { | |
125 | code: "class C { [foo\n]\n= 0 }", | |
126 | options: ["before"], | |
127 | parserOptions: { ecmaVersion: 2022 } | |
128 | }, | |
129 | { | |
130 | code: "class C { [foo\n]= 0 }", | |
131 | options: ["after"], | |
132 | parserOptions: { ecmaVersion: 2022 } | |
133 | }, | |
134 | { | |
135 | code: "class C { [foo\n]=\n0 }", | |
136 | options: ["after"], | |
137 | parserOptions: { ecmaVersion: 2022 } | |
138 | }, | |
139 | { | |
140 | code: "class C { [foo\n]= 0 }", | |
141 | options: ["none"], | |
142 | parserOptions: { ecmaVersion: 2022 } | |
143 | }, | |
144 | { | |
145 | code: "class C { foo\n=\n0 }", | |
146 | options: ["none", { overrides: { "=": "ignore" } }], | |
147 | parserOptions: { ecmaVersion: 2022 } | |
6f036462 | 148 | } |
eb39fafa DC |
149 | ], |
150 | ||
151 | invalid: [ | |
152 | { | |
153 | code: "1\n+ 1", | |
154 | output: "1 +\n1", | |
155 | errors: [{ | |
156 | messageId: "operatorAtEnd", | |
157 | data: { operator: "+" }, | |
158 | type: "BinaryExpression", | |
159 | line: 2, | |
160 | column: 1, | |
161 | endLine: 2, | |
162 | endColumn: 2 | |
163 | }] | |
164 | }, | |
165 | { | |
166 | code: "1 + 2 \n + 3", | |
167 | output: "1 + 2 + \n 3", | |
168 | errors: [{ | |
169 | messageId: "operatorAtEnd", | |
170 | data: { operator: "+" }, | |
171 | type: "BinaryExpression", | |
172 | line: 2, | |
173 | column: 2, | |
174 | endLine: 2, | |
175 | endColumn: 3 | |
176 | }] | |
177 | }, | |
178 | { | |
179 | code: "1\n+\n1", | |
180 | output: "1+\n1", | |
181 | errors: [{ | |
182 | messageId: "badLinebreak", | |
183 | data: { operator: "+" }, | |
184 | type: "BinaryExpression", | |
185 | line: 2, | |
186 | column: 1, | |
187 | endLine: 2, | |
188 | endColumn: 2 | |
189 | }] | |
190 | }, | |
191 | { | |
192 | code: "1 + (1\n+ 1)", | |
193 | output: "1 + (1 +\n1)", | |
194 | errors: [{ | |
195 | messageId: "operatorAtEnd", | |
196 | data: { operator: "+" }, | |
197 | type: "BinaryExpression", | |
198 | line: 2, | |
199 | column: 1, | |
200 | endLine: 2, | |
201 | endColumn: 2 | |
202 | }] | |
203 | }, | |
204 | { | |
205 | code: "f(1\n+ 1);", | |
206 | output: "f(1 +\n1);", | |
207 | errors: [{ | |
208 | messageId: "operatorAtEnd", | |
209 | data: { operator: "+" }, | |
210 | type: "BinaryExpression", | |
211 | line: 2, | |
212 | column: 1, | |
213 | endLine: 2, | |
214 | endColumn: 2 | |
215 | }] | |
216 | }, | |
217 | { | |
218 | code: "1 \n || 1", | |
219 | output: "1 || \n 1", | |
220 | errors: [{ | |
221 | messageId: "operatorAtEnd", | |
222 | data: { operator: "||" }, | |
223 | type: "LogicalExpression", | |
224 | line: 2, | |
225 | column: 2, | |
226 | endLine: 2, | |
227 | endColumn: 4 | |
228 | }] | |
229 | }, | |
230 | { | |
231 | code: "a\n += 1", | |
232 | output: "a +=\n 1", | |
233 | errors: [{ | |
234 | messageId: "operatorAtEnd", | |
235 | data: { operator: "+=" }, | |
236 | type: "AssignmentExpression", | |
237 | line: 2, | |
238 | column: 2, | |
239 | endLine: 2, | |
240 | endColumn: 4 | |
241 | }] | |
242 | }, | |
243 | { | |
244 | code: "var a\n = 1", | |
245 | output: "var a =\n 1", | |
246 | errors: [{ | |
247 | messageId: "operatorAtEnd", | |
248 | data: { operator: "=" }, | |
249 | type: "VariableDeclarator", | |
250 | line: 2, | |
251 | column: 2, | |
252 | endLine: 2, | |
253 | endColumn: 3 | |
254 | }] | |
255 | }, | |
256 | { | |
257 | code: "(b)\n*\n(c)", | |
258 | output: "(b)*\n(c)", | |
259 | errors: [{ | |
260 | messageId: "badLinebreak", | |
261 | data: { operator: "*" }, | |
262 | type: "BinaryExpression", | |
263 | line: 2, | |
264 | column: 1, | |
265 | endLine: 2, | |
266 | endColumn: 2 | |
267 | }] | |
268 | }, | |
269 | { | |
270 | code: "answer = everything ?\n 42 :\n foo;", | |
271 | output: "answer = everything\n ? 42\n : foo;", | |
272 | errors: [{ | |
273 | messageId: "operatorAtBeginning", | |
274 | data: { operator: "?" }, | |
275 | type: "ConditionalExpression", | |
276 | line: 1, | |
277 | column: 21, | |
278 | endLine: 1, | |
279 | endColumn: 22 | |
280 | }, | |
281 | { | |
282 | messageId: "operatorAtBeginning", | |
283 | data: { operator: ":" }, | |
284 | type: "ConditionalExpression", | |
285 | line: 2, | |
286 | column: 6, | |
287 | endLine: 2, | |
288 | endColumn: 7 | |
289 | }] | |
290 | }, | |
291 | ||
292 | { | |
293 | code: "answer = everything \n? 42 \n: foo;", | |
294 | output: "answer = everything ? \n42 : \nfoo;", | |
295 | options: ["after"], | |
296 | errors: [{ | |
297 | messageId: "operatorAtEnd", | |
298 | data: { operator: "?" }, | |
299 | type: "ConditionalExpression", | |
300 | line: 2, | |
301 | column: 1, | |
302 | endLine: 2, | |
303 | endColumn: 2 | |
304 | }, | |
305 | { | |
306 | messageId: "operatorAtEnd", | |
307 | data: { operator: ":" }, | |
308 | type: "ConditionalExpression", | |
309 | line: 3, | |
310 | column: 1, | |
311 | endLine: 3, | |
312 | endColumn: 2 | |
313 | }] | |
314 | }, | |
315 | ||
316 | { | |
317 | code: "1 +\n1", | |
318 | output: "1\n+ 1", | |
319 | options: ["before"], | |
320 | errors: [{ | |
321 | messageId: "operatorAtBeginning", | |
322 | data: { operator: "+" }, | |
323 | type: "BinaryExpression", | |
324 | line: 1, | |
325 | column: 3, | |
326 | endLine: 1, | |
327 | endColumn: 4 | |
328 | }] | |
329 | }, | |
330 | { | |
331 | code: "f(1 +\n1);", | |
332 | output: "f(1\n+ 1);", | |
333 | options: ["before"], | |
334 | errors: [{ | |
335 | messageId: "operatorAtBeginning", | |
336 | data: { operator: "+" }, | |
337 | type: "BinaryExpression", | |
338 | line: 1, | |
339 | column: 5, | |
340 | endLine: 1, | |
341 | endColumn: 6 | |
342 | }] | |
343 | }, | |
344 | { | |
345 | code: "1 || \n 1", | |
346 | output: "1 \n || 1", | |
347 | options: ["before"], | |
348 | errors: [{ | |
349 | messageId: "operatorAtBeginning", | |
350 | data: { operator: "||" }, | |
351 | type: "LogicalExpression", | |
352 | line: 1, | |
353 | column: 3, | |
354 | endLine: 1, | |
355 | endColumn: 5 | |
356 | }] | |
357 | }, | |
358 | { | |
359 | code: "a += \n1", | |
360 | output: "a \n+= 1", | |
361 | options: ["before"], | |
362 | errors: [{ | |
363 | messageId: "operatorAtBeginning", | |
364 | data: { operator: "+=" }, | |
365 | type: "AssignmentExpression", | |
366 | line: 1, | |
367 | column: 3, | |
368 | endLine: 1, | |
369 | endColumn: 5 | |
370 | }] | |
371 | }, | |
372 | { | |
373 | code: "var a = \n1", | |
374 | output: "var a \n= 1", | |
375 | options: ["before"], | |
376 | errors: [{ | |
377 | messageId: "operatorAtBeginning", | |
378 | data: { operator: "=" }, | |
379 | type: "VariableDeclarator", | |
380 | line: 1, | |
381 | column: 7, | |
382 | endLine: 1, | |
383 | endColumn: 8 | |
384 | }] | |
385 | }, | |
386 | { | |
387 | code: "answer = everything ?\n 42 :\n foo;", | |
388 | output: "answer = everything\n ? 42\n : foo;", | |
389 | options: ["before"], | |
390 | errors: [{ | |
391 | messageId: "operatorAtBeginning", | |
392 | data: { operator: "?" }, | |
393 | type: "ConditionalExpression", | |
394 | line: 1, | |
395 | column: 21, | |
396 | endLine: 1, | |
397 | endColumn: 22 | |
398 | }, | |
399 | { | |
400 | messageId: "operatorAtBeginning", | |
401 | data: { operator: ":" }, | |
402 | type: "ConditionalExpression", | |
403 | line: 2, | |
404 | column: 6, | |
405 | endLine: 2, | |
406 | endColumn: 7 | |
407 | }] | |
408 | }, | |
409 | ||
410 | { | |
411 | code: "1 +\n1", | |
412 | output: "1 +1", | |
413 | options: ["none"], | |
414 | errors: [{ | |
415 | messageId: "noLinebreak", | |
416 | data: { operator: "+" }, | |
417 | type: "BinaryExpression", | |
418 | line: 1, | |
419 | column: 3, | |
420 | endLine: 1, | |
421 | endColumn: 4 | |
422 | }] | |
423 | }, | |
424 | { | |
425 | code: "1\n+1", | |
426 | output: "1+1", | |
427 | options: ["none"], | |
428 | errors: [{ | |
429 | messageId: "noLinebreak", | |
430 | data: { operator: "+" }, | |
431 | type: "BinaryExpression", | |
432 | line: 2, | |
433 | column: 1, | |
434 | endLine: 2, | |
435 | endColumn: 2 | |
436 | }] | |
437 | }, | |
438 | { | |
439 | code: "f(1 +\n1);", | |
440 | output: "f(1 +1);", | |
441 | options: ["none"], | |
442 | errors: [{ | |
443 | messageId: "noLinebreak", | |
444 | data: { operator: "+" }, | |
445 | type: "BinaryExpression", | |
446 | line: 1, | |
447 | column: 5, | |
448 | endLine: 1, | |
449 | endColumn: 6 | |
450 | }] | |
451 | }, | |
452 | { | |
453 | code: "f(1\n+ 1);", | |
454 | output: "f(1+ 1);", | |
455 | options: ["none"], | |
456 | errors: [{ | |
457 | messageId: "noLinebreak", | |
458 | data: { operator: "+" }, | |
459 | type: "BinaryExpression", | |
460 | line: 2, | |
461 | column: 1, | |
462 | endLine: 2, | |
463 | endColumn: 2 | |
464 | }] | |
465 | }, | |
466 | { | |
467 | code: "1 || \n 1", | |
468 | output: "1 || 1", | |
469 | options: ["none"], | |
470 | errors: [{ | |
471 | messageId: "noLinebreak", | |
472 | data: { operator: "||" }, | |
473 | type: "LogicalExpression", | |
474 | line: 1, | |
475 | column: 3, | |
476 | endLine: 1, | |
477 | endColumn: 5 | |
478 | }] | |
479 | }, | |
480 | { | |
481 | code: "1 \n || 1", | |
482 | output: "1 || 1", | |
483 | options: ["none"], | |
484 | errors: [{ | |
485 | messageId: "noLinebreak", | |
486 | data: { operator: "||" }, | |
487 | type: "LogicalExpression", | |
488 | line: 2, | |
489 | column: 2, | |
490 | endLine: 2, | |
491 | endColumn: 4 | |
492 | }] | |
493 | }, | |
494 | { | |
495 | code: "a += \n1", | |
496 | output: "a += 1", | |
497 | options: ["none"], | |
498 | errors: [{ | |
499 | messageId: "noLinebreak", | |
500 | data: { operator: "+=" }, | |
501 | type: "AssignmentExpression", | |
502 | line: 1, | |
503 | column: 3, | |
504 | endLine: 1, | |
505 | endColumn: 5 | |
506 | }] | |
507 | }, | |
508 | { | |
509 | code: "a \n+= 1", | |
510 | output: "a += 1", | |
511 | options: ["none"], | |
512 | errors: [{ | |
513 | messageId: "noLinebreak", | |
514 | data: { operator: "+=" }, | |
515 | type: "AssignmentExpression", | |
516 | line: 2, | |
517 | column: 1, | |
518 | endLine: 2, | |
519 | endColumn: 3 | |
520 | }] | |
521 | }, | |
522 | { | |
523 | code: "var a = \n1", | |
524 | output: "var a = 1", | |
525 | options: ["none"], | |
526 | errors: [{ | |
527 | messageId: "noLinebreak", | |
528 | data: { operator: "=" }, | |
529 | type: "VariableDeclarator", | |
530 | line: 1, | |
531 | column: 7, | |
532 | endLine: 1, | |
533 | endColumn: 8 | |
534 | }] | |
535 | }, | |
536 | { | |
537 | code: "var a \n = 1", | |
538 | output: "var a = 1", | |
539 | options: ["none"], | |
540 | errors: [{ | |
541 | messageId: "noLinebreak", | |
542 | data: { operator: "=" }, | |
543 | type: "VariableDeclarator", | |
544 | line: 2, | |
545 | column: 2, | |
546 | endLine: 2, | |
547 | endColumn: 3 | |
548 | }] | |
549 | }, | |
550 | { | |
551 | code: "answer = everything ?\n 42 \n: foo;", | |
552 | output: "answer = everything ? 42 : foo;", | |
553 | options: ["none"], | |
554 | errors: [{ | |
555 | messageId: "noLinebreak", | |
556 | data: { operator: "?" }, | |
557 | type: "ConditionalExpression", | |
558 | line: 1, | |
559 | column: 21, | |
560 | endLine: 1, | |
561 | endColumn: 22 | |
562 | }, | |
563 | { | |
564 | messageId: "noLinebreak", | |
565 | data: { operator: ":" }, | |
566 | type: "ConditionalExpression", | |
567 | line: 3, | |
568 | column: 1, | |
569 | endLine: 3, | |
570 | endColumn: 2 | |
571 | }] | |
572 | }, | |
573 | { | |
574 | code: "answer = everything\n?\n42 + 43\n:\nfoo;", | |
575 | output: "answer = everything?42 + 43:foo;", | |
576 | options: ["none"], | |
577 | errors: [{ | |
578 | messageId: "badLinebreak", | |
579 | data: { operator: "?" }, | |
580 | type: "ConditionalExpression", | |
581 | line: 2, | |
582 | column: 1, | |
583 | endLine: 2, | |
584 | endColumn: 2 | |
585 | }, | |
586 | { | |
587 | messageId: "badLinebreak", | |
588 | data: { operator: ":" }, | |
589 | type: "ConditionalExpression", | |
590 | line: 4, | |
591 | column: 1, | |
592 | endLine: 4, | |
593 | endColumn: 2 | |
594 | }] | |
595 | }, | |
596 | { | |
597 | code: "a = b \n >>> \n c;", | |
598 | output: "a = b >>> \n c;", | |
599 | errors: [{ | |
600 | messageId: "badLinebreak", | |
601 | data: { operator: ">>>" }, | |
602 | type: "BinaryExpression", | |
603 | line: 2, | |
604 | column: 3, | |
605 | endLine: 2, | |
606 | endColumn: 6 | |
607 | }] | |
608 | }, | |
609 | { | |
610 | code: "foo +=\n42;\nbar -=\n12\n+ 5;", | |
611 | output: "foo +=42;\nbar -=\n12\n+ 5;", | |
612 | options: ["after", { overrides: { "+=": "none", "+": "before" } }], | |
613 | errors: [{ | |
614 | messageId: "noLinebreak", | |
615 | data: { operator: "+=" }, | |
616 | type: "AssignmentExpression", | |
617 | line: 1, | |
618 | column: 5, | |
619 | endLine: 1, | |
620 | endColumn: 7 | |
621 | }] | |
622 | }, | |
623 | { | |
624 | code: "answer = everything\n?\n42\n:\nfoo;", | |
625 | output: "answer = everything\n?\n42\n:foo;", | |
626 | options: ["after", { overrides: { "?": "ignore", ":": "before" } }], | |
627 | errors: [{ | |
628 | messageId: "badLinebreak", | |
629 | data: { operator: ":" }, | |
630 | type: "ConditionalExpression", | |
631 | line: 4, | |
632 | column: 1, | |
633 | endLine: 4, | |
634 | endColumn: 2 | |
635 | }] | |
636 | }, | |
637 | { | |
638 | ||
639 | // Insert an additional space to avoid changing the operator to ++ or --. | |
640 | code: "foo+\n+bar", | |
641 | output: "foo\n+ +bar", | |
642 | options: ["before"], | |
643 | errors: [{ | |
644 | messageId: "operatorAtBeginning", | |
645 | data: { operator: "+" }, | |
646 | type: "BinaryExpression", | |
647 | line: 1, | |
648 | column: 4, | |
649 | endLine: 1, | |
650 | endColumn: 5 | |
651 | }] | |
652 | }, | |
653 | { | |
654 | code: "foo //comment\n&& bar", | |
655 | output: "foo && //comment\nbar", | |
656 | errors: [{ | |
657 | messageId: "operatorAtEnd", | |
658 | data: { operator: "&&" }, | |
659 | type: "LogicalExpression", | |
660 | line: 2, | |
661 | column: 1, | |
662 | endLine: 2, | |
663 | endColumn: 3 | |
664 | }] | |
665 | }, | |
666 | { | |
667 | code: "foo//comment\n+\nbar", | |
668 | output: null, | |
669 | errors: [{ | |
670 | messageId: "badLinebreak", | |
671 | data: { operator: "+" }, | |
672 | type: "BinaryExpression", | |
673 | line: 2, | |
674 | column: 1, | |
675 | endLine: 2, | |
676 | endColumn: 2 | |
677 | }] | |
678 | }, | |
679 | { | |
680 | code: "foo\n+//comment\nbar", | |
681 | output: null, | |
682 | options: ["before"], | |
683 | errors: [{ | |
684 | messageId: "badLinebreak", | |
685 | data: { operator: "+" }, | |
686 | type: "BinaryExpression", | |
687 | line: 2, | |
688 | column: 1, | |
689 | endLine: 2, | |
690 | endColumn: 2 | |
691 | }] | |
692 | }, | |
693 | { | |
694 | code: "foo /* a */ \n+ /* b */ bar", | |
695 | output: null, // Not fixed because there is a comment on both sides | |
696 | errors: [{ | |
697 | messageId: "operatorAtEnd", | |
698 | data: { operator: "+" }, | |
699 | type: "BinaryExpression", | |
700 | line: 2, | |
701 | column: 1, | |
702 | endLine: 2, | |
703 | endColumn: 2 | |
704 | }] | |
705 | }, | |
706 | { | |
707 | code: "foo /* a */ +\n /* b */ bar", | |
708 | output: null, // Not fixed because there is a comment on both sides | |
709 | options: ["before"], | |
710 | errors: [{ | |
711 | messageId: "operatorAtBeginning", | |
712 | data: { operator: "+" }, | |
713 | type: "BinaryExpression", | |
714 | line: 1, | |
715 | column: 13, | |
716 | endLine: 1, | |
717 | endColumn: 14 | |
718 | }] | |
d3726936 TL |
719 | }, |
720 | { | |
721 | code: "foo ??\n bar", | |
722 | output: "foo\n ?? bar", | |
723 | options: ["after", { overrides: { "??": "before" } }], | |
724 | parserOptions: { ecmaVersion: 2020 }, | |
725 | errors: [{ | |
726 | messageId: "operatorAtBeginning", | |
727 | data: { operator: "??" } | |
728 | }] | |
6f036462 TL |
729 | }, |
730 | ||
731 | { | |
732 | code: "a \n &&= b", | |
733 | output: "a &&= \n b", | |
734 | options: ["after"], | |
735 | parserOptions: { ecmaVersion: 2021 }, | |
736 | errors: [{ | |
737 | messageId: "operatorAtEnd", | |
738 | data: { operator: "&&=" }, | |
739 | type: "AssignmentExpression", | |
740 | line: 2, | |
741 | column: 3, | |
742 | endLine: 2, | |
743 | endColumn: 6 | |
744 | }] | |
745 | }, | |
746 | { | |
747 | code: "a ||=\n b", | |
748 | output: "a\n ||= b", | |
749 | options: ["before"], | |
750 | parserOptions: { ecmaVersion: 2021 }, | |
751 | errors: [{ | |
752 | messageId: "operatorAtBeginning", | |
753 | data: { operator: "||=" }, | |
754 | type: "AssignmentExpression", | |
755 | line: 1, | |
756 | column: 3, | |
757 | endLine: 1, | |
758 | endColumn: 6 | |
759 | }] | |
760 | }, | |
761 | { | |
762 | code: "a ??=\n b", | |
763 | output: "a ??= b", | |
764 | options: ["none"], | |
765 | parserOptions: { ecmaVersion: 2021 }, | |
766 | errors: [{ | |
767 | messageId: "noLinebreak", | |
768 | data: { operator: "??=" }, | |
769 | type: "AssignmentExpression", | |
770 | line: 1, | |
771 | column: 4, | |
772 | endLine: 1, | |
773 | endColumn: 7 | |
774 | }] | |
775 | }, | |
776 | { | |
777 | code: "a \n &&= b", | |
778 | output: "a &&= b", | |
779 | options: ["before", { overrides: { "&&=": "none" } }], | |
780 | parserOptions: { ecmaVersion: 2021 }, | |
781 | errors: [{ | |
782 | messageId: "noLinebreak", | |
783 | data: { operator: "&&=" }, | |
784 | type: "AssignmentExpression", | |
785 | line: 2, | |
786 | column: 3, | |
787 | endLine: 2, | |
788 | endColumn: 6 | |
789 | }] | |
790 | }, | |
791 | { | |
792 | code: "a ||=\nb", | |
793 | output: "a\n||= b", | |
794 | options: ["after", { overrides: { "||=": "before" } }], | |
795 | parserOptions: { ecmaVersion: 2021 }, | |
796 | errors: [{ | |
797 | messageId: "operatorAtBeginning", | |
798 | data: { operator: "||=" }, | |
799 | type: "AssignmentExpression", | |
800 | line: 1, | |
801 | column: 3, | |
802 | endLine: 1, | |
803 | endColumn: 6 | |
804 | }] | |
805 | }, | |
806 | { | |
807 | code: "a\n??=b", | |
808 | output: "a??=\nb", | |
809 | options: ["none", { overrides: { "??=": "after" } }], | |
810 | parserOptions: { ecmaVersion: 2021 }, | |
811 | errors: [{ | |
812 | messageId: "operatorAtEnd", | |
813 | data: { operator: "??=" }, | |
814 | type: "AssignmentExpression", | |
815 | line: 2, | |
816 | column: 1, | |
817 | endLine: 2, | |
818 | endColumn: 4 | |
819 | }] | |
609c276f TL |
820 | }, |
821 | ||
822 | // class fields | |
823 | { | |
824 | code: "class C { a\n= 0; }", | |
825 | output: "class C { a =\n0; }", | |
826 | options: ["after"], | |
827 | parserOptions: { ecmaVersion: 2022 }, | |
828 | errors: [{ | |
829 | messageId: "operatorAtEnd", | |
830 | data: { operator: "=" }, | |
831 | type: "PropertyDefinition", | |
832 | line: 2, | |
833 | column: 1, | |
834 | endLine: 2, | |
835 | endColumn: 2 | |
836 | }] | |
837 | }, | |
838 | { | |
839 | code: "class C { a =\n0; }", | |
840 | output: "class C { a\n= 0; }", | |
841 | options: ["before"], | |
842 | parserOptions: { ecmaVersion: 2022 }, | |
843 | errors: [{ | |
844 | messageId: "operatorAtBeginning", | |
845 | data: { operator: "=" }, | |
846 | type: "PropertyDefinition", | |
847 | line: 1, | |
848 | column: 13, | |
849 | endLine: 1, | |
850 | endColumn: 14 | |
851 | }] | |
852 | }, | |
853 | { | |
854 | code: "class C { a =\n0; }", | |
855 | output: "class C { a =0; }", | |
856 | options: ["none"], | |
857 | parserOptions: { ecmaVersion: 2022 }, | |
858 | errors: [{ | |
859 | messageId: "noLinebreak", | |
860 | data: { operator: "=" }, | |
861 | type: "PropertyDefinition", | |
862 | line: 1, | |
863 | column: 13, | |
864 | endLine: 1, | |
865 | endColumn: 14 | |
866 | }] | |
867 | }, | |
868 | { | |
869 | code: "class C { [a]\n= 0; }", | |
870 | output: "class C { [a] =\n0; }", | |
871 | options: ["after"], | |
872 | parserOptions: { ecmaVersion: 2022 }, | |
873 | errors: [{ | |
874 | messageId: "operatorAtEnd", | |
875 | data: { operator: "=" }, | |
876 | type: "PropertyDefinition", | |
877 | line: 2, | |
878 | column: 1, | |
879 | endLine: 2, | |
880 | endColumn: 2 | |
881 | }] | |
882 | }, | |
883 | { | |
884 | code: "class C { [a] =\n0; }", | |
885 | output: "class C { [a]\n= 0; }", | |
886 | options: ["before"], | |
887 | parserOptions: { ecmaVersion: 2022 }, | |
888 | errors: [{ | |
889 | messageId: "operatorAtBeginning", | |
890 | data: { operator: "=" }, | |
891 | type: "PropertyDefinition", | |
892 | line: 1, | |
893 | column: 15, | |
894 | endLine: 1, | |
895 | endColumn: 16 | |
896 | }] | |
897 | }, | |
898 | { | |
899 | code: "class C { [a]\n =0; }", | |
900 | output: "class C { [a] =0; }", | |
901 | options: ["none"], | |
902 | parserOptions: { ecmaVersion: 2022 }, | |
903 | errors: [{ | |
904 | messageId: "noLinebreak", | |
905 | data: { operator: "=" }, | |
906 | type: "PropertyDefinition", | |
907 | line: 2, | |
908 | column: 2, | |
909 | endLine: 2, | |
910 | endColumn: 3 | |
911 | }] | |
eb39fafa DC |
912 | } |
913 | ] | |
914 | }); |