]>
git.proxmox.com Git - pve-eslint.git/blob - eslint/tests/lib/rules/no-empty.js
98651a41256d42186d1b90f86e21cefe2adaaf67
2 * @fileoverview Tests for no-empty rule.
3 * @author Nicholas C. Zakas
8 //------------------------------------------------------------------------------
10 //------------------------------------------------------------------------------
12 const rule
= require("../../../lib/rules/no-empty"),
13 { RuleTester
} = require("../../../lib/rule-tester");
15 //------------------------------------------------------------------------------
17 //------------------------------------------------------------------------------
19 const ruleTester
= new RuleTester();
21 ruleTester
.run("no-empty", rule
, {
24 "while (foo) { bar() }",
25 "for (;foo;) { bar() }",
26 "try { foo() } catch (ex) { foo() }",
27 "switch(foo) {case 'foo': break;}",
29 { code
: "var foo = () => {};", parserOptions
: { ecmaVersion
: 6 } },
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 }] }
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" }] },
55 code
: "try {} catch (ex) {}",
56 options
: [{ allowEmptyCatch
: true }],
57 errors
: [{ messageId
: "unexpected", data
: { type
: "block" }, type
: "BlockStatement" }]
60 code
: "try { foo(); } catch (ex) {} finally {}",
61 options
: [{ allowEmptyCatch
: true }],
62 errors
: [{ messageId
: "unexpected", data
: { type
: "block" }, type
: "BlockStatement" }]
65 code
: "try {} catch (ex) {} finally {}",
66 options
: [{ allowEmptyCatch
: true }],
68 { messageId
: "unexpected", data
: { type
: "block" }, type
: "BlockStatement" },
69 { messageId
: "unexpected", data
: { type
: "block" }, type
: "BlockStatement" }
73 code
: "try { foo(); } catch (ex) {} finally {}",
75 { messageId
: "unexpected", data
: { type
: "block" }, type
: "BlockStatement" },
76 { messageId
: "unexpected", data
: { type
: "block" }, type
: "BlockStatement" }