promise/catch-or-return
eslint-plugin-promise
No autofixRecommended
eslint.config.js
import promise from "eslint-plugin-promise";
export default [
{
plugins: { promise },
rules: {
"promise/catch-or-return": "error",
},
},
];myPromise.then(doSomething)
myPromise.then(doSomething, catchErrors) // catch() may be a little better
function doSomethingElse() {
return myPromise.then(doSomething)
}myPromise.then(doSomething).catch(errors)
myPromise.then(doSomething).then(doSomethingElse).catch(errors)
function doSomethingElse() {
return myPromise.then(doSomething)
}Examples from the ESLint documentation.
promise/catch-or-return
eslint-plugin-promise
import promise from "eslint-plugin-promise";
export default [
{
plugins: { promise },
rules: {
"promise/catch-or-return": "error",
},
},
];promise/catch-or-return
promise plugin · restriction
{
"plugins": [
"promise"
],
"rules": {
"promise/catch-or-return": "error"
}
}Biome does not have this rule.
Require returning inside each then() to create readable and reusable Promise chains.
Disallow calling cb() inside of a then() (use [util.callbackify][] instead).
Disallow nested then() or catch() statements.
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.