prefer-const-binding
Suggests const for a binding that is declared with let but never reassigned after initialization.
let is a promise to the reader that a binding will change. When it never does, the promise is false advertising — the next person to touch the function has to trace every branch to confirm the variable really is stable before they can reason about it safely. Schist scans each binding's reference list for a write after its initializer; if none exists, the declaration is a hint, not a warning, because a mutable binding that happens not to mutate yet is not a bug, just an opportunity.
Violation and fix
let config = loadConfig();
let handler = (event: Event) => {
config.count += 1;
};
const config = loadConfig();
const handler = (event: Event) => {
config.count += 1;
};
Note that config.count += 1 mutates a property on the object config points at, not the config binding itself — the reference never changes, so const is correct even though the object it holds is mutable. Schist's binding analysis distinguishes property mutation from reassignment; a rule that conflated the two would produce false positives on nearly every object-holding binding in a typical codebase.
Autofix
Rewriting let to const is mechanical and behavior-preserving by construction — if a later write existed, the rule would not have fired — so Schist applies this fix in the same pass as no-unused-import when both are enabled.
Configuration
[rules.prefer-const-binding]
severity = "hint"
autofix = true
There is no ignore list for this rule; if a binding is ever reassigned, the analysis simply does not flag it, so exemptions are rarely necessary.
Related
- no-unused-import — the other rule Schist autofixes in the same binding-hygiene pass.
- no-shadowed-binding — a scoping problem the mutability check does not catch.
- Rules index — the full catalog in evaluation order.