unicorn/prefer-then-catch
eslint-plugin-unicorn
Suggestion
eslint.config.js
import unicorn from "eslint-plugin-unicorn";
export default [
{
plugins: { unicorn },
rules: {
"unicorn/prefer-then-catch": "error",
},
},
];Prefer .then().catch() over .then(…, …) for error handling.
fetch(url).then(
response => JSON.parse(response),
error => {
log(error);
},
);fetch(url)
.then(response => JSON.parse(response))
.catch(error => {
log(error);
});promise.then(undefined, handleError);
promise.then(onFulfilled, undefined);Examples from the ESLint documentation.
unicorn/prefer-then-catch
eslint-plugin-unicorn
import unicorn from "eslint-plugin-unicorn";
export default [
{
plugins: { unicorn },
rules: {
"unicorn/prefer-then-catch": "error",
},
},
];Oxlint does not have this rule.
Biome does not have this rule.
Prefer declaring variables and type aliases in the smallest possible scope.
Require type literals to be last in union types.
Prefer a single object destructuring declaration per local const source.
Require parentheses around complex spread arguments.
Prefer simple conditions first in logical expressions.
Enforce a consistent style for single-line block comments.