]> git.proxmox.com Git - pve-eslint.git/blob - eslint/tests/lib/rules/no-extra-semi.js
913290aaf85718b0272326bc01539b9f0abd3e38
[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
42 // modules
43 { code: "export const x = 42;", parserOptions: { ecmaVersion: 6, sourceType: "module" } },
44 { code: "export default 42;", parserOptions: { ecmaVersion: 6, sourceType: "module" } }
45 ],
46 invalid: [
47 {
48 code: "var x = 5;;",
49 output: "var x = 5;",
50 errors: [{ messageId: "unexpected", type: "EmptyStatement" }]
51 },
52 {
53 code: "function foo(){};",
54 output: "function foo(){}",
55 errors: [{ messageId: "unexpected", type: "EmptyStatement" }]
56 },
57 {
58 code: "for(;;);;",
59 output: "for(;;);",
60 errors: [{ messageId: "unexpected", type: "EmptyStatement" }]
61 },
62 {
63 code: "while(0);;",
64 output: "while(0);",
65 errors: [{ messageId: "unexpected", type: "EmptyStatement" }]
66 },
67 {
68 code: "do;while(0);;",
69 output: "do;while(0);",
70 errors: [{ messageId: "unexpected", type: "EmptyStatement" }]
71 },
72 {
73 code: "for(a in b);;",
74 output: "for(a in b);",
75 errors: [{ messageId: "unexpected", type: "EmptyStatement" }]
76 },
77 {
78 code: "for(a of b);;",
79 output: "for(a of b);",
80 parserOptions: { ecmaVersion: 6 },
81 errors: [{ messageId: "unexpected", type: "EmptyStatement" }]
82 },
83 {
84 code: "if(true);;",
85 output: "if(true);",
86 errors: [{ messageId: "unexpected", type: "EmptyStatement" }]
87 },
88 {
89 code: "if(true){} else;;",
90 output: "if(true){} else;",
91 errors: [{ messageId: "unexpected", type: "EmptyStatement" }]
92 },
93 {
94 code: "if(true){;} else {;}",
95 output: "if(true){} else {}",
96 errors: [{ messageId: "unexpected", type: "EmptyStatement" }, { messageId: "unexpected", type: "EmptyStatement" }]
97 },
98 {
99 code: "foo:;;",
100 output: "foo:;",
101 errors: [{ messageId: "unexpected", type: "EmptyStatement" }]
102 },
103 {
104 code: "with(foo);;",
105 output: "with(foo);",
106 errors: [{ messageId: "unexpected", type: "EmptyStatement" }]
107 },
108 {
109 code: "with(foo){;}",
110 output: "with(foo){}",
111 errors: [{ messageId: "unexpected", type: "EmptyStatement" }]
112 },
113
114 // Class body.
115 {
116 code: "class A { ; }",
117 output: "class A { }",
118 parserOptions: { ecmaVersion: 6 },
119 errors: [{ messageId: "unexpected", type: "Punctuator", column: 11 }]
120 },
121 {
122 code: "class A { /*a*/; }",
123 output: "class A { /*a*/ }",
124 parserOptions: { ecmaVersion: 6 },
125 errors: [{ messageId: "unexpected", type: "Punctuator", column: 16 }]
126 },
127 {
128 code: "class A { ; a() {} }",
129 output: "class A { a() {} }",
130 parserOptions: { ecmaVersion: 6 },
131 errors: [{ messageId: "unexpected", type: "Punctuator", column: 11 }]
132 },
133 {
134 code: "class A { a() {}; }",
135 output: "class A { a() {} }",
136 parserOptions: { ecmaVersion: 6 },
137 errors: [{ messageId: "unexpected", type: "Punctuator", column: 17 }]
138 },
139 {
140 code: "class A { a() {}; b() {} }",
141 output: "class A { a() {} b() {} }",
142 parserOptions: { ecmaVersion: 6 },
143 errors: [{ messageId: "unexpected", type: "Punctuator", column: 17 }]
144 },
145 {
146 code: "class A {; a() {}; b() {}; }",
147 output: "class A { a() {} b() {} }",
148 parserOptions: { ecmaVersion: 6 },
149 errors: [
150 { messageId: "unexpected", type: "Punctuator", column: 10 },
151 { messageId: "unexpected", type: "Punctuator", column: 18 },
152 { messageId: "unexpected", type: "Punctuator", column: 26 }
153 ]
154 },
155 {
156 code: "class A { a() {}; get b() {} }",
157 output: "class A { a() {} get b() {} }",
158 parserOptions: { ecmaVersion: 6 },
159 errors: [{ messageId: "unexpected", type: "Punctuator", column: 17 }]
160 }
161 ]
162 });