Skip to content

Latest commit

 

History

History
36 lines (25 loc) · 830 Bytes

no-promise-in-callback.md

File metadata and controls

36 lines (25 loc) · 830 Bytes

Disallow using promises inside of callbacks (promise/no-promise-in-callback)

⚠️ This rule warns in the following configs: ✅ flat/recommended, ✅ recommended.

Discourages the use of promises inside callbacks.

Rule Details

Promises and callbacks are different ways to handle asynchronous code and should not be mixed.

Examples of incorrect code for this rule:

doSomething((err, val) => {
  if (err) console.error(err)
  else doSomethingElse(val).then(console.log)
})

Examples of correct code for this rule:

promisify(doSomething)()
  .then(doSomethingElse)
  .then(console.log)
  .catch(console.error)

When Not To Use It

If you do not want to be notified when using promises inside of callbacks, you can safely disable this rule.