-
-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bumps deps; use ESLint 3 rule format
- Loading branch information
1 parent
d6bd2a0
commit 083dc3e
Showing
6 changed files
with
150 additions
and
134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,63 @@ | ||
module.exports = function (context) { | ||
var options = context.options[0] || {} | ||
var allowThen = options.allowThen | ||
var terminationMethod = options.terminationMethod || 'catch' | ||
var STATIC_METHODS = [ | ||
'all', | ||
'race', | ||
'reject', | ||
'resolve' | ||
] | ||
function isPromise (expression) { | ||
return ( // hello.then() | ||
expression.type === 'CallExpression' && | ||
expression.callee.type === 'MemberExpression' && | ||
expression.callee.property.name === 'then' | ||
) || ( // hello.catch() | ||
expression.type === 'CallExpression' && | ||
expression.callee.type === 'MemberExpression' && | ||
expression.callee.property.name === 'catch' | ||
) || ( // somePromise.ANYTHING() | ||
expression.type === 'CallExpression' && | ||
expression.callee.type === 'MemberExpression' && | ||
isPromise(expression.callee.object) | ||
) || ( // Promise.STATIC_METHOD() | ||
expression.type === 'CallExpression' && | ||
expression.callee.type === 'MemberExpression' && | ||
expression.callee.object.type === 'Identifier' && | ||
expression.callee.object.name === 'Promise' && | ||
STATIC_METHODS.indexOf(expression.callee.property.name) !== -1 | ||
) | ||
} | ||
return { | ||
ExpressionStatement: function (node) { | ||
if (!isPromise(node.expression)) { | ||
return | ||
} | ||
var STATIC_METHODS = [ | ||
'all', | ||
'race', | ||
'reject', | ||
'resolve' | ||
] | ||
|
||
// somePromise.then(a, b) | ||
if (allowThen && | ||
node.expression.type === 'CallExpression' && | ||
node.expression.callee.type === 'MemberExpression' && | ||
node.expression.callee.property.name === 'then' && | ||
node.expression.arguments.length === 2 | ||
) { | ||
return | ||
} | ||
function isPromise (expression) { | ||
return ( // hello.then() | ||
expression.type === 'CallExpression' && | ||
expression.callee.type === 'MemberExpression' && | ||
expression.callee.property.name === 'then' | ||
) || ( // hello.catch() | ||
expression.type === 'CallExpression' && | ||
expression.callee.type === 'MemberExpression' && | ||
expression.callee.property.name === 'catch' | ||
) || ( // somePromise.ANYTHING() | ||
expression.type === 'CallExpression' && | ||
expression.callee.type === 'MemberExpression' && | ||
isPromise(expression.callee.object) | ||
) || ( // Promise.STATIC_METHOD() | ||
expression.type === 'CallExpression' && | ||
expression.callee.type === 'MemberExpression' && | ||
expression.callee.object.type === 'Identifier' && | ||
expression.callee.object.name === 'Promise' && | ||
STATIC_METHODS.indexOf(expression.callee.property.name) !== -1 | ||
) | ||
} | ||
|
||
module.exports = { | ||
create: function (context) { | ||
var options = context.options[0] || {} | ||
var allowThen = options.allowThen | ||
var terminationMethod = options.terminationMethod || 'catch' | ||
|
||
return { | ||
ExpressionStatement: function (node) { | ||
if (!isPromise(node.expression)) { | ||
return | ||
} | ||
|
||
// somePromise.then(a, b) | ||
if (allowThen && | ||
node.expression.type === 'CallExpression' && | ||
node.expression.callee.type === 'MemberExpression' && | ||
node.expression.callee.property.name === 'then' && | ||
node.expression.arguments.length === 2 | ||
) { | ||
return | ||
} | ||
|
||
// somePromise.catch() | ||
if (node.expression.type === 'CallExpression' && | ||
node.expression.callee.type === 'MemberExpression' && | ||
node.expression.callee.property.name === terminationMethod | ||
) { | ||
return | ||
// somePromise.catch() | ||
if (node.expression.type === 'CallExpression' && | ||
node.expression.callee.type === 'MemberExpression' && | ||
node.expression.callee.property.name === terminationMethod | ||
) { | ||
return | ||
} | ||
context.report(node, 'Expected ' + terminationMethod + '() or return') | ||
} | ||
context.report(node, 'Expected ' + terminationMethod + '() or return') | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters