Skip to content

Latest commit

 

History

History
42 lines (28 loc) · 938 Bytes

no-promise-in-callback.md

File metadata and controls

42 lines (28 loc) · 938 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)

Options

exemptDeclarations

Whether or not to exempt function declarations. Defaults to false.

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.