Skip to content

Commit

Permalink
fix hey.then(x => { return; }, err=>{ log(err); })
Browse files Browse the repository at this point in the history
  • Loading branch information
ahuff44 committed Oct 7, 2016
1 parent 5523a81 commit 271e239
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
13 changes: 11 additions & 2 deletions rules/always-return.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,27 @@ function isFunctionWithBlockStatement (node) {
return false
}

function isThenExpression (node) {
function isThenCallExpression (node) {
return (
node.type === 'CallExpression' &&
node.callee.type === 'MemberExpression' &&
node.callee.property.name === 'then'
)
}

function isFirstArgument (node) {
return (
node.parent &&
node.parent.arguments &&
node.parent.arguments[0] === node
)
}

function isInlineThenFunctionExpression (node) {
return (
isFunctionWithBlockStatement(node) &&
isThenExpression(node.parent)
isThenCallExpression(node.parent) &&
isFirstArgument(node)
)
}

Expand Down
3 changes: 2 additions & 1 deletion test/always-return.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ ruleTester.run('always-return', rule, {
{ code: 'hey.then(x => { if (x) { return x; } throw new Error("no x"); })', parserOptions: parserOptions },
{ 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; var y = "unreachable"; })', parserOptions: parserOptions },
{ code: 'hey.then(x => { return; }, err=>{ log(err); })', parserOptions: parserOptions }
],

invalid: [
Expand Down

0 comments on commit 271e239

Please sign in to comment.