File tree 2 files changed +46
-0
lines changed
2 files changed +46
-0
lines changed Original file line number Diff line number Diff line change
1
+ import { createRule } from "../utils"
2
+ import type * as ESTree from "estree"
3
+
4
+ export default createRule ( "no-store-async" , {
5
+ meta : {
6
+ docs : {
7
+ description :
8
+ "disallow using async/await inside svelte stores because it causes issues with the auto-unsubscribing features" ,
9
+ category : "Possible Errors" ,
10
+ recommended : true ,
11
+ default : "error" ,
12
+ } ,
13
+ schema : [ ] ,
14
+ messages : {
15
+ unexpected : "Do not pass async functions to svelte stores." ,
16
+ } ,
17
+ type : "problem" ,
18
+ } ,
19
+ create ( context ) {
20
+ return {
21
+ CallExpression ( node : ESTree . CallExpression ) {
22
+ if ( node . callee . type !== "Identifier" ) return
23
+ const { name } = node . callee
24
+ if ( name !== "writable" && name !== "readable" && name !== "derived" )
25
+ return
26
+ const [ , fn ] = node . arguments
27
+ if ( fn . type !== "ArrowFunctionExpression" || ! fn . async ) return
28
+
29
+ const start = fn . loc ?. start ?? { line : 1 , column : 0 }
30
+ context . report ( {
31
+ node : fn ,
32
+ loc : {
33
+ start,
34
+ end : {
35
+ line : start . line ,
36
+ column : start . column + 5 ,
37
+ } ,
38
+ } ,
39
+ messageId : "unexpected" ,
40
+ } )
41
+ } ,
42
+ }
43
+ } ,
44
+ } )
Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ import noReactiveFunctions from "../rules/no-reactive-functions"
21
21
import noReactiveLiterals from "../rules/no-reactive-literals"
22
22
import noShorthandStylePropertyOverrides from "../rules/no-shorthand-style-property-overrides"
23
23
import noSpacesAroundEqualSignsInAttribute from "../rules/no-spaces-around-equal-signs-in-attribute"
24
+ import noStoreAsync from "../rules/no-store-async"
24
25
import noTargetBlank from "../rules/no-target-blank"
25
26
import noUnknownStyleDirectiveProperty from "../rules/no-unknown-style-directive-property"
26
27
import noUnusedSvelteIgnore from "../rules/no-unused-svelte-ignore"
@@ -59,6 +60,7 @@ export const rules = [
59
60
noReactiveLiterals ,
60
61
noShorthandStylePropertyOverrides ,
61
62
noSpacesAroundEqualSignsInAttribute ,
63
+ noStoreAsync ,
62
64
noTargetBlank ,
63
65
noUnknownStyleDirectiveProperty ,
64
66
noUnusedSvelteIgnore ,
You can’t perform that action at this time.
0 commit comments