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