no-conditional-statement
Disallow if and switch statements.
Targeted pattern scopeβ
This rule targets IfStatement and SwitchStatement nodes.
What this rule reportsβ
- Any
ifstatement (or branch completeness issues when configured) - Any
switchstatement (or case completeness issues when configured)
Why this rule existsβ
Expression-oriented branching is easier to compose and test in immutable-style codebases.
β Incorrectβ
if (enabled) {
return a;
}
return b;
β Correctβ
return enabled ? a : b;
Additional examplesβ
// β Switch statement branching
switch (status) {
case "idle":
return "Ready";
case "loading":
return "Loadingβ¦";
default:
return "Done";
}
// β
Lookup table expression
const labels = {
done: "Done",
idle: "Ready",
loading: "Loadingβ¦",
} as const;
return labels[status] ?? "Done";
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-conditional-statement": "error",
},
},
];
When not to use itβ
If your team favors explicit if/switch statements for readability (especially in long business workflows), enforcing expression-only branching can hurt clarity. In those modules, prefer keeping conventional branching and use other immutability rules to guard mutation.
Rule catalog ID: R903