]> git.proxmox.com Git - pve-eslint.git/blob - eslint/tests/lib/rules/no-extra-semi.js
import 8.3.0 source
[pve-eslint.git] / eslint / tests / lib / rules / no-extra-semi.js
1 /**
2 * @fileoverview Tests for no-extra-semi rule.
3 * @author Nicholas C. Zakas
4 */
5
6 "use strict";
7
8 //------------------------------------------------------------------------------
9 // Requirements
10 //------------------------------------------------------------------------------
11
12 const rule = require("../../../lib/rules/no-extra-semi"),
13 { RuleTester } = require("../../../lib/rule-tester");
14
15 //------------------------------------------------------------------------------
16 // Tests
17 //------------------------------------------------------------------------------
18
19 const ruleTester = new RuleTester();
20
21 ruleTester.run("no-extra-semi", rule, {
22 valid: [
23 "var x = 5;",
24 "function foo(){}",
25 "for(;;);",
26 "while(0);",
27 "do;while(0);",
28 "for(a in b);",
29 { code: "for(a of b);", parserOptions: { ecmaVersion: 6 } },
30 "if(true);",
31 "if(true); else;",
32 "foo: ;",
33 "with(foo);",
34
35 // Class body.
36 { code: "class A { }", parserOptions: { ecmaVersion: 6 } },
37 { code: "var A = class { };", parserOptions: { ecmaVersion: 6 } },
38 { code: "class A { a() { this; } }", parserOptions: { ecmaVersion: 6 } },
39 { code: "var A = class { a() { this; } };", parserOptions: { ecmaVersion: 6 } },
40 { code: "class A { } a;", parserOptions: { ecmaVersion: 6 } },
41 { code: "class A { field; }", parserOptions: { ecmaVersion: 2022 } },
42 { code: "class A { field = 0; }", parserOptions: { ecmaVersion: 2022 } },
43 { code: "class A { static { foo; } }", parserOptions: { ecmaVersion: 2022 } },
44
45 // modules
46 { code: "export const x = 42;", parserOptions: { ecmaVersion: 6, sourceType: "module" } },
47 { code: "export default 42;", parserOptions: { ecmaVersion: 6, sourceType: "module" } }
48 ],
49 invalid: [
50 {
51 code: "var x = 5;;",
52 output: "var x = 5;",
53 errors: [{ messageId: "unexpected", type: "EmptyStatement" }]
54 },
55 {
56 code: "function foo(){};",
57 output: "function foo(){}",
58 errors: [{ messageId: "unexpected", type: "EmptyStatement" }]
59 },
60 {
61 code: "for(;;);;",
62 output: "for(;;);",
63 errors: [{ messageId: "unexpected", type: "EmptyStatement" }]
64 },
65 {
66 code: "while(0);;",
67 output: "while(0);",
68 errors: [{ messageId: "unexpected", type: "EmptyStatement" }]
69 },
70 {
71 code: "do;while(0);;",
72 output: "do;while(0);",
73 errors: [{ messageId: "unexpected", type: "EmptyStatement" }]
74 },
75 {
76 code: "for(a in b);;",
77 output: "for(a in b);",
78 errors: [{ messageId: "unexpected", type: "EmptyStatement" }]
79 },
80 {
81 code: "for(a of b);;",
82 output: "for(a of b);",
83 parserOptions: { ecmaVersion: 6 },
84 errors: [{ messageId: "unexpected", type: "EmptyStatement" }]
85 },
86 {
87 code: "if(true);;",
88 output: "if(true);",
89 errors: [{ messageId: "unexpected", type: "EmptyStatement" }]
90 },
91 {
92 code: "if(true){} else;;",
93 output: "if(true){} else;",
94 errors: [{ messageId: "unexpected", type: "EmptyStatement" }]
95 },
96 {
97 code: "if(true){;} else {;}",
98 output: "if(true){} else {}",
99 errors: [{ messageId: "unexpected", type: "EmptyStatement" }, { messageId: "unexpected", type: "EmptyStatement" }]
100 },
101 {
102 code: "foo:;;",
103 output: "foo:;",
104 errors: [{ messageId: "unexpected", type: "EmptyStatement" }]
105 },
106 {
107 code: "with(foo);;",
108 output: "with(foo);",
109 errors: [{ messageId: "unexpected", type: "EmptyStatement" }]
110 },
111 {
112 code: "with(foo){;}",
113 output: "with(foo){}",
114 errors: [{ messageId: "unexpected", type: "EmptyStatement" }]
115 },
116 {
117 code: "class A { static { ; } }",
118 output: "class A { static { } }",
119 parserOptions: { ecmaVersion: 2022 },
120 errors: [{ messageId: "unexpected", type: "EmptyStatement", column: 20 }]
121 },
122 {
123 code: "class A { static { a;; } }",
124 output: "class A { static { a; } }",
125 parserOptions: { ecmaVersion: 2022 },
126 errors: [{ messageId: "unexpected", type: "EmptyStatement", column: 22 }]
127 },
128
129 // Class body.
130 {
131 code: "class A { ; }",
132 output: "class A { }",
133 parserOptions: { ecmaVersion: 6 },
134 errors: [{ messageId: "unexpected", type: "Punctuator", column: 11 }]
135 },
136 {
137 code: "class A { /*a*/; }",
138 output: "class A { /*a*/ }",
139 parserOptions: { ecmaVersion: 6 },
140 errors: [{ messageId: "unexpected", type: "Punctuator", column: 16 }]
141 },
142 {
143 code: "class A { ; a() {} }",
144 output: "class A { a() {} }",
145 parserOptions: { ecmaVersion: 6 },
146 errors: [{ messageId: "unexpected", type: "Punctuator", column: 11 }]
147 },
148 {
149 code: "class A { a() {}; }",
150 output: "class A { a() {} }",
151 parserOptions: { ecmaVersion: 6 },
152 errors: [{ messageId: "unexpected", type: "Punctuator", column: 17 }]
153 },
154 {
155 code: "class A { a() {}; b() {} }",
156 output: "class A { a() {} b() {} }",
157 parserOptions: { ecmaVersion: 6 },
158 errors: [{ messageId: "unexpected", type: "Punctuator", column: 17 }]
159 },
160 {
161 code: "class A {; a() {}; b() {}; }",
162 output: "class A { a() {} b() {} }",
163 parserOptions: { ecmaVersion: 6 },
164 errors: [
165 { messageId: "unexpected", type: "Punctuator", column: 10 },
166 { messageId: "unexpected", type: "Punctuator", column: 18 },
167 { messageId: "unexpected", type: "Punctuator", column: 26 }
168 ]
169 },
170 {
171 code: "class A { a() {}; get b() {} }",
172 output: "class A { a() {} get b() {} }",
173 parserOptions: { ecmaVersion: 6 },
174 errors: [{ messageId: "unexpected", type: "Punctuator", column: 17 }]
175 },
176 {
177 code: "class A { field;; }",
178 output: "class A { field; }",
179 parserOptions: { ecmaVersion: 2022 },
180 errors: [{ messageId: "unexpected", type: "Punctuator", column: 17 }]
181 },
182 {
183 code: "class A { static {}; }",
184 output: "class A { static {} }",
185 parserOptions: { ecmaVersion: 2022 },
186 errors: [{ messageId: "unexpected", type: "Punctuator", column: 20 }]
187 },
188 {
189 code: "class A { static { a; }; foo(){} }",
190 output: "class A { static { a; } foo(){} }",
191 parserOptions: { ecmaVersion: 2022 },
192 errors: [{ messageId: "unexpected", type: "Punctuator", column: 24 }]
193 }
194 ]
195 });