promise/always-return
eslint-plugin-promise
No autofixRecommended
eslint.config.js
import promise from "eslint-plugin-promise";
export default [
{
plugins: { promise },
rules: {
"promise/always-return": "error",
},
},
];Require returning inside each then() to create readable and reusable Promise chains.
myPromise.then(function (val) {})
myPromise.then(() => {
doSomething()
})
myPromise.then((b) => {
if (b) {
return 'yes'
} else {
forgotToReturn()
}
})myPromise.then((val) => val * 2)
myPromise.then(function (val) {
return val * 2
})
myPromise.then(doSomething) // could be either
myPromise.then((b) => {
if (b) {
return 'yes'
} else {
return 'no'
}
})Examples from the ESLint documentation.
promise/always-return
eslint-plugin-promise
import promise from "eslint-plugin-promise";
export default [
{
plugins: { promise },
rules: {
"promise/always-return": "error",
},
},
];promise/always-return
promise plugin · suspicious
{
"plugins": [
"promise"
],
"rules": {
"promise/always-return": "error"
}
}Biome does not have this rule.
Disallow nested then() or catch() statements.
Enforce the use of catch() on un-returned promises.
Disallow calling cb() inside of a then() (use [util.callbackify][] instead).
Disallow calling new on a Promise static method.
Disallow using promises inside of callbacks.
Enforces the proper number of arguments are passed to Promise functions.