You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
20 lines
631 B
20 lines
631 B
'use strict' |
|
|
|
const isInsidePromise = require('./is-inside-promise') |
|
|
|
function isInsideCallback(node) { |
|
const isCallExpression = |
|
node.type === 'FunctionExpression' || |
|
node.type === 'ArrowFunctionExpression' || |
|
node.type === 'FunctionDeclaration' // this may be controversial |
|
|
|
// it's totally fine to use promises inside promises |
|
if (isInsidePromise(node)) return |
|
|
|
const name = node.params && node.params[0] && node.params[0].name |
|
const firstArgIsError = name === 'err' || name === 'error' |
|
const isInACallback = isCallExpression && firstArgIsError |
|
return isInACallback |
|
} |
|
|
|
module.exports = isInsideCallback
|
|
|