]>
git.proxmox.com Git - pve-eslint.git/blob - eslint/tests/lib/rules/no-lone-blocks.js
2 * @fileoverview Tests for no-lone-blocks rule.
3 * @author Brandon Mills
8 //------------------------------------------------------------------------------
10 //------------------------------------------------------------------------------
12 const rule
= require("../../../lib/rules/no-lone-blocks"),
13 { RuleTester
} = require("../../../lib/rule-tester");
15 //------------------------------------------------------------------------------
17 //------------------------------------------------------------------------------
19 const ruleTester
= new RuleTester();
21 ruleTester
.run("no-lone-blocks", rule
, {
23 "if (foo) { if (bar) { baz(); } }",
24 "do { bar(); } while (foo)",
25 "function foo() { while (bar) { baz() } }",
27 // Block-level bindings
28 { code
: "{ let x = 1; }", parserOptions
: { ecmaVersion
: 6 } },
29 { code
: "{ const x = 1; }", parserOptions
: { ecmaVersion
: 6 } },
30 { code
: "'use strict'; { function bar() {} }", parserOptions
: { ecmaVersion
: 6 } },
31 { code
: "{ function bar() {} }", parserOptions
: { ecmaVersion
: 6, ecmaFeatures
: { impliedStrict
: true } } },
32 { code
: "{ class Bar {} }", parserOptions
: { ecmaVersion
: 6 } },
34 { code
: "{ {let y = 1;} let x = 1; }", parserOptions
: { ecmaVersion
: 6 } },
60 { code
: "function foo() { { const x = 4 } const x = 3 }", parserOptions
: { ecmaVersion
: 6 } },
62 { code
: "class C { static {} }", parserOptions
: { ecmaVersion
: 2022 } },
63 { code
: "class C { static { foo; } }", parserOptions
: { ecmaVersion
: 2022 } },
64 { code
: "class C { static { if (foo) { block; } } }", parserOptions
: { ecmaVersion
: 2022 } },
65 { code
: "class C { static { lbl: { block; } } }", parserOptions
: { ecmaVersion
: 2022 } },
66 { code
: "class C { static { { let block; } something; } }", parserOptions
: { ecmaVersion
: 2022 } },
67 { code
: "class C { static { something; { const block = 1; } } }", parserOptions
: { ecmaVersion
: 2022 } },
68 { code
: "class C { static { { function block(){} } something; } }", parserOptions
: { ecmaVersion
: 2022 } },
69 { code
: "class C { static { something; { class block {} } } }", parserOptions
: { ecmaVersion
: 2022 } }
75 messageId
: "redundantBlock",
76 type
: "BlockStatement"
82 messageId
: "redundantBlock",
83 type
: "BlockStatement"
87 code
: "foo(); {} bar();",
89 messageId
: "redundantBlock",
90 type
: "BlockStatement"
94 code
: "if (foo) { bar(); {} baz(); }",
96 messageId
: "redundantNestedBlock",
97 type
: "BlockStatement"
104 messageId
: "redundantBlock",
105 type
: "BlockStatement",
109 messageId
: "redundantNestedBlock",
110 type
: "BlockStatement",
116 code
: "function foo() { bar(); {} baz(); }",
118 messageId
: "redundantNestedBlock",
119 type
: "BlockStatement"
123 code
: "while (foo) { {} }",
125 messageId
: "redundantNestedBlock",
126 type
: "BlockStatement"
130 // Non-block-level bindings, even in ES6
132 code
: "{ function bar() {} }",
133 parserOptions
: { ecmaVersion
: 6 },
135 messageId
: "redundantBlock",
136 type
: "BlockStatement"
140 code
: "{var x = 1;}",
141 parserOptions
: { ecmaVersion
: 6 },
143 messageId
: "redundantBlock",
144 type
: "BlockStatement"
149 code
: "{ \n{var x = 1;}\n let y = 2; } {let z = 1;}",
150 parserOptions
: { ecmaVersion
: 6 },
152 messageId
: "redundantNestedBlock",
153 type
: "BlockStatement",
158 code
: "{ \n{let x = 1;}\n var y = 2; } {let z = 1;}",
159 parserOptions
: { ecmaVersion
: 6 },
161 messageId
: "redundantBlock",
162 type
: "BlockStatement",
167 code
: "{ \n{var x = 1;}\n var y = 2; }\n {var z = 1;}",
168 parserOptions
: { ecmaVersion
: 6 },
171 messageId
: "redundantBlock",
172 type
: "BlockStatement",
176 messageId
: "redundantNestedBlock",
177 type
: "BlockStatement",
181 messageId
: "redundantBlock",
182 type
: "BlockStatement",
198 messageId
: "redundantBlock",
199 type
: "BlockStatement",
214 messageId
: "redundantBlock",
215 type
: "BlockStatement",
227 parserOptions
: { ecmaVersion
: 6 },
229 messageId
: "redundantNestedBlock",
230 type
: "BlockStatement",
243 messageId
: "redundantNestedBlock",
244 type
: "BlockStatement",
260 parserOptions
: { ecmaVersion
: 2022 },
262 messageId
: "redundantNestedBlock",
263 type
: "BlockStatement",
280 parserOptions
: { ecmaVersion
: 2022 },
282 messageId
: "redundantNestedBlock",
283 type
: "BlockStatement",
297 parserOptions
: { ecmaVersion
: 2022 },
299 messageId
: "redundantNestedBlock",
300 type
: "BlockStatement",
314 parserOptions
: { ecmaVersion
: 2022 },
316 messageId
: "redundantNestedBlock",
317 type
: "BlockStatement",
331 parserOptions
: { ecmaVersion
: 2022 },
333 messageId
: "redundantNestedBlock",
334 type
: "BlockStatement",
348 parserOptions
: { ecmaVersion
: 2022 },
350 messageId
: "redundantNestedBlock",
351 type
: "BlockStatement",
365 parserOptions
: { ecmaVersion
: 2022 },
367 messageId
: "redundantNestedBlock",
368 type
: "BlockStatement",
383 parserOptions
: { ecmaVersion
: 2022 },
385 messageId
: "redundantNestedBlock",
386 type
: "BlockStatement",
401 parserOptions
: { ecmaVersion
: 2022 },
403 messageId
: "redundantNestedBlock",
404 type
: "BlockStatement",
419 parserOptions
: { ecmaVersion
: 2022 },
421 messageId
: "redundantNestedBlock",
422 type
: "BlockStatement",
437 parserOptions
: { ecmaVersion
: 2022 },
439 messageId
: "redundantNestedBlock",
440 type
: "BlockStatement",