forked from sveltejs/eslint-plugin-svelte
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathno-store-async.ts
49 lines (47 loc) · 1.25 KB
/
no-store-async.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import { createRule } from "../utils"
import { extractStoreReferences } from "./reference-helpers/svelte-store"
export default createRule("no-store-async", {
meta: {
docs: {
description:
"disallow using async/await inside svelte stores because it causes issues with the auto-unsubscribing features",
category: "Possible Errors",
recommended: true,
default: "error",
},
schema: [],
messages: {
unexpected: "Do not pass async functions to svelte stores.",
},
type: "problem",
},
create(context) {
return {
Program() {
for (const { node } of extractStoreReferences(context)) {
const [, fn] = node.arguments
if (
!fn ||
(fn.type !== "ArrowFunctionExpression" &&
fn.type !== "FunctionExpression") ||
!fn.async
) {
continue
}
const start = fn.loc?.start ?? { line: 1, column: 0 }
context.report({
node: fn,
loc: {
start,
end: {
line: start.line,
column: start.column + 5,
},
},
messageId: "unexpected",
})
}
},
}
},
})