Skip to content

Commit

Permalink
Fixes #34. Handle unreachable return or throw.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan Murphy authored and Ryan Murphy committed Nov 4, 2016
1 parent a6d66a8 commit b2bf625
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
5 changes: 4 additions & 1 deletion rules/always-return.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@ module.exports = {
function markCurrentBranchAsGood () {
var funcInfo = peek(funcInfoStack)
var currentBranchID = peek(funcInfo.branchIDStack)
funcInfo.branchInfoMap[currentBranchID].good = true
if (funcInfo.branchInfoMap[currentBranchID]) {
funcInfo.branchInfoMap[currentBranchID].good = true
}
// else unreachable code
}

return {
Expand Down
1 change: 1 addition & 0 deletions test/always-return.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ ruleTester.run('always-return', rule, {
{ code: 'hey.then(x => { var f = function() { }; return f; })', parserOptions: parserOptions },
{ code: 'hey.then(x => { if (x) { return x; } else { return x; } })', parserOptions: parserOptions },
{ code: 'hey.then(x => { return x; var y = "unreachable"; })', parserOptions: parserOptions },
{ code: 'hey.then(x => { return x; return "unreachable"; })', parserOptions: parserOptions },
{ code: 'hey.then(x => { return; }, err=>{ log(err); })', parserOptions: parserOptions },
{ code: 'hey.then(x => { return x && x(); }, err=>{ log(err); })', parserOptions: parserOptions },
{ code: 'hey.then(x => { return x.y || x(); }, err=>{ log(err); })', parserOptions: parserOptions }
Expand Down

0 comments on commit b2bf625

Please sign in to comment.