]>
git.proxmox.com Git - pve-eslint.git/blob - eslint/tests/lib/rules/block-spacing.js
2 * @fileoverview Tests for block-spacing rule.
3 * @author Toru Nagashima
8 //------------------------------------------------------------------------------
10 //------------------------------------------------------------------------------
12 const rule
= require("../../../lib/rules/block-spacing");
13 const { RuleTester
} = require("../../../lib/rule-tester");
15 //------------------------------------------------------------------------------
17 //------------------------------------------------------------------------------
19 const ruleTester
= new RuleTester();
21 ruleTester
.run("block-spacing", rule
, {
25 { code
: "{ foo(); }", options
: ["always"] },
31 "if (a) {} else { foo(); }",
33 "switch (a) { case 0: foo(); }",
34 "while (a) { foo(); }",
35 "do { foo(); } while (a);",
36 "for (;;) { foo(); }",
37 "for (var a in b) { foo(); }",
38 { code
: "for (var a of b) { foo(); }", parserOptions
: { ecmaVersion
: 6 } },
39 "try { foo(); } catch (e) { foo(); }",
40 "function foo() { bar(); }",
41 "(function() { bar(); });",
42 { code
: "(() => { bar(); });", parserOptions
: { ecmaVersion
: 6 } },
43 "if (a) { /* comment */ foo(); /* comment */ }",
44 "if (a) { //comment\n foo(); }",
47 { code
: "{foo();}", options
: ["never"] },
48 { code
: "{foo();\n}", options
: ["never"] },
49 { code
: "{\nfoo();}", options
: ["never"] },
50 { code
: "{\r\nfoo();\r\n}", options
: ["never"] },
51 { code
: "if (a) {foo();}", options
: ["never"] },
52 { code
: "if (a) {} else {foo();}", options
: ["never"] },
53 { code
: "switch (a) {}", options
: ["never"] },
54 { code
: "switch (a) {case 0: foo();}", options
: ["never"] },
55 { code
: "while (a) {foo();}", options
: ["never"] },
56 { code
: "do {foo();} while (a);", options
: ["never"] },
57 { code
: "for (;;) {foo();}", options
: ["never"] },
58 { code
: "for (var a in b) {foo();}", options
: ["never"] },
59 { code
: "for (var a of b) {foo();}", options
: ["never"], parserOptions
: { ecmaVersion
: 6 } },
60 { code
: "try {foo();} catch (e) {foo();}", options
: ["never"] },
61 { code
: "function foo() {bar();}", options
: ["never"] },
62 { code
: "(function() {bar();});", options
: ["never"] },
63 { code
: "(() => {bar();});", options
: ["never"], parserOptions
: { ecmaVersion
: 6 } },
64 { code
: "if (a) {/* comment */ foo(); /* comment */}", options
: ["never"] },
65 { code
: "if (a) { //comment\n foo();}", options
: ["never"] }
76 { type
: "BlockStatement", line
: 1, column
: 1, messageId
: "missing", data
: { location
: "after", token
: "{" } },
77 { type
: "BlockStatement", line
: 1, column
: 8, messageId
: "missing", data
: { location
: "before", token
: "}" } }
84 { type
: "BlockStatement", line
: 1, column
: 1, messageId
: "missing", data
: { location
: "after", token
: "{" } },
85 { type
: "BlockStatement", line
: 1, column
: 8, messageId
: "missing", data
: { location
: "before", token
: "}" } }
92 { type
: "BlockStatement", line
: 1, column
: 9, messageId
: "missing", data
: { location
: "before", token
: "}" } }
99 { type
: "BlockStatement", line
: 1, column
: 1, messageId
: "missing", data
: { location
: "after", token
: "{" } }
104 output
: "{\nfoo(); }",
106 { type
: "BlockStatement", line
: 2, column
: 7, messageId
: "missing", data
: { location
: "before", token
: "}" } }
111 output
: "{ foo();\n}",
113 { type
: "BlockStatement", line
: 1, column
: 1, messageId
: "missing", data
: { location
: "after", token
: "{" } }
117 code
: "if (a) {foo();}",
118 output
: "if (a) { foo(); }",
120 { type
: "BlockStatement", line
: 1, column
: 8, messageId
: "missing", data
: { location
: "after", token
: "{" } },
121 { type
: "BlockStatement", line
: 1, column
: 15, messageId
: "missing", data
: { location
: "before", token
: "}" } }
125 code
: "if (a) {} else {foo();}",
126 output
: "if (a) {} else { foo(); }",
128 { type
: "BlockStatement", line
: 1, column
: 16, messageId
: "missing", data
: { location
: "after", token
: "{" } },
129 { type
: "BlockStatement", line
: 1, column
: 23, messageId
: "missing", data
: { location
: "before", token
: "}" } }
133 code
: "switch (a) {case 0: foo();}",
134 output
: "switch (a) { case 0: foo(); }",
136 { type
: "SwitchStatement", line
: 1, column
: 12, messageId
: "missing", data
: { location
: "after", token
: "{" } },
137 { type
: "SwitchStatement", line
: 1, column
: 27, messageId
: "missing", data
: { location
: "before", token
: "}" } }
141 code
: "while (a) {foo();}",
142 output
: "while (a) { foo(); }",
144 { type
: "BlockStatement", line
: 1, column
: 11, messageId
: "missing", data
: { location
: "after", token
: "{" } },
145 { type
: "BlockStatement", line
: 1, column
: 18, messageId
: "missing", data
: { location
: "before", token
: "}" } }
149 code
: "do {foo();} while (a);",
150 output
: "do { foo(); } while (a);",
152 { type
: "BlockStatement", line
: 1, column
: 4, messageId
: "missing", data
: { location
: "after", token
: "{" } },
153 { type
: "BlockStatement", line
: 1, column
: 11, messageId
: "missing", data
: { location
: "before", token
: "}" } }
157 code
: "for (;;) {foo();}",
158 output
: "for (;;) { foo(); }",
160 { type
: "BlockStatement", line
: 1, column
: 10, messageId
: "missing", data
: { location
: "after", token
: "{" } },
161 { type
: "BlockStatement", line
: 1, column
: 17, messageId
: "missing", data
: { location
: "before", token
: "}" } }
165 code
: "for (var a in b) {foo();}",
166 output
: "for (var a in b) { foo(); }",
168 { type
: "BlockStatement", line
: 1, column
: 18, messageId
: "missing", data
: { location
: "after", token
: "{" } },
169 { type
: "BlockStatement", line
: 1, column
: 25, messageId
: "missing", data
: { location
: "before", token
: "}" } }
173 code
: "for (var a of b) {foo();}",
174 output
: "for (var a of b) { foo(); }",
175 parserOptions
: { ecmaVersion
: 6 },
177 { type
: "BlockStatement", line
: 1, column
: 18, messageId
: "missing", data
: { location
: "after", token
: "{" } },
178 { type
: "BlockStatement", line
: 1, column
: 25, messageId
: "missing", data
: { location
: "before", token
: "}" } }
182 code
: "try {foo();} catch (e) {foo();} finally {foo();}",
183 output
: "try { foo(); } catch (e) { foo(); } finally { foo(); }",
185 { type
: "BlockStatement", line
: 1, column
: 5, messageId
: "missing", data
: { location
: "after", token
: "{" } },
186 { type
: "BlockStatement", line
: 1, column
: 12, messageId
: "missing", data
: { location
: "before", token
: "}" } },
187 { type
: "BlockStatement", line
: 1, column
: 24, messageId
: "missing", data
: { location
: "after", token
: "{" } },
188 { type
: "BlockStatement", line
: 1, column
: 31, messageId
: "missing", data
: { location
: "before", token
: "}" } },
189 { type
: "BlockStatement", line
: 1, column
: 41, messageId
: "missing", data
: { location
: "after", token
: "{" } },
190 { type
: "BlockStatement", line
: 1, column
: 48, messageId
: "missing", data
: { location
: "before", token
: "}" } }
194 code
: "function foo() {bar();}",
195 output
: "function foo() { bar(); }",
197 { type
: "BlockStatement", line
: 1, column
: 16, messageId
: "missing", data
: { location
: "after", token
: "{" } },
198 { type
: "BlockStatement", line
: 1, column
: 23, messageId
: "missing", data
: { location
: "before", token
: "}" } }
202 code
: "(function() {bar();});",
203 output
: "(function() { bar(); });",
205 { type
: "BlockStatement", line
: 1, column
: 13, messageId
: "missing", data
: { location
: "after", token
: "{" } },
206 { type
: "BlockStatement", line
: 1, column
: 20, messageId
: "missing", data
: { location
: "before", token
: "}" } }
210 code
: "(() => {bar();});",
211 output
: "(() => { bar(); });",
212 parserOptions
: { ecmaVersion
: 6 },
214 { type
: "BlockStatement", line
: 1, column
: 8, messageId
: "missing", data
: { location
: "after", token
: "{" } },
215 { type
: "BlockStatement", line
: 1, column
: 15, messageId
: "missing", data
: { location
: "before", token
: "}" } }
219 code
: "if (a) {/* comment */ foo(); /* comment */}",
220 output
: "if (a) { /* comment */ foo(); /* comment */ }",
221 parserOptions
: { ecmaVersion
: 6 },
223 { type
: "BlockStatement", line
: 1, column
: 8, messageId
: "missing", data
: { location
: "after", token
: "{" } },
224 { type
: "BlockStatement", line
: 1, column
: 43, messageId
: "missing", data
: { location
: "before", token
: "}" } }
228 code
: "if (a) {//comment\n foo(); }",
229 output
: "if (a) { //comment\n foo(); }",
230 parserOptions
: { ecmaVersion
: 6 },
232 { type
: "BlockStatement", line
: 1, column
: 8, messageId
: "missing", data
: { location
: "after", token
: "{" } }
236 //----------------------------------------------------------------------
243 { type
: "BlockStatement", line
: 1, column
: 1, messageId
: "extra", data
: { location
: "after", token
: "{" } },
244 { type
: "BlockStatement", line
: 1, column
: 10, messageId
: "extra", data
: { location
: "before", token
: "}" } }
252 { type
: "BlockStatement", line
: 1, column
: 1, messageId
: "extra", data
: { location
: "after", token
: "{" } }
260 { type
: "BlockStatement", line
: 1, column
: 9, messageId
: "extra", data
: { location
: "before", token
: "}" } }
265 output
: "{\nfoo();}",
268 { type
: "BlockStatement", line
: 2, column
: 8, messageId
: "extra", data
: { location
: "before", token
: "}" } }
273 output
: "{foo();\n}",
276 { type
: "BlockStatement", line
: 1, column
: 1, messageId
: "extra", data
: { location
: "after", token
: "{" } }
280 code
: "if (a) { foo(); }",
281 output
: "if (a) {foo();}",
284 { type
: "BlockStatement", line
: 1, column
: 8, messageId
: "extra", data
: { location
: "after", token
: "{" } },
285 { type
: "BlockStatement", line
: 1, column
: 17, messageId
: "extra", data
: { location
: "before", token
: "}" } }
289 code
: "if (a) {} else { foo(); }",
290 output
: "if (a) {} else {foo();}",
293 { type
: "BlockStatement", line
: 1, column
: 16, messageId
: "extra", data
: { location
: "after", token
: "{" } },
294 { type
: "BlockStatement", line
: 1, column
: 25, messageId
: "extra", data
: { location
: "before", token
: "}" } }
298 code
: "switch (a) { case 0: foo(); }",
299 output
: "switch (a) {case 0: foo();}",
302 { type
: "SwitchStatement", line
: 1, column
: 12, messageId
: "extra", data
: { location
: "after", token
: "{" } },
303 { type
: "SwitchStatement", line
: 1, column
: 29, messageId
: "extra", data
: { location
: "before", token
: "}" } }
307 code
: "while (a) { foo(); }",
308 output
: "while (a) {foo();}",
311 { type
: "BlockStatement", line
: 1, column
: 11, messageId
: "extra", data
: { location
: "after", token
: "{" } },
312 { type
: "BlockStatement", line
: 1, column
: 20, messageId
: "extra", data
: { location
: "before", token
: "}" } }
316 code
: "do { foo(); } while (a);",
317 output
: "do {foo();} while (a);",
320 { type
: "BlockStatement", line
: 1, column
: 4, messageId
: "extra", data
: { location
: "after", token
: "{" } },
321 { type
: "BlockStatement", line
: 1, column
: 13, messageId
: "extra", data
: { location
: "before", token
: "}" } }
325 code
: "for (;;) { foo(); }",
326 output
: "for (;;) {foo();}",
329 { type
: "BlockStatement", line
: 1, column
: 10, messageId
: "extra", data
: { location
: "after", token
: "{" } },
330 { type
: "BlockStatement", line
: 1, column
: 19, messageId
: "extra", data
: { location
: "before", token
: "}" } }
334 code
: "for (var a in b) { foo(); }",
335 output
: "for (var a in b) {foo();}",
338 { type
: "BlockStatement", line
: 1, column
: 18, messageId
: "extra", data
: { location
: "after", token
: "{" } },
339 { type
: "BlockStatement", line
: 1, column
: 27, messageId
: "extra", data
: { location
: "before", token
: "}" } }
343 code
: "for (var a of b) { foo(); }",
344 output
: "for (var a of b) {foo();}",
346 parserOptions
: { ecmaVersion
: 6 },
348 { type
: "BlockStatement", line
: 1, column
: 18, messageId
: "extra", data
: { location
: "after", token
: "{" } },
349 { type
: "BlockStatement", line
: 1, column
: 27, messageId
: "extra", data
: { location
: "before", token
: "}" } }
353 code
: "try { foo(); } catch (e) { foo(); } finally { foo(); }",
354 output
: "try {foo();} catch (e) {foo();} finally {foo();}",
357 { type
: "BlockStatement", line
: 1, column
: 5, messageId
: "extra", data
: { location
: "after", token
: "{" } },
358 { type
: "BlockStatement", line
: 1, column
: 14, messageId
: "extra", data
: { location
: "before", token
: "}" } },
359 { type
: "BlockStatement", line
: 1, column
: 26, messageId
: "extra", data
: { location
: "after", token
: "{" } },
360 { type
: "BlockStatement", line
: 1, column
: 35, messageId
: "extra", data
: { location
: "before", token
: "}" } },
361 { type
: "BlockStatement", line
: 1, column
: 45, messageId
: "extra", data
: { location
: "after", token
: "{" } },
362 { type
: "BlockStatement", line
: 1, column
: 54, messageId
: "extra", data
: { location
: "before", token
: "}" } }
366 code
: "function foo() { bar(); }",
367 output
: "function foo() {bar();}",
370 { type
: "BlockStatement", line
: 1, column
: 16, messageId
: "extra", data
: { location
: "after", token
: "{" } },
371 { type
: "BlockStatement", line
: 1, column
: 25, messageId
: "extra", data
: { location
: "before", token
: "}" } }
375 code
: "(function() { bar(); });",
376 output
: "(function() {bar();});",
379 { type
: "BlockStatement", line
: 1, column
: 13, messageId
: "extra", data
: { location
: "after", token
: "{" } },
380 { type
: "BlockStatement", line
: 1, column
: 22, messageId
: "extra", data
: { location
: "before", token
: "}" } }
384 code
: "(() => { bar(); });",
385 output
: "(() => {bar();});",
387 parserOptions
: { ecmaVersion
: 6 },
389 { type
: "BlockStatement", line
: 1, column
: 8, messageId
: "extra", data
: { location
: "after", token
: "{" } },
390 { type
: "BlockStatement", line
: 1, column
: 17, messageId
: "extra", data
: { location
: "before", token
: "}" } }
394 code
: "if (a) { /* comment */ foo(); /* comment */ }",
395 output
: "if (a) {/* comment */ foo(); /* comment */}",
398 { type
: "BlockStatement", line
: 1, column
: 8, messageId
: "extra", data
: { location
: "after", token
: "{" } },
399 { type
: "BlockStatement", line
: 1, column
: 45, messageId
: "extra", data
: { location
: "before", token
: "}" } }