@@ -10,49 +10,45 @@ export default createRule("no-extra-reactive-curlies", {
10
10
recommended : false ,
11
11
conflictWithPrettier : false ,
12
12
} ,
13
- fixable : "code" ,
13
+ hasSuggestions : true ,
14
14
schema : [ ] ,
15
15
messages : {
16
16
extraCurlies : `Do not wrap reactive statements in curly braces unless necessary.` ,
17
+ removeExtraCurlies : `Remove the unnecessary curly braces.` ,
17
18
} ,
18
19
type : "suggestion" ,
19
20
} ,
20
21
create ( context ) {
21
22
return {
23
+ // $: { foo = "bar"; }
22
24
[ `SvelteReactiveStatement > BlockStatement[body.length=1]` ] : (
23
25
node : TSESTree . BlockStatement ,
24
26
) => {
25
- // $: { foo = "bar"; }
26
- // Only want to transform if the contents of the block is a single assignment
27
- // Anything else gets us into potentially weird territory and probably isn't worth handling
28
- if (
29
- node . body [ 0 ] . type !== "ExpressionStatement" ||
30
- node . body [ 0 ] . expression . type !== "AssignmentExpression"
31
- ) {
32
- return false
33
- }
34
-
35
27
const source = context . getSourceCode ( )
36
28
37
29
return context . report ( {
38
30
node,
39
31
loc : node . loc ,
40
32
messageId : "extraCurlies" ,
33
+ suggest : [
34
+ {
35
+ messageId : "removeExtraCurlies" ,
36
+ fix ( fixer ) {
37
+ const tokens = source . getTokens ( node , { includeComments : true } )
41
38
42
- fix ( fixer ) {
43
- const tokens = source . getTokens ( node , { includeComments : true } )
44
-
45
- // Remove everything up to the second token, and the entire last token since
46
- // those are known to be "{" and "}"
47
- return [
48
- fixer . removeRange ( [ tokens [ 0 ] . range [ 0 ] , tokens [ 1 ] . range [ 0 ] ] ) ,
39
+ // Remove everything up to the second token, and the entire last token since
40
+ // those are known to be "{" and "}"
41
+ return [
42
+ fixer . removeRange ( [ tokens [ 0 ] . range [ 0 ] , tokens [ 1 ] . range [ 0 ] ] ) ,
49
43
50
- fixer . removeRange ( [
51
- tokens [ tokens . length - 2 ] . range [ 1 ] ,
52
- tokens [ tokens . length - 1 ] . range [ 1 ] ,
53
- ] ) ,
54
- ]
55
- } ,
44
+ fixer . removeRange ( [
45
+ tokens [ tokens . length - 2 ] . range [ 1 ] ,
46
+ tokens [ tokens . length - 1 ] . range [ 1 ] ,
47
+ ] ) ,
48
+ ]
49
+ } ,
50
+ } ,
51
+ ] ,
56
52
} )
57
53
} ,
58
54
}
0 commit comments