Skip to content

Commit be2c4db

Browse files
committed
wip: make suggestions instead
Per conversation with @ota-meshi in the PR
1 parent bab0d03 commit be2c4db

File tree

1 file changed

+20
-24
lines changed

1 file changed

+20
-24
lines changed

src/rules/no-extra-reactive-curlies.ts

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,49 +10,45 @@ export default createRule("no-extra-reactive-curlies", {
1010
recommended: false,
1111
conflictWithPrettier: false,
1212
},
13-
fixable: "code",
13+
hasSuggestions: true,
1414
schema: [],
1515
messages: {
1616
extraCurlies: `Do not wrap reactive statements in curly braces unless necessary.`,
17+
removeExtraCurlies: `Remove the unnecessary curly braces.`,
1718
},
1819
type: "suggestion",
1920
},
2021
create(context) {
2122
return {
23+
// $: { foo = "bar"; }
2224
[`SvelteReactiveStatement > BlockStatement[body.length=1]`]: (
2325
node: TSESTree.BlockStatement,
2426
) => {
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-
3527
const source = context.getSourceCode()
3628

3729
return context.report({
3830
node,
3931
loc: node.loc,
4032
messageId: "extraCurlies",
33+
suggest: [
34+
{
35+
messageId: "removeExtraCurlies",
36+
fix(fixer) {
37+
const tokens = source.getTokens(node, { includeComments: true })
4138

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]]),
4943

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+
],
5652
})
5753
},
5854
}

0 commit comments

Comments
 (0)