]>
git.proxmox.com Git - pve-eslint.git/blob - eslint/tests/lib/rules/no-unsafe-finally.js
2 * @fileoverview Tests for no-unsafe-finally
3 * @author Onur Temizkan
8 //------------------------------------------------------------------------------
10 //------------------------------------------------------------------------------
12 const rule
= require("../../../lib/rules/no-unsafe-finally"),
13 { RuleTester
} = require("../../../lib/rule-tester");
15 //------------------------------------------------------------------------------
17 //------------------------------------------------------------------------------
19 const ruleTester
= new RuleTester();
21 ruleTester
.run("no-unsafe-finally", rule
, {
23 "var foo = function() {\n try { \n return 1; \n } catch(err) { \n return 2; \n } finally { \n console.log('hola!') \n } \n }",
24 "var foo = function() { try { return 1 } catch(err) { return 2 } finally { console.log('hola!') } }",
25 "var foo = function() { try { return 1 } catch(err) { return 2 } finally { function a(x) { return x } } }",
26 "var foo = function() { try { return 1 } catch(err) { return 2 } finally { var a = function(x) { if(!x) { throw new Error() } } } }",
27 "var foo = function() { try { return 1 } catch(err) { return 2 } finally { var a = function(x) { while(true) { if(x) { break } else { continue } } } } }",
28 "var foo = function() { try { return 1 } catch(err) { return 2 } finally { var a = function(x) { label: while(true) { if(x) { break label; } else { continue } } } } }",
29 "var foo = function() { try {} finally { while (true) break; } }",
30 "var foo = function() { try {} finally { while (true) continue; } }",
31 "var foo = function() { try {} finally { switch (true) { case true: break; } } }",
32 "var foo = function() { try {} finally { do { break; } while (true) } }",
34 code
: "var foo = function() { try { return 1; } catch(err) { return 2; } finally { var bar = () => { throw new Error(); }; } };",
35 parserOptions
: { ecmaVersion
: 6 }
38 code
: "var foo = function() { try { return 1; } catch(err) { return 2 } finally { (x) => x } }",
39 parserOptions
: { ecmaVersion
: 6 }
42 code
: "var foo = function() { try { return 1; } finally { class bar { constructor() {} static ehm() { return 'Hola!'; } } } };",
43 parserOptions
: { ecmaVersion
: 6 }
48 code
: "var foo = function() { \n try { \n return 1; \n } catch(err) { \n return 2; \n } finally { \n return 3; \n } \n }",
49 errors
: [{ messageId
: "unsafeUsage", data
: { nodeType
: "ReturnStatement" }, type
: "ReturnStatement", line
: 7, column
: 2 }]
52 code
: "var foo = function() { try { return 1 } catch(err) { return 2 } finally { if(true) { return 3 } else { return 2 } } }",
54 { messageId
: "unsafeUsage", data
: { nodeType
: "ReturnStatement" }, type
: "ReturnStatement", line
: 1, column
: 86 },
55 { messageId
: "unsafeUsage", data
: { nodeType
: "ReturnStatement" }, type
: "ReturnStatement", line
: 1, column
: 104 }
59 code
: "var foo = function() { try { return 1 } catch(err) { return 2 } finally { return 3 } }",
60 errors
: [{ messageId
: "unsafeUsage", data
: { nodeType
: "ReturnStatement" }, type
: "ReturnStatement", line
: 1, column
: 75 }]
63 code
: "var foo = function() { try { return 1 } catch(err) { return 2 } finally { return function(x) { return y } } }",
64 errors
: [{ messageId
: "unsafeUsage", data
: { nodeType
: "ReturnStatement" }, type
: "ReturnStatement", line
: 1, column
: 75 }]
67 code
: "var foo = function() { try { return 1 } catch(err) { return 2 } finally { return { x: function(c) { return c } } } }",
68 errors
: [{ messageId
: "unsafeUsage", data
: { nodeType
: "ReturnStatement" }, type
: "ReturnStatement", line
: 1, column
: 75 }]
71 code
: "var foo = function() { try { return 1 } catch(err) { return 2 } finally { throw new Error() } }",
72 errors
: [{ messageId
: "unsafeUsage", data
: { nodeType
: "ThrowStatement" }, type
: "ThrowStatement", line
: 1, column
: 75 }]
75 code
: "var foo = function() { try { foo(); } finally { try { bar(); } finally { return; } } };",
76 errors
: [{ messageId
: "unsafeUsage", data
: { nodeType
: "ReturnStatement" }, type
: "ReturnStatement", line
: 1, column
: 74 }]
79 code
: "var foo = function() { label: try { return 0; } finally { break label; } return 1; }",
80 errors
: [{ messageId
: "unsafeUsage", data
: { nodeType
: "BreakStatement" }, type
: "BreakStatement", line
: 1, column
: 59 }]
83 code
: "var foo = function() { \n a: try { \n return 1; \n } catch(err) { \n return 2; \n } finally { \n break a; \n } \n }",
84 errors
: [{ messageId
: "unsafeUsage", data
: { nodeType
: "BreakStatement" }, type
: "BreakStatement", line
: 7, column
: 2 }]
87 code
: "var foo = function() { while (true) try {} finally { break; } }",
88 errors
: [{ messageId
: "unsafeUsage", data
: { nodeType
: "BreakStatement" }, type
: "BreakStatement", line
: 1, column
: 54 }]
91 code
: "var foo = function() { while (true) try {} finally { continue; } }",
92 errors
: [{ messageId
: "unsafeUsage", data
: { nodeType
: "ContinueStatement" }, type
: "ContinueStatement", line
: 1, column
: 54 }]
95 code
: "var foo = function() { switch (true) { case true: try {} finally { break; } } }",
96 errors
: [{ messageId
: "unsafeUsage", data
: { nodeType
: "BreakStatement" }, type
: "BreakStatement", line
: 1, column
: 68 }]
99 code
: "var foo = function() { a: while (true) try {} finally { switch (true) { case true: break a; } } }",
100 errors
: [{ messageId
: "unsafeUsage", data
: { nodeType
: "BreakStatement" }, type
: "BreakStatement", line
: 1, column
: 84 }]
103 code
: "var foo = function() { a: while (true) try {} finally { switch (true) { case true: continue; } } }",
104 errors
: [{ messageId
: "unsafeUsage", data
: { nodeType
: "ContinueStatement" }, type
: "ContinueStatement", line
: 1, column
: 84 }]
107 code
: "var foo = function() { a: switch (true) { case true: try {} finally { switch (true) { case true: break a; } } } }",
108 errors
: [{ messageId
: "unsafeUsage", data
: { nodeType
: "BreakStatement" }, type
: "BreakStatement", line
: 1, column
: 98 }]