is-inside-callback.js 631 B

1234567891011121314151617181920
  1. 'use strict'
  2. const isInsidePromise = require('./is-inside-promise')
  3. function isInsideCallback(node) {
  4. const isCallExpression =
  5. node.type === 'FunctionExpression' ||
  6. node.type === 'ArrowFunctionExpression' ||
  7. node.type === 'FunctionDeclaration' // this may be controversial
  8. // it's totally fine to use promises inside promises
  9. if (isInsidePromise(node)) return
  10. const name = node.params && node.params[0] && node.params[0].name
  11. const firstArgIsError = name === 'err' || name === 'error'
  12. const isInACallback = isCallExpression && firstArgIsError
  13. return isInACallback
  14. }
  15. module.exports = isInsideCallback