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