no-expression-statement
Disallow standalone expression statements.
Targeted pattern scopeâ
This rule targets ExpressionStatement nodes, with optional ignore patterns.
What this rule reportsâ
- Top-level or block-level expression statements used only for side effects
Why this rule existsâ
Expression statements often hide mutation and side effects. Explicit value flow is clearer in immutable code.
â Incorrectâ
doWork();
â Correctâ
const result = compute(input);
Additional examplesâ
// â Side-effect expression statement
analytics.track("checkout_started");
// â
Explicit command collection
const event = {
name: "checkout_started",
timestamp: Date.now(),
};
return publishAnalytics(event);
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-expression-statement": "error",
},
},
];
When not to use itâ
Disable this rule for side-effect-centric entry points such as CLI bootstrap files, telemetry initializers, or test setup scripts. Those files are intentionally imperative, and forcing expression-only style there usually adds ceremony without real safety gains.
Rule catalog ID: R904