no-let
Disallow mutable let declarations.
Targeted pattern scopeâ
This rule targets VariableDeclaration nodes where kind === "let".
What this rule reportsâ
- Any
letdeclaration not ignored by configured patterns
Why this rule existsâ
const bindings better communicate immutability intent and prevent accidental reassignment.
â Incorrectâ
let total = 0;
â Correctâ
const total = 0;
Additional examplesâ
// â Reassignment with let
let runningTotal = 0;
for (const value of values) {
runningTotal += value;
}
// â
Declarative accumulation
const runningTotal = values.reduce((sum, value) => sum + value, 0);
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-let": "error",
},
},
];
When not to use itâ
let is still practical in tightly scoped algorithms where reassignment improves clarity (for example, pointer-based parsing loops or numeric simulations). If those hotspots are rare, keep no-let enabled globally and add selective per-file overrides.
Rule catalog ID: R905