Skip to content

Commit ae139a7

Browse files
authored
fix: no-reactive-literals using :matches(...) (#207)
* fix: corrected query using :matches() Previously it wasn't which meant the resulting query could match too many things. * test: updated tests to reduce false-positives
1 parent f3c3554 commit ae139a7

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/rules/no-reactive-literals.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export default createRule("no-reactive-literals", {
1818
},
1919
create(context) {
2020
return {
21-
[`SvelteReactiveStatement > ExpressionStatement > AssignmentExpression${[
21+
[`SvelteReactiveStatement > ExpressionStatement > AssignmentExpression:matches(${[
2222
// $: foo = "foo";
2323
// $: foo = 1;
2424
`[right.type="Literal"]`,
@@ -28,7 +28,7 @@ export default createRule("no-reactive-literals", {
2828
2929
// $: foo = {};
3030
`[right.type="ObjectExpression"][right.properties.length=0]`,
31-
].join(",")}`](node: TSESTree.AssignmentExpression) {
31+
].join(",")})`](node: TSESTree.AssignmentExpression) {
3232
// Move upwards to include the entire reactive statement
3333
const parent = node.parent?.parent
3434

tests/fixtures/rules/no-reactive-literals/valid/test01-input.svelte

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,10 @@
33
$: foo = `${"bar"}baz`
44
$: bar = [ "bar" ]
55
$: baz = { qux : true }
6+
7+
let qux;
8+
9+
qux = 1;
10+
qux = [];
11+
qux = {};
612
</script>

0 commit comments

Comments
 (0)