Skip to content

Commit 15e0038

Browse files
committed
fix: ignore $state in the prefer-const rule
1 parent 20a2f32 commit 15e0038

File tree

5 files changed

+8
-7
lines changed

5 files changed

+8
-7
lines changed

.changeset/sixty-cars-fail.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'eslint-plugin-svelte': patch
3+
---
4+
5+
fix: ignore `$state` in the `prefer-const` rule

docs/rules/prefer-const.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ since: 'v3.0.0-next.6'
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 `$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`, `$state`, 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

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ function shouldSkipDeclaration(declaration: TSESTree.Expression | null) {
3131
return false;
3232
}
3333

34-
if (callee.type === 'Identifier' && ['$props', '$derived'].includes(callee.name)) {
34+
if (callee.type === 'Identifier' && ['$props', '$derived', '$state'].includes(callee.name)) {
3535
return true;
3636
}
3737

packages/eslint-plugin-svelte/tests/fixtures/rules/prefer-const/invalid/test01-errors.yaml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@
22
line: 3
33
column: 6
44
suggestions: null
5-
- message: "'state' is never reassigned. Use 'const' instead."
6-
line: 4
7-
column: 6
8-
suggestions: null
95
- message: "'raw' is never reassigned. Use 'const' instead."
106
line: 5
117
column: 6

packages/eslint-plugin-svelte/tests/fixtures/rules/prefer-const/invalid/test01-output.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<script>
22
let { prop1, prop2 } = $props();
33
const zero = 0;
4-
const state = $state(0);
4+
let state = $state(0);
55
const raw = $state.raw(0);
66
const doubled = state * 2;
77
let derived = $derived(state * 2);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy