]> git.proxmox.com Git - pve-eslint.git/blob - eslint/tests/lib/rules/no-empty.js
98651a41256d42186d1b90f86e21cefe2adaaf67
[pve-eslint.git] / eslint / tests / lib / rules / no-empty.js
1 /**
2 * @fileoverview Tests for no-empty rule.
3 * @author Nicholas C. Zakas
4 */
5
6 "use strict";
7
8 //------------------------------------------------------------------------------
9 // Requirements
10 //------------------------------------------------------------------------------
11
12 const rule = require("../../../lib/rules/no-empty"),
13 { RuleTester } = require("../../../lib/rule-tester");
14
15 //------------------------------------------------------------------------------
16 // Tests
17 //------------------------------------------------------------------------------
18
19 const ruleTester = new RuleTester();
20
21 ruleTester.run("no-empty", rule, {
22 valid: [
23 "if (foo) { bar() }",
24 "while (foo) { bar() }",
25 "for (;foo;) { bar() }",
26 "try { foo() } catch (ex) { foo() }",
27 "switch(foo) {case 'foo': break;}",
28 "(function() { }())",
29 { code: "var foo = () => {};", parserOptions: { ecmaVersion: 6 } },
30 "function foo() { }",
31 "if (foo) {/* empty */}",
32 "while (foo) {/* empty */}",
33 "for (;foo;) {/* empty */}",
34 "try { foo() } catch (ex) {/* empty */}",
35 "try { foo() } catch (ex) {// empty\n}",
36 "try { foo() } finally {// empty\n}",
37 "try { foo() } finally {// test\n}",
38 "try { foo() } finally {\n \n // hi i am off no use\n}",
39 "try { foo() } catch (ex) {/* test111 */}",
40 "if (foo) { bar() } else { // nothing in me \n}",
41 "if (foo) { bar() } else { /**/ \n}",
42 "if (foo) { bar() } else { // \n}",
43 { code: "try { foo(); } catch (ex) {}", options: [{ allowEmptyCatch: true }] },
44 { code: "try { foo(); } catch (ex) {} finally { bar(); }", options: [{ allowEmptyCatch: true }] }
45 ],
46 invalid: [
47 { code: "try {} catch (ex) {throw ex}", errors: [{ messageId: "unexpected", data: { type: "block" }, type: "BlockStatement" }] },
48 { code: "try { foo() } catch (ex) {}", errors: [{ messageId: "unexpected", data: { type: "block" }, type: "BlockStatement" }] },
49 { code: "try { foo() } catch (ex) {throw ex} finally {}", errors: [{ messageId: "unexpected", data: { type: "block" }, type: "BlockStatement" }] },
50 { code: "if (foo) {}", errors: [{ messageId: "unexpected", data: { type: "block" }, type: "BlockStatement" }] },
51 { code: "while (foo) {}", errors: [{ messageId: "unexpected", data: { type: "block" }, type: "BlockStatement" }] },
52 { code: "for (;foo;) {}", errors: [{ messageId: "unexpected", data: { type: "block" }, type: "BlockStatement" }] },
53 { code: "switch(foo) {}", errors: [{ messageId: "unexpected", data: { type: "switch" }, type: "SwitchStatement" }] },
54 {
55 code: "try {} catch (ex) {}",
56 options: [{ allowEmptyCatch: true }],
57 errors: [{ messageId: "unexpected", data: { type: "block" }, type: "BlockStatement" }]
58 },
59 {
60 code: "try { foo(); } catch (ex) {} finally {}",
61 options: [{ allowEmptyCatch: true }],
62 errors: [{ messageId: "unexpected", data: { type: "block" }, type: "BlockStatement" }]
63 },
64 {
65 code: "try {} catch (ex) {} finally {}",
66 options: [{ allowEmptyCatch: true }],
67 errors: [
68 { messageId: "unexpected", data: { type: "block" }, type: "BlockStatement" },
69 { messageId: "unexpected", data: { type: "block" }, type: "BlockStatement" }
70 ]
71 },
72 {
73 code: "try { foo(); } catch (ex) {} finally {}",
74 errors: [
75 { messageId: "unexpected", data: { type: "block" }, type: "BlockStatement" },
76 { messageId: "unexpected", data: { type: "block" }, type: "BlockStatement" }
77 ]
78 }
79 ]
80 });