Skip to content

noSvelteUnnecessaryStateWrap

biome.json
{
"linter": {
"rules": {
"nursery": {
"noSvelteUnnecessaryStateWrap": "error"
}
}
}
}

Disallow unnecessary $state wrapping of reactive classes.

Several classes exported from svelte/reactivity — such as SvelteMap, SvelteSet, and SvelteDate — are already deeply reactive without the $state rune. Wrapping them in $state(...) is redundant and may mislead readers into thinking the reactivity comes from the rune rather than the class itself.

Use the additionalReactiveClasses option to extend this list with custom reactive classes from your own codebase.

Use allowReassign: true if you need to reassign the variable itself after declaration, which requires $state to track the reference change.

<script>
import { SvelteMap } from "svelte/reactivity";
const map = $state(new SvelteMap());
</script>
code-block.svelte:2:13 lint/nursery/noSvelteUnnecessaryStateWrap  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━

SvelteMap is already reactive, wrapping it in $state() is unnecessary.

1 │ import { SvelteMap } from “svelte/reactivity”;
> 2 │ const map = $state(new SvelteMap());
^^^^^^^^^^^^^^^^^^^^^^^
3 │

Classes from svelte/reactivity track their own mutations without needing a $state wrapper.

This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

Unsafe fix: Remove the unnecessary $state() wrapper.

2 │ const·map·=·$state(new·SvelteMap());
------- -
<script>
import { SvelteMap } from "svelte/reactivity";
const map = new SvelteMap();
</script>

When true, suppresses the autofix for variables that are reassigned after declaration. Because reassigning a $state-wrapped value changes the binding itself, removing $state would break reactivity for those reassignments. The diagnostic still fires — only the unsafe autofix is withheld.

Default: false

biome.json
{
"linter": {
"rules": {
"nursery": {
"noSvelteUnnecessaryStateWrap": {
"level": "on",
"options": {
"allowReassign": true
}
}
}
}
}
}
<script>
import { SvelteMap } from "svelte/reactivity";
const map = $state(new SvelteMap());
</script>
code-block.svelte:2:13 lint/nursery/noSvelteUnnecessaryStateWrap  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━

SvelteMap is already reactive, wrapping it in $state() is unnecessary.

1 │ import { SvelteMap } from “svelte/reactivity”;
> 2 │ const map = $state(new SvelteMap());
^^^^^^^^^^^^^^^^^^^^^^^
3 │

Classes from svelte/reactivity track their own mutations without needing a $state wrapper.

This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

Unsafe fix: Remove the unnecessary $state() wrapper.

2 │ const·map·=·$state(new·SvelteMap());
------- -
<script>
import { SvelteMap } from "svelte/reactivity";
let map = $state(new SvelteMap());
map = new SvelteMap();
</script>
code-block.svelte:2:11 lint/nursery/noSvelteUnnecessaryStateWrap ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

SvelteMap is already reactive, wrapping it in $state() is unnecessary.

1 │ import { SvelteMap } from “svelte/reactivity”;
> 2 │ let map = $state(new SvelteMap());
^^^^^^^^^^^^^^^^^^^^^^^
3 │ map = new SvelteMap();
4 │

Classes from svelte/reactivity track their own mutations without needing a $state wrapper.

This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

An array of additional class names to treat as already reactive (beyond the built-in svelte/reactivity classes). Use this to extend the rule with custom reactive classes from your own codebase.

biome.json
{
"linter": {
"rules": {
"nursery": {
"noSvelteUnnecessaryStateWrap": {
"level": "on",
"options": {
"additionalReactiveClasses": [
"MyReactiveStore"
]
}
}
}
}
}
}
<script>
const store = $state(new MyReactiveStore());
</script>
code-block.svelte:1:15 lint/nursery/noSvelteUnnecessaryStateWrap  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━

MyReactiveStore is already reactive, wrapping it in $state() is unnecessary.

> 1 │ const store = $state(new MyReactiveStore());
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2 │

Classes from svelte/reactivity track their own mutations without needing a $state wrapper.

This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

Unsafe fix: Remove the unnecessary $state() wrapper.

1 │ const·store·=·$state(new·MyReactiveStore());
------- -
<script>
const store = new MyReactiveStore();
</script>