Skip to content

Commit 9549560

Browse files
authored
Add object numeric destructuring for reactivity rule
1 parent 8a17ade commit 9549560

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

packages/eslint-plugin-solid/src/rules/reactivity.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@
33
* @link https://github.com/solidjs-community/eslint-plugin-solid/blob/main/docs/reactivity.md
44
*/
55

6-
import { TSESTree as T, TSESLint, ESLintUtils, ASTUtils } from "@typescript-eslint/utils";
6+
import {
7+
TSESTree as T,
8+
TSESLint,
9+
ESLintUtils,
10+
ASTUtils,
11+
AST_NODE_TYPES,
12+
} from "@typescript-eslint/utils";
713
import { traverse } from "estraverse";
814
import {
915
findParent,
@@ -209,6 +215,19 @@ const getNthDestructuredVar = (id: T.Node, n: number, context: CompatContext): V
209215
if (el?.type === "Identifier") {
210216
return findVariable(context, el);
211217
}
218+
} else if (id?.type === "ObjectPattern") {
219+
// {0: a, '1': b, 2: c, ...rest}
220+
const el = id.properties.find((p): p is T.Property => {
221+
if (p.type !== "Property") return false;
222+
if (p.key.type !== "Literal") return false;
223+
224+
const key = p.key;
225+
return key.value === n || (typeof key.value === "string" && key.value === String(n));
226+
});
227+
228+
if (el?.type === "Property" && el.value.type === "Identifier") {
229+
return findVariable(context, el.value);
230+
}
212231
}
213232
return null;
214233
};

0 commit comments

Comments
 (0)