Skip to content

Commit

Permalink
Update: Add test and move existing tests for eslint#9228
Browse files Browse the repository at this point in the history
  • Loading branch information
graingert committed Sep 23, 2017
1 parent b9748d9 commit 6e581d1
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions tests/lib/rules/no-else-return.js
Expand Up @@ -96,6 +96,18 @@ ruleTester.run("no-else-return", rule, {
output: "function foo9() {if (x) { return true; } else if (y) { return true; } notAReturn(); }",
errors: [{ message: "Unnecessary 'else' after 'return'.", type: "BlockStatement" }]
},
{
code: "function foo9a() {if (x) { return true; } else if (y) { return true; } else { notAReturn(); } }",
output: "function foo9a() {if (x) { return true; } if (y) { return true; } else { notAReturn(); } }",
options: [{ allowElseIf: true }],
errors: [{ message: "Unnecessary 'else' after 'return'.", type: "IfStatement" }]
},
{
code: "function foo9b() {if (x) { return true; } if (y) { return true; } else { notAReturn(); } }",
output: "function foo9b() {if (x) { return true; } if (y) { return true; } notAReturn(); }",
options: [{ allowElseIf: true }],
errors: [{ message: "Unnecessary 'else' after 'return'.", type: "BlockStatement" }]
},
{
code: "function foo10() { if (foo) return bar; else (foo).bar(); }",
output: "function foo10() { if (foo) return bar; (foo).bar(); }",
Expand Down Expand Up @@ -140,6 +152,24 @@ ruleTester.run("no-else-return", rule, {
code: "function foo18() { if (foo) return function() {} \nelse [1, 2, 3].map(bar) }",
output: null,
errors: [{ message: "Unnecessary 'else' after 'return'.", type: "ExpressionStatement" }]
},
{
code: "function foo19() { if (true) { return x; } else if (false) { return y; } }",
output: "function foo19() { if (true) { return x; } if (false) { return y; } }",
options: [{ allowElseIf: true }],
errors: [{ message: "Unnecessary 'else' after 'return'.", type: "IfStatement" }]
},
{
code: "function foo20() {if (x) { return true; } else if (y) { notAReturn() } else { notAReturn(); } }",
output: "function foo20() {if (x) { return true; } if (y) { notAReturn() } else { notAReturn(); } }",
options: [{ allowElseIf: true }],
errors: [{ message: "Unnecessary 'else' after 'return'.", type: "IfStatement" }]
},
{
code: "function foo21() { var x = true; if (x) { return x; } else if (x === false) { return false; } }",
output: "function foo21() { var x = true; if (x) { return x; } if (x === false) { return false; } }",
options: [{ allowElseIf: true }],
errors: [{ message: "Unnecessary 'else' after 'return'.", type: "IfStatement" }]
}
]
});

0 comments on commit 6e581d1

Please sign in to comment.