]> git.proxmox.com Git - pve-eslint.git/blob - eslint/tests/lib/rules/semi-style.js
first commit
[pve-eslint.git] / eslint / tests / lib / rules / semi-style.js
1 /**
2 * @fileoverview Tests for semi-style rule.
3 * @author Toru Nagashima
4 */
5
6 "use strict";
7
8 //------------------------------------------------------------------------------
9 // Requirements
10 //------------------------------------------------------------------------------
11
12 const rule = require("../../../lib/rules/semi-style"),
13 { RuleTester } = require("../../../lib/rule-tester");
14
15 //------------------------------------------------------------------------------
16 // Tests
17 //------------------------------------------------------------------------------
18
19 const ruleTester = new RuleTester();
20
21 ruleTester.run("semi-style", rule, {
22 valid: [
23 ";",
24 ";foo;bar;baz;",
25 "foo;\nbar;",
26 "for(a;b;c);",
27 "for(a;\nb;\nc);",
28 "for((a\n);\n(b\n);\n(c));",
29 "if(a)foo;\nbar",
30 { code: ";", options: ["last"] },
31 { code: ";foo;bar;baz;", options: ["last"] },
32 { code: "foo;\nbar;", options: ["last"] },
33 { code: "for(a;b;c);", options: ["last"] },
34 { code: "for(a;\nb;\nc);", options: ["last"] },
35 { code: "for((a\n);\n(b\n);\n(c));", options: ["last"] },
36 { code: "if(a)foo;\nbar", options: ["last"] },
37 { code: ";", options: ["first"] },
38 { code: ";foo;bar;baz;", options: ["first"] },
39 { code: "foo\n;bar;", options: ["first"] },
40 { code: "for(a;b;c);", options: ["first"] },
41 { code: "for(a;\nb;\nc);", options: ["first"] },
42 { code: "for((a\n);\n(b\n);\n(c));", options: ["first"] },
43
44 // edge cases
45 {
46 code: `
47 {
48 ;
49 }
50 `,
51 options: ["first"]
52 },
53 {
54 code: `
55 while (a)
56 ;
57 foo
58 `,
59 options: ["first"]
60 },
61 {
62 code: `
63 do
64 ;
65 while (a)
66 `,
67 options: ["first"]
68 },
69 {
70 code: `
71 do
72 foo;
73 while (a)
74 `,
75 options: ["first"]
76 },
77 {
78 code: `
79 if (a)
80 foo;
81 else
82 bar
83 `,
84 options: ["first"]
85 },
86 {
87 code: `
88 if (a)
89 foo
90 ;bar
91 `,
92 options: ["first"]
93 },
94 {
95 code: `
96 {
97 ;
98 }
99 `,
100 options: ["last"]
101 },
102 {
103 code: `
104 switch (a) {
105 case 1:
106 ;foo
107 }
108 `,
109 options: ["last"]
110 },
111 {
112 code: `
113 while (a)
114 ;
115 foo
116 `,
117 options: ["last"]
118 },
119 {
120 code: `
121 do
122 ;
123 while (a)
124 `,
125 options: ["last"]
126 }
127 ],
128 invalid: [
129 {
130 code: "foo\n;bar",
131 output: "foo;\nbar",
132 errors: [{
133 messageId: "expectedSemiColon",
134 data: {
135 pos: "the end of the previous line"
136 }
137 }]
138 },
139 {
140 code: "if(a)foo\n;bar",
141 output: "if(a)foo;\nbar",
142 errors: [{
143 messageId: "expectedSemiColon",
144 data: {
145 pos: "the end of the previous line"
146 }
147 }]
148 },
149 {
150 code: "var foo\n;bar",
151 output: "var foo;\nbar",
152 errors: [{
153 messageId: "expectedSemiColon",
154 data: {
155 pos: "the end of the previous line"
156 }
157 }]
158 },
159 {
160 code: "foo\n;\nbar",
161 output: "foo;\nbar",
162 errors: [{
163 messageId: "expectedSemiColon",
164 data: {
165 pos: "the end of the previous line"
166 }
167 }]
168 },
169 {
170 code: "for(a\n;b;c)d",
171 output: "for(a;\nb;c)d",
172 errors: [{
173 messageId: "expectedSemiColon",
174 data: {
175 pos: "the end of the previous line"
176 }
177 }]
178 },
179 {
180 code: "for(a;b\n;c)d",
181 output: "for(a;b;\nc)d",
182 errors: [{
183 messageId: "expectedSemiColon",
184 data: {
185 pos: "the end of the previous line"
186 }
187 }]
188 },
189 {
190 code: "do;while(a)\n;b",
191 output: "do;while(a);\nb",
192 errors: [{
193 messageId: "expectedSemiColon",
194 data: {
195 pos: "the end of the previous line"
196 }
197 }]
198 },
199
200 {
201 code: "foo\n;bar",
202 output: "foo;\nbar",
203 options: ["last"],
204 errors: [{
205 messageId: "expectedSemiColon",
206 data: {
207 pos: "the end of the previous line"
208 }
209 }]
210 },
211 {
212 code: "if(a)foo\n;bar",
213 output: "if(a)foo;\nbar",
214 options: ["last"],
215 errors: [{
216 messageId: "expectedSemiColon",
217 data: {
218 pos: "the end of the previous line"
219 }
220 }]
221 },
222 {
223 code: "var foo\n;bar",
224 output: "var foo;\nbar",
225 options: ["last"],
226 errors: [{
227 messageId: "expectedSemiColon",
228 data: {
229 pos: "the end of the previous line"
230 }
231 }]
232 },
233 {
234 code: "foo\n;\nbar",
235 output: "foo;\nbar",
236 options: ["last"],
237 errors: [{
238 messageId: "expectedSemiColon",
239 data: {
240 pos: "the end of the previous line"
241 }
242 }]
243 },
244 {
245 code: "for(a\n;b;c)d",
246 output: "for(a;\nb;c)d",
247 options: ["last"],
248 errors: [{
249 messageId: "expectedSemiColon",
250 data: {
251 pos: "the end of the previous line"
252 }
253 }]
254 },
255 {
256 code: "for(a;b\n;c)d",
257 output: "for(a;b;\nc)d",
258 options: ["last"],
259 errors: [{
260 messageId: "expectedSemiColon",
261 data: {
262 pos: "the end of the previous line"
263 }
264 }]
265 },
266 {
267 code: "foo()\n;",
268 output: "foo();\n",
269 options: ["last"],
270 errors: [{
271 messageId: "expectedSemiColon",
272 data: {
273 pos: "the end of the previous line"
274 }
275 }]
276 },
277
278 {
279 code: "foo;\nbar",
280 output: "foo\n;bar",
281 options: ["first"],
282 errors: [{
283 messageId: "expectedSemiColon",
284 data: {
285 pos: "the beginning of the next line"
286 }
287 }]
288 },
289 {
290 code: "if(a)foo;\nbar",
291 output: "if(a)foo\n;bar",
292 options: ["first"],
293 errors: [{
294 messageId: "expectedSemiColon",
295 data: {
296 pos: "the beginning of the next line"
297 }
298 }]
299 },
300 {
301 code: "var foo;\nbar",
302 output: "var foo\n;bar",
303 options: ["first"],
304 errors: [{
305 messageId: "expectedSemiColon",
306 data: {
307 pos: "the beginning of the next line"
308 }
309 }]
310 },
311 {
312 code: "foo\n;\nbar",
313 output: "foo\n;bar",
314 options: ["first"],
315 errors: [{
316 messageId: "expectedSemiColon",
317 data: {
318 pos: "the beginning of the next line"
319 }
320 }]
321 },
322 {
323 code: "for(a\n;b;c)d",
324 output: "for(a;\nb;c)d",
325 options: ["first"],
326 errors: [{
327 messageId: "expectedSemiColon",
328 data: {
329 pos: "the end of the previous line"
330 }
331 }]
332 },
333 {
334 code: "for(a;b\n;c)d",
335 output: "for(a;b;\nc)d",
336 options: ["first"],
337 errors: [{
338 messageId: "expectedSemiColon",
339 data: {
340 pos: "the end of the previous line"
341 }
342 }]
343 },
344
345 {
346 code: "foo\n;/**/bar",
347 output: null,
348 errors: [{
349 messageId: "expectedSemiColon",
350 data: {
351 pos: "the end of the previous line"
352 }
353 }]
354 },
355 {
356 code: "foo\n/**/;bar",
357 output: null,
358 errors: [{
359 messageId: "expectedSemiColon",
360 data: {
361 pos: "the end of the previous line"
362 }
363 }]
364 },
365
366 {
367 code: "foo;\n/**/bar",
368 output: null,
369 options: ["first"],
370 errors: [{
371 messageId: "expectedSemiColon",
372 data: {
373 pos: "the beginning of the next line"
374 }
375 }]
376 },
377 {
378 code: "foo/**/;\nbar",
379 output: null,
380 options: ["first"],
381 errors: [{
382 messageId: "expectedSemiColon",
383 data: {
384 pos: "the beginning of the next line"
385 }
386 }]
387 }
388 ]
389 });