Skip to content

Commit

Permalink
scope to .then function call
Browse files Browse the repository at this point in the history
  • Loading branch information
geoffdutton committed Jan 27, 2017
1 parent b84874f commit 360fb8b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
5 changes: 5 additions & 0 deletions rules/always-return.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ function isInlineThenFunctionExpression (node) {

function hasParentReturnStatement (node) {
if (node && node.parent && node.parent.type) {
// if the parent is a then, and we haven't returned anything, fail
if (isThenCallExpression(node.parent)) {
return false
}

if (node.parent.type === 'ReturnStatement') {
return true
}
Expand Down
16 changes: 9 additions & 7 deletions test/always-return.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,16 @@ ruleTester.run('always-return', rule, {
errors: [ { message: message } ]
},
{
code: `hey.then(x => {
anotherFunc({
nested: {
one: x === 1 ? 1 : 0,
two: x === 2 ? 1 : 0
}
code: `(function() {
return hey.then(x => {
anotherFunc({
nested: {
one: x === 1 ? 1 : 0,
two: x === 2 ? 1 : 0
}
})
})
})`,
})()`,
parserOptions: parserOptions,
errors: [ { message: message } ]
}
Expand Down

0 comments on commit 360fb8b

Please sign in to comment.