You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+1
Original file line number
Diff line number
Diff line change
@@ -361,6 +361,7 @@ These rules relate to better ways of doing things to help you avoid problems:
361
361
|[svelte/no-reactive-functions](https://sveltejs.github.io/eslint-plugin-svelte/rules/no-reactive-functions/)| it's not necessary to define functions in reactive statements |:star::bulb:|
362
362
|[svelte/no-reactive-literals](https://sveltejs.github.io/eslint-plugin-svelte/rules/no-reactive-literals/)| don't assign literal values in reactive statements |:star::bulb:|
363
363
|[svelte/no-svelte-internal](https://sveltejs.github.io/eslint-plugin-svelte/rules/no-svelte-internal/)| svelte/internal will be removed in Svelte 6. |:star:|
364
+
|[svelte/no-unnecessary-state-wrap](https://sveltejs.github.io/eslint-plugin-svelte/rules/no-unnecessary-state-wrap/)| Disallow unnecessary $state wrapping of reactive classes |:star::wrench::bulb:|
364
365
|[svelte/no-unused-class-name](https://sveltejs.github.io/eslint-plugin-svelte/rules/no-unused-class-name/)| disallow the use of a class in the template without a corresponding style ||
|[svelte/no-useless-children-snippet](https://sveltejs.github.io/eslint-plugin-svelte/rules/no-useless-children-snippet/)| disallow explicit children snippet where it's not needed |:star:|
|[svelte/block-lang](./rules/block-lang.md)| disallows the use of languages other than those specified in the configuration for the lang attribute of `<script>` and `<style>` blocks. |:bulb:|
52
-
|[svelte/button-has-type](./rules/button-has-type.md)| disallow usage of button without an explicit type attribute ||
53
-
|[svelte/no-at-debug-tags](./rules/no-at-debug-tags.md)| disallow the use of `{@debug}`|:star:|
54
-
|[svelte/no-ignored-unsubscribe](./rules/no-ignored-unsubscribe.md)| disallow ignoring the unsubscribe method returned by the `subscribe()` on Svelte stores. ||
55
-
|[svelte/no-immutable-reactive-statements](./rules/no-immutable-reactive-statements.md)| disallow reactive statements that don't reference reactive values. |:star:|
56
-
|[svelte/no-inline-styles](./rules/no-inline-styles.md)| disallow attributes and directives that produce inline styles ||
57
-
|[svelte/no-inspect](./rules/no-inspect.md)| Warns against the use of `$inspect` directive |:star:|
58
-
|[svelte/no-reactive-functions](./rules/no-reactive-functions.md)| it's not necessary to define functions in reactive statements |:star::bulb:|
59
-
|[svelte/no-reactive-literals](./rules/no-reactive-literals.md)| don't assign literal values in reactive statements |:star::bulb:|
60
-
|[svelte/no-svelte-internal](./rules/no-svelte-internal.md)| svelte/internal will be removed in Svelte 6. |:star:|
61
-
|[svelte/no-unused-class-name](./rules/no-unused-class-name.md)| disallow the use of a class in the template without a corresponding style ||
|[svelte/block-lang](./rules/block-lang.md)| disallows the use of languages other than those specified in the configuration for the lang attribute of `<script>` and `<style>` blocks. |:bulb:|
52
+
|[svelte/button-has-type](./rules/button-has-type.md)| disallow usage of button without an explicit type attribute ||
53
+
|[svelte/no-at-debug-tags](./rules/no-at-debug-tags.md)| disallow the use of `{@debug}`|:star:|
54
+
|[svelte/no-ignored-unsubscribe](./rules/no-ignored-unsubscribe.md)| disallow ignoring the unsubscribe method returned by the `subscribe()` on Svelte stores. ||
55
+
|[svelte/no-immutable-reactive-statements](./rules/no-immutable-reactive-statements.md)| disallow reactive statements that don't reference reactive values. |:star:|
56
+
|[svelte/no-inline-styles](./rules/no-inline-styles.md)| disallow attributes and directives that produce inline styles ||
57
+
|[svelte/no-inspect](./rules/no-inspect.md)| Warns against the use of `$inspect` directive |:star:|
58
+
|[svelte/no-reactive-functions](./rules/no-reactive-functions.md)| it's not necessary to define functions in reactive statements |:star::bulb:|
59
+
|[svelte/no-reactive-literals](./rules/no-reactive-literals.md)| don't assign literal values in reactive statements |:star::bulb:|
60
+
|[svelte/no-svelte-internal](./rules/no-svelte-internal.md)| svelte/internal will be removed in Svelte 6. |:star:|
61
+
|[svelte/no-unnecessary-state-wrap](./rules/no-unnecessary-state-wrap.md)| Disallow unnecessary $state wrapping of reactive classes |:star::wrench::bulb:|
62
+
|[svelte/no-unused-class-name](./rules/no-unused-class-name.md)| disallow the use of a class in the template without a corresponding style ||
description: 'Disallow unnecessary $state wrapping of reactive classes'
6
+
---
7
+
8
+
# svelte/no-unnecessary-state-wrap
9
+
10
+
> Disallow unnecessary $state wrapping of reactive classes
11
+
12
+
-:exclamation: <badgetext="This rule has not been released yet."vertical="middle"type="error"> **_This rule has not been released yet._** </badge>
13
+
-:gear: This rule is included in `"plugin:svelte/recommended"`.
14
+
-:wrench: The `--fix` option on the [command line](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems) can automatically fix some of the problems reported by this rule.
15
+
-:bulb: Some problems reported by this rule are manually fixable by editor [suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions).
16
+
17
+
## :book: Rule Details
18
+
19
+
In Svelte 5, several built-in classes from `svelte/reactivity` are already reactive by default:
20
+
21
+
-`SvelteSet`
22
+
-`SvelteMap`
23
+
-`SvelteURL`
24
+
-`SvelteURLSearchParams`
25
+
-`SvelteDate`
26
+
-`MediaQuery`
27
+
28
+
Therefore, wrapping them with `$state` is unnecessary and can lead to confusion.
-`additionalReactiveClasses` ... An array of class names that should also be considered reactive. This is useful when you have custom classes that are inherently reactive. Default is `[]`.
0 commit comments