sfcc/prefer-const
Requires const for let and var declarations that are never reassigned, except in Rhino-sensitive scopes where const would be unsafe.
What it checks
- Finds declarations whose variables are never reassigned
- Skips nested blocks, because Rhino can treat nested
constbindings as conflicting function-scoped bindings - Skips Rhino-critical scopes, such as loop headers and related declarations handled by
sfcc/rhino-const-compat
Fix behavior
- Rewrites eligible
letandvardeclarations toconst - Leaves unsafe scopes alone so
--fixdoes not bounce between conflicting rules
Why this rule exists
The config aims to preserve the safe use of const while avoiding patterns that behave differently in Rhino. That keeps the fix flow stable and makes the Rhino-specific rules cooperate instead of fighting each other.
Default behavior
- Severity:
error - Auto-fix: yes
Example
Invalid
js
let value = compute() Valid
js
const value = compute()