Skip to content

Commit 5413886

Browse files
committed
tidy
1 parent b8230a0 commit 5413886

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

docs/rules/prefer-const.md

+9-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ description: 'Require `const` declarations for variables that are never reassign
1414

1515
## :book: Rule Details
1616

17-
This rule reports the same as the base ESLint `prefer-const` rule, except that ignores Svelte reactive values such as `$state`, `$derived` and `$props`. If this rule is active, make sure to disable the base `prefer-const` rule, as it will conflict with this rule.
17+
This rule reports the same as the base ESLint `prefer-const` rule, except that ignores Svelte reactive values such as `$derived` and `$props`. If this rule is active, make sure to disable the base `prefer-const` rule, as it will conflict with this rule.
1818

1919
<!--eslint-skip-->
2020

@@ -24,12 +24,18 @@ This rule reports the same as the base ESLint `prefer-const` rule, except that i
2424
2525
// ✓ GOOD
2626
const { a, b } = $props();
27-
let { a, b } = $state();
27+
let c = $state('');
28+
let d = $derived(a * 2);
29+
let e = $derived.by(() => b * 2);
2830
2931
// ✗ BAD
30-
// Imagine obj is not re-assigned, therefore it should be constant
3132
let obj = { a, b };
33+
let g = $state(0);
34+
let h = $state({ count: 1 });
3235
</script>
36+
37+
<input bind:value={c} />
38+
<input bind:value={h.count} />
3339
```
3440

3541
## :wrench: Options

packages/eslint-plugin-svelte/src/rules/prefer-const.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ function findDeclarationCallee(node: TSESTree.Expression) {
1919

2020
/**
2121
* Determines if a declaration should be skipped in the const preference analysis.
22-
* Specifically checks for Svelte's state management utilities ($state, $props, $derived).
22+
* Specifically checks for Svelte's state management utilities ($props, $derived).
2323
*/
2424
function shouldSkipDeclaration(declaration: TSESTree.Expression | null) {
2525
if (!declaration) {

0 commit comments

Comments
 (0)