Skip to content

Latest commit

 

History

History
38 lines (28 loc) · 874 Bytes

no-return-wrap.md

File metadata and controls

38 lines (28 loc) · 874 Bytes

Disallow wrapping values in Promise.resolve or Promise.reject when not needed (promise/no-return-wrap)

💼 This rule is enabled in the ✅ recommended config.

Ensure that inside a then() or a catch() we always return or throw a raw value instead of wrapping in Promise.resolve or Promise.reject

Valid

myPromise.then(function (val) {
  return val * 2
})
myPromise.then(function (val) {
  throw 'bad thing'
})

Invalid

myPromise.then(function (val) {
  return Promise.resolve(val * 2)
})
myPromise.then(function (val) {
  return Promise.reject('bad thing')
})

Options

allowReject

Pass { allowReject: true } as an option to this rule to permit wrapping returned values with Promise.reject, such as when you would use it as another way to reject the promise.