no-reject
Disallow Promise.reject(...).
Targeted pattern scopeâ
This rule targets CallExpression nodes matching Promise.reject(...).
What this rule reportsâ
- Calls to
Promise.reject(...)
Why this rule existsâ
In immutable/functional error handling, explicit error values are often preferred over rejected promise control flow.
â Incorrectâ
return Promise.reject(new Error("boom"));
â Correctâ
return { ok: false, error: "boom" };
Additional examplesâ
// â Rejecting promise for expected validation outcome
const loadUser = async (id: string) => {
if (!id) {
return Promise.reject(new Error("Missing user id"));
}
return fetchUser(id);
};
// â
Return a value-level failure object
const loadUser = async (id: string) => {
if (!id) {
return { ok: false, error: "Missing user id" };
}
return { ok: true, value: await fetchUser(id) };
};
ESLint flat config exampleâ
import immutable from "eslint-plugin-immutable-2";
export default [
{
files: ["**/*.{js,mjs,cjs,ts,mts,cts,tsx}"],
plugins: { immutable },
rules: {
"immutable/no-reject": "error",
},
},
];
When not to use itâ
Keep Promise.reject if your APIs intentionally model failures as rejected promises (for example, compatibility layers around fetch wrappers or public SDKs that consumers already handle with .catch). In that case, document the error contract and apply this rule only to internal logic.
Rule catalog ID: R909