pageClass | sidebarDepth | title | description |
---|---|---|---|
rule-details |
0 |
svelte/prefer-let |
Prefer `let` over `const` for Svelte 5 reactive variable declarations. |
Prefer
let
overconst
for Svelte 5 reactive variable declarations.
- ❗ This rule has not been released yet.
- 🔧 The
--fix
option on the command line can automatically fix some of the problems reported by this rule.
This rule reports usages of const
variable declarations on Svelte reactive
function assignments. While values may not be reassigned in the code itself,
they are reassigned by Svelte.
<script>
/* eslint svelte/prefer-let: "error" */
// ✓ GOOD
let { a, b } = $props();
let c = $state('');
let d = $derived(a * 2);
let e = $derived.by(() => b * 2);
// ✗ BAD
const g = $state(0);
const h = $derived({ count: g });
</script>
{
"svelte/prefer-const": [
"error",
{
"exclude": ["$props", "$derived", "$derived.by", "$state", "$state.raw"]
}
]
}
exclude
: The reactive assignments that you want to exclude from being reported.