Skip to content

Latest commit

 

History

History
39 lines (29 loc) · 910 Bytes

no-return-wrap.md

File metadata and controls

39 lines (29 loc) · 910 Bytes

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

💼 This rule is enabled in the following configs: ✅ flat/recommended, ✅ recommended.

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.