|
| 1 | +--- |
| 2 | +pageClass: "rule-details" |
| 3 | +sidebarDepth: 0 |
| 4 | +title: "svelte/no-store-async" |
| 5 | +description: "disallow using async/await inside svelte stores" |
| 6 | +--- |
| 7 | + |
| 8 | +# svelte/no-store-async |
| 9 | + |
| 10 | +> disallow using async/await inside svelte stores |
| 11 | +
|
| 12 | +- :gear: This rule is included in `"plugin:svelte/recommended"`. |
| 13 | + |
| 14 | +## :book: Rule Details |
| 15 | + |
| 16 | +This rule reports all uses of async/await inside svelte stores. |
| 17 | +Because it causes issues with the auto-unsubscribing features. |
| 18 | + |
| 19 | +<ESLintCodeBlock language="javascript"> |
| 20 | + |
| 21 | +<!--eslint-skip--> |
| 22 | + |
| 23 | +```js |
| 24 | +/* eslint svelte/no-store-async: "error" */ |
| 25 | + |
| 26 | +import { writable, readable, derived } from "svelte/store" |
| 27 | + |
| 28 | +/* ✓ GOOD */ |
| 29 | +const w1 = writable(false, () => {}) |
| 30 | +const r1 = readable(false, () => {}) |
| 31 | +const d1 = derived(a1, ($a1) => {}) |
| 32 | + |
| 33 | +/* ✗ BAD */ |
| 34 | +const w2 = writable(false, async () => {}) |
| 35 | +const r2 = readable(false, async () => {}) |
| 36 | +const d2 = derived(a1, async ($a1) => {}) |
| 37 | +``` |
| 38 | + |
| 39 | +</ESLintCodeBlock> |
| 40 | + |
| 41 | +## :wrench: Options |
| 42 | + |
| 43 | +Nothing. |
| 44 | + |
| 45 | +## :books: Further Reading |
| 46 | + |
| 47 | +- [Svelte - Docs > 4. Prefix stores with $ to access their values / Store contract](https://svelte.dev/docs#component-format-script-4-prefix-stores-with-$-to-access-their-values-store-contract) |
| 48 | + |
| 49 | +## :rocket: Version |
| 50 | + |
| 51 | +This rule was introduced in eslint-plugin-svelte v3.1.0 |
| 52 | + |
| 53 | +## :mag: Implementation |
| 54 | + |
| 55 | +- [Rule source](https://github.com/ota-meshi/eslint-plugin-svelte/blob/main/src/rules/no-store-async.ts) |
| 56 | +- [Test source](https://github.com/ota-meshi/eslint-plugin-svelte/blob/main/tests/src/rules/no-store-async.ts) |
0 commit comments