@itin-labs/eslint-plugin-worklet-order 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/README.md +19 -5
- package/dist/rule.d.ts +3 -0
- package/dist/rule.js +176 -17
- package/package.json +4 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @itin-labs/eslint-plugin-worklet-order
|
|
2
2
|
|
|
3
|
+
## 0.2.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- d10951c: Changed: the messages no longer say the worklet "gets undefined". With React Native's preset that's what happens to a `const` or `let`, but a class, or a build that keeps block scoping, throws a `ReferenceError` when the module loads instead. They now say the variable isn't set yet, which covers both.
|
|
8
|
+
- d10951c: Added: functions the Babel plugin makes worklets without a `'worklet'` directive are checked too. That's a function passed inline or by name to `useAnimatedStyle`, `useDerivedValue`, `runOnUI`, an animation's callback, a `Gesture.Pan()` callback and the other calls the plugin knows, from anywhere in the file. So `useAnimatedStyle(styleFn)` in a component now gets a module-level `function styleFn` reported when it uses a constant declared below it, and module-level code that uses `styleFn` above its declaration is reported as well. The rule's docs list the calls, and the README lists the cases it still doesn't follow.
|
|
9
|
+
|
|
10
|
+
### Patch Changes
|
|
11
|
+
|
|
12
|
+
- d10951c: Fixed: a worklet that only assigns to a variable declared further down, with `=`, `+=` and the like or as a destructuring target, is no longer reported. The Babel plugin doesn't capture those. `x++` and a `for (x of ...)` target are still reported, since the plugin captures them.
|
|
13
|
+
- d10951c: Fixed: with a Flow parser, a `typeof` in a type above a worklet declaration, and `declare var`, `declare function` or `declare class` below a worklet, are no longer reported. The build erases both. Names in Flow annotations inside a worklet are still checked, because the Babel plugin captures them.
|
|
14
|
+
|
|
3
15
|
## 0.1.0
|
|
4
16
|
|
|
5
17
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -16,6 +16,17 @@ export default [
|
|
|
16
16
|
];
|
|
17
17
|
```
|
|
18
18
|
|
|
19
|
+
The package is an ES module, so in a CommonJS config the plugin is the `default` of what `require` returns:
|
|
20
|
+
|
|
21
|
+
```js
|
|
22
|
+
// eslint.config.cjs
|
|
23
|
+
const workletOrder = require('@itin-labs/eslint-plugin-worklet-order').default;
|
|
24
|
+
|
|
25
|
+
module.exports = [workletOrder.configs.recommended];
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
It needs ESLint 9 or later with a flat config (the older `.eslintrc` format isn't supported) and Node 22.12 or later. ESLint lints only `.js`, `.mjs` and `.cjs` files unless a config entry names others, so `.ts` and `.tsx` files need an entry with a TypeScript parser, such as typescript-eslint's, in front of this one.
|
|
29
|
+
|
|
19
30
|
It's for anyone writing worklets as plain functions at the top of a module, which is the usual way to share math between gesture handlers and animated styles.
|
|
20
31
|
|
|
21
32
|
## The problem
|
|
@@ -62,7 +73,9 @@ Module-level code that uses a worklet function declared further down, outside an
|
|
|
62
73
|
|
|
63
74
|
Files that start with a `'worklet'` directive are understood too: there the plugin makes every top-level function a worklet, so plain function declarations lose their hoisting as well.
|
|
64
75
|
|
|
65
|
-
|
|
76
|
+
So are most functions the plugin makes worklets without a directive: a function passed inline or by name to `useAnimatedStyle`, `useDerivedValue`, `runOnUI`, an animation's callback, a gesture callback such as `Gesture.Pan().onEnd(...)`, and the other calls listed in the rule's docs. A call anywhere in the file counts, so `function styleFn() { return { opacity: OPACITY }; }` above `const OPACITY = 0.5`, used from a component as `useAnimatedStyle(styleFn)`, is reported: the plugin makes `styleFn` a worklet, which captures `OPACITY` before it's set.
|
|
77
|
+
|
|
78
|
+
It doesn't report imports, configured globals, plain function declarations in ordinary files (they're hoisted with their value), `declare` statements, a named worklet calling itself, worklets marked `'no-worklet-closure'`, uses only in TypeScript types or in a Flow `typeof` outside a worklet, assignments to a variable (`x = 1`, `x += 1`, destructuring), JSX element names, or anything shadowed by a local name. The details and more examples are in [the rule's docs](docs/rules/no-capture-before-define.md).
|
|
66
79
|
|
|
67
80
|
## How it compares
|
|
68
81
|
|
|
@@ -74,11 +87,12 @@ ESLint's own `no-use-before-define` doesn't fit. With its defaults it reports th
|
|
|
74
87
|
|
|
75
88
|
What the rule doesn't catch, or can't:
|
|
76
89
|
|
|
77
|
-
-
|
|
90
|
+
- Some functions the plugin makes worklets without a directive. The rule follows functions passed to the calls its docs list, and not these, which still capture when they're defined: functions in an object argument, such as `useAnimatedScrollHandler({ onScroll: handleScroll })` or the `use...Gesture` hooks, even when they name a module-level function; layout animation callbacks such as `FadeIn.withCallback(...)`; functions in a config object, such as `withTiming`'s `easing` or `createWorkletRuntime`'s `initializer`; a name that reaches the function through another variable (`const g = f`) or an assignment after its declaration (`let f; f = () => ...`); and a call written as `(0, runOnUI)(f)` or `(api?.runOnUI)(f)`. The lists match react-native-worklets 0.14.1, which a weekly check compares with the newest release; Reanimated 3's own copy of the plugin isn't checked.
|
|
78
91
|
- Worklets created inside a function that happens to run while the module loads, such as an IIFE.
|
|
79
|
-
- Bindings declared inside a module-level block, like `if (x) { const L = 1; }
|
|
80
|
-
- A named `export default function snap() { 'worklet'; ... }`. The plugin replaces it with `export default factory(...)`, so the name `snap` stops existing inside the file
|
|
92
|
+
- Bindings declared inside a module-level block, like `if (x) { const L = 1; }`, or inside a TypeScript namespace. Only bindings at the top of the module are checked.
|
|
93
|
+
- A named `export default function snap() { 'worklet'; ... }`. The plugin replaces it with `export default factory(...)`, so the name `snap` stops existing inside the file, and every use of it throws a `ReferenceError`. The rule reports uses above the declaration, with a message that assumes `snap` becomes a `const` there, and doesn't report uses below it.
|
|
81
94
|
- Worklets that call each other in a cycle. No order works, since each captures the other when it's defined; the rule reports one of them. Pass one in as an argument, or merge them.
|
|
95
|
+
- Flow types inside a worklet. The plugin skips TypeScript's types when it works out what a worklet captures, but not Flow's, so a type alias or imported type named in an annotation inside a worklet, its parameters and return type included, is captured, and the build erases it: a `ReferenceError` when the worklet is defined. The rule reports this only when the type is declared further down with `type`, `opaque type` or `interface` (not `declare type`), and then its advice to move the declaration doesn't help.
|
|
82
96
|
- Worklet classes (a class in a worklet file, or one with `__workletClass`), and worklet methods, which the plugin turns into instance fields created per instance.
|
|
83
97
|
- One file at a time, so it can't follow a capture into another module. Imports are always safe for this reason.
|
|
84
98
|
- Values that change. A `let` reassigned after the worklet is defined stays at its old value inside the worklet, which is a different problem.
|
|
@@ -92,7 +106,7 @@ The rule only reads the code ESLint gives it, and never uses the network. When i
|
|
|
92
106
|
|
|
93
107
|
## Status and versioning
|
|
94
108
|
|
|
95
|
-
The RuleTester tests cover every case above, with TypeScript cases through typescript-eslint's parser, and check the recommended config end to end. A property-based test runs the rule on 500 generated modules each run, with nested and shadowed uses, and compares it with an oracle that restates the rule's position logic, so it checks the scope handling but can't catch a wrong model of the plugin. A differential test covers that: it runs the real worklets Babel plugin on every test input and checks that the rule reports exactly the captures and early uses Babel's output has. It needs the plugin, which isn't a dev dependency because it pulls in react-native, so it
|
|
109
|
+
The RuleTester tests cover every case above, with TypeScript cases through typescript-eslint's parser and Flow cases through hermes-eslint, and check the recommended config end to end. A property-based test runs the rule on 500 generated modules each run, with nested and shadowed uses, and compares it with an oracle that restates the rule's position logic, so it checks the scope handling but can't catch a wrong model of the plugin. A differential test covers that: it runs the real worklets Babel plugin on every test input and checks that the rule reports exactly the captures and early uses Babel's output has. It needs the plugin, which isn't a dev dependency because it pulls in react-native, so CI installs it: a fixed version on every pull request, and the newest release weekly. A plain `npm test` skips it. CI runs the rest on Node 22, 24 and 26 with ESLint 10, and on ESLint 9.0.
|
|
96
110
|
|
|
97
111
|
Versions are 0.x until the rule has settled. A minor release can report new cases or change messages, and says so in the changelog; a patch release only fixes false positives or crashes. 1.0 will come when:
|
|
98
112
|
|
package/dist/rule.d.ts
CHANGED
package/dist/rule.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
// The worklets Babel plugin skips identifiers inside type positions when it builds a
|
|
2
|
-
// ESLint's own types don't know these
|
|
1
|
+
// The worklets Babel plugin skips identifiers inside TypeScript type positions when it builds a
|
|
2
|
+
// closure. ESLint's own types don't know these node types, so they're compared as strings.
|
|
3
3
|
const TYPE_POSITIONS = new Set([
|
|
4
4
|
'TSTypeAnnotation',
|
|
5
5
|
'TSTypeQuery',
|
|
@@ -10,6 +10,69 @@ const TYPE_POSITIONS = new Set([
|
|
|
10
10
|
'TSTypeParameterDeclaration',
|
|
11
11
|
'TSClassImplements',
|
|
12
12
|
]);
|
|
13
|
+
// Outside a worklet, Flow's `typeof x` is erased too. Inside one it isn't: the plugin skips only
|
|
14
|
+
// TypeScript's types, so a name in a Flow annotation there is captured like any other.
|
|
15
|
+
const ERASED_OUTSIDE_WORKLETS = new Set([...TYPE_POSITIONS, 'TypeofTypeAnnotation']);
|
|
16
|
+
// Calls whose function arguments the plugin makes worklets without a directive, with the argument
|
|
17
|
+
// positions it looks at, and the gesture chains whose callbacks it does the same for. Copied from
|
|
18
|
+
// react-native-worklets 0.14.1: reanimatedFunctionArgsToWorkletize in autoworkletization.ts, and
|
|
19
|
+
// gestureHandlerGestureObjects and gestureHandlerBuilderMethods in
|
|
20
|
+
// gestureHandlerAutoworkletization.ts, both under plugin/src in its repository and bundled into
|
|
21
|
+
// plugin/index.js in the package. The differential test compares them with the installed plugin's
|
|
22
|
+
// bundle, so the weekly run against its newest release fails when they change.
|
|
23
|
+
export const WORKLET_ARGUMENTS = new Map([
|
|
24
|
+
['useFrameCallback', [0]],
|
|
25
|
+
['useAnimatedStyle', [0]],
|
|
26
|
+
['useAnimatedProps', [0]],
|
|
27
|
+
['createAnimatedPropAdapter', [0]],
|
|
28
|
+
['useDerivedValue', [0]],
|
|
29
|
+
['useAnimatedScrollHandler', [0]],
|
|
30
|
+
['useAnimatedReaction', [0, 1]],
|
|
31
|
+
['withTiming', [2, 3]],
|
|
32
|
+
['withSpring', [2, 3]],
|
|
33
|
+
['withDecay', [1]],
|
|
34
|
+
['withRepeat', [3]],
|
|
35
|
+
['runOnUI', [0]],
|
|
36
|
+
['executeOnUIRuntimeSync', [0]],
|
|
37
|
+
['scheduleOnUI', [0]],
|
|
38
|
+
['runOnUISync', [0]],
|
|
39
|
+
['runOnUIAsync', [0]],
|
|
40
|
+
['runOnRuntime', [1]],
|
|
41
|
+
['runOnRuntimeSync', [1]],
|
|
42
|
+
['runOnRuntimeAsync', [1]],
|
|
43
|
+
['scheduleOnRuntime', [1]],
|
|
44
|
+
['runOnRuntimeSyncWithId', [1]],
|
|
45
|
+
['runOnRuntimeAsyncWithId', [1]],
|
|
46
|
+
['scheduleOnRuntimeWithId', [1]],
|
|
47
|
+
['createWorkletRuntime', [1]],
|
|
48
|
+
]);
|
|
49
|
+
export const GESTURE_OBJECTS = new Set([
|
|
50
|
+
'Tap',
|
|
51
|
+
'Pan',
|
|
52
|
+
'Pinch',
|
|
53
|
+
'Rotation',
|
|
54
|
+
'Fling',
|
|
55
|
+
'LongPress',
|
|
56
|
+
'ForceTouch',
|
|
57
|
+
'Native',
|
|
58
|
+
'Manual',
|
|
59
|
+
'Race',
|
|
60
|
+
'Simultaneous',
|
|
61
|
+
'Exclusive',
|
|
62
|
+
'Hover',
|
|
63
|
+
]);
|
|
64
|
+
export const GESTURE_CALLBACKS = new Set([
|
|
65
|
+
'onBegin',
|
|
66
|
+
'onStart',
|
|
67
|
+
'onEnd',
|
|
68
|
+
'onFinalize',
|
|
69
|
+
'onUpdate',
|
|
70
|
+
'onChange',
|
|
71
|
+
'onTouchesDown',
|
|
72
|
+
'onTouchesMove',
|
|
73
|
+
'onTouchesUp',
|
|
74
|
+
'onTouchesCancelled',
|
|
75
|
+
]);
|
|
13
76
|
export const rule = {
|
|
14
77
|
meta: {
|
|
15
78
|
type: 'problem',
|
|
@@ -20,16 +83,57 @@ export const rule = {
|
|
|
20
83
|
},
|
|
21
84
|
schema: [],
|
|
22
85
|
messages: {
|
|
23
|
-
later: "{{worklet}} captures '{{name}}' when it's defined, but '{{name}}'
|
|
24
|
-
self: "{{worklet}} captures '{{name}}' while '{{name}}' is still being set
|
|
25
|
-
usedAbove: "'{{name}}' is a worklet, which the Babel plugin turns into a const that's only set where it's declared, further down the file, so it'
|
|
86
|
+
later: "{{worklet}} captures '{{name}}' when it's defined, but '{{name}}' isn't set until further down the file. Move '{{name}}' above the worklet.",
|
|
87
|
+
self: "{{worklet}} captures '{{name}}' while '{{name}}' is still being set. Don't refer to '{{name}}' inside its own value.",
|
|
88
|
+
usedAbove: "'{{name}}' is a worklet, which the Babel plugin turns into a const that's only set where it's declared, further down the file, so it isn't set yet here. Move '{{name}}' above this line.",
|
|
26
89
|
},
|
|
27
90
|
},
|
|
28
91
|
create(context) {
|
|
29
92
|
const { sourceCode } = context;
|
|
30
93
|
const program = sourceCode.ast;
|
|
31
|
-
|
|
32
|
-
|
|
94
|
+
// Worklets without a directive of their own: a worklet file's functions, and the functions
|
|
95
|
+
// passed to the calls above, added as the calls are visited.
|
|
96
|
+
const workletized = workletFileFunctions(program);
|
|
97
|
+
const isWorklet = (node) => workletized.has(node) || directives(node).includes('worklet');
|
|
98
|
+
const functions = [];
|
|
99
|
+
function markCallbacks(call) {
|
|
100
|
+
const { callee } = call;
|
|
101
|
+
const name = callee.type === 'Identifier'
|
|
102
|
+
? callee.name
|
|
103
|
+
: callee.type === 'MemberExpression' && callee.property.type === 'Identifier'
|
|
104
|
+
? callee.property.name
|
|
105
|
+
: undefined;
|
|
106
|
+
// The plugin doesn't look at calls in an optional chain.
|
|
107
|
+
if (name === undefined || isOptional(call))
|
|
108
|
+
return;
|
|
109
|
+
const positions = WORKLET_ARGUMENTS.get(name);
|
|
110
|
+
const isGestureCallback = callee.type === 'MemberExpression' && GESTURE_CALLBACKS.has(name) && hasGesture(callee.object);
|
|
111
|
+
call.arguments.forEach((argument, index) => {
|
|
112
|
+
if (!positions?.includes(index) && !isGestureCallback)
|
|
113
|
+
return;
|
|
114
|
+
const worklet = functionPassed(argument);
|
|
115
|
+
if (worklet)
|
|
116
|
+
workletized.add(worklet);
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
/** The function an argument is, or the one its name stands for, as far as the plugin follows it. */
|
|
120
|
+
function functionPassed(argument) {
|
|
121
|
+
if (isFunctionExpression(argument))
|
|
122
|
+
return argument;
|
|
123
|
+
if (argument.type !== 'Identifier')
|
|
124
|
+
return undefined;
|
|
125
|
+
const variable = sourceCode.getScope(argument).references.find((r) => r.identifier === argument)?.resolved;
|
|
126
|
+
// TypeScript's overload signatures are erased; the plugin sees only the implementation.
|
|
127
|
+
const defs = variable?.defs.filter((d) => d.node.type !== 'TSDeclareFunction');
|
|
128
|
+
const def = defs?.length === 1 ? defs[0] : undefined;
|
|
129
|
+
if (def?.type === 'FunctionName' && def.node.type === 'FunctionDeclaration')
|
|
130
|
+
return def.node;
|
|
131
|
+
// A variable that keeps the function it starts with. The plugin also follows one that's
|
|
132
|
+
// assigned again, to its last assignment; that isn't followed here.
|
|
133
|
+
const init = def?.type === 'Variable' ? def.node.init : undefined;
|
|
134
|
+
const reassigned = variable?.references.some((r) => r.isWrite() && !r.init);
|
|
135
|
+
return init && isFunctionExpression(init) && !reassigned ? init : undefined;
|
|
136
|
+
}
|
|
33
137
|
function check(node) {
|
|
34
138
|
if (!isWorklet(node) || !runsAtLoad(node))
|
|
35
139
|
return;
|
|
@@ -49,7 +153,9 @@ export const rule = {
|
|
|
49
153
|
continue;
|
|
50
154
|
// JSX names aren't captured by the plugin outside its bundle mode.
|
|
51
155
|
const identifier = reference.identifier;
|
|
52
|
-
if (identifier.type === 'JSXIdentifier' || isInTypePosition(identifier, node))
|
|
156
|
+
if (identifier.type === 'JSXIdentifier' || isInTypePosition(identifier, node, TYPE_POSITIONS))
|
|
157
|
+
continue;
|
|
158
|
+
if (isAssignmentTarget(identifier))
|
|
53
159
|
continue;
|
|
54
160
|
const ready = readyAt(variable, isWorklet);
|
|
55
161
|
if (ready === undefined || ready <= start)
|
|
@@ -79,8 +185,9 @@ export const rule = {
|
|
|
79
185
|
if (range(node)[0] >= declared)
|
|
80
186
|
continue;
|
|
81
187
|
// An export list only links the binding; it doesn't read it.
|
|
82
|
-
if (node.parent?.type === 'ExportSpecifier' || isInTypePosition(node, program))
|
|
188
|
+
if (node.parent?.type === 'ExportSpecifier' || isInTypePosition(node, program, ERASED_OUTSIDE_WORKLETS)) {
|
|
83
189
|
continue;
|
|
190
|
+
}
|
|
84
191
|
if (!runsAtLoad(node))
|
|
85
192
|
continue;
|
|
86
193
|
context.report({ node, messageId: 'usedAbove', data: { name: variable.name } });
|
|
@@ -89,10 +196,15 @@ export const rule = {
|
|
|
89
196
|
}
|
|
90
197
|
}
|
|
91
198
|
return {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
199
|
+
CallExpression: markCallbacks,
|
|
200
|
+
':function'(node) {
|
|
201
|
+
functions.push(node);
|
|
202
|
+
},
|
|
203
|
+
// A call further down the file can make a function above it a worklet, so the checks wait.
|
|
204
|
+
'Program:exit'() {
|
|
205
|
+
functions.forEach(check);
|
|
206
|
+
checkUsesAbove();
|
|
207
|
+
},
|
|
96
208
|
};
|
|
97
209
|
},
|
|
98
210
|
};
|
|
@@ -107,6 +219,26 @@ function directives(node) {
|
|
|
107
219
|
}
|
|
108
220
|
return found;
|
|
109
221
|
}
|
|
222
|
+
function isFunctionExpression(node) {
|
|
223
|
+
return node.type === 'FunctionExpression' || node.type === 'ArrowFunctionExpression';
|
|
224
|
+
}
|
|
225
|
+
/** Part of an optional chain from its first `?.` on. */
|
|
226
|
+
function isOptional(node) {
|
|
227
|
+
if (node.type !== 'CallExpression' && node.type !== 'MemberExpression')
|
|
228
|
+
return false;
|
|
229
|
+
return node.optional || isOptional(node.type === 'CallExpression' ? node.callee : node.object);
|
|
230
|
+
}
|
|
231
|
+
/** A chain of method calls with `Gesture.Pan()`, or another gesture, somewhere along it. */
|
|
232
|
+
function hasGesture(node) {
|
|
233
|
+
if (node.type !== 'CallExpression' || node.callee.type !== 'MemberExpression')
|
|
234
|
+
return false;
|
|
235
|
+
const { object, property } = node.callee;
|
|
236
|
+
const isGesture = object.type === 'Identifier' &&
|
|
237
|
+
object.name === 'Gesture' &&
|
|
238
|
+
property.type === 'Identifier' &&
|
|
239
|
+
GESTURE_OBJECTS.has(property.name);
|
|
240
|
+
return isGesture || hasGesture(object);
|
|
241
|
+
}
|
|
110
242
|
/**
|
|
111
243
|
* In a file whose prologue has 'worklet', the plugin workletizes every top-level function, exported
|
|
112
244
|
* or not, every function a top-level variable is initialized with, and the methods and function
|
|
@@ -174,9 +306,12 @@ function isModuleVariable(variable) {
|
|
|
174
306
|
function readyAt(variable, isWorklet) {
|
|
175
307
|
let ready;
|
|
176
308
|
for (const def of variable.defs) {
|
|
177
|
-
// Imports are set before any code runs
|
|
178
|
-
if (def.type === 'ImportBinding'
|
|
309
|
+
// Imports are set before any code runs.
|
|
310
|
+
if (def.type === 'ImportBinding')
|
|
179
311
|
return undefined;
|
|
312
|
+
// Ambient declarations are erased, which leaves any real declaration of the same name to count.
|
|
313
|
+
if (isAmbient(def))
|
|
314
|
+
continue;
|
|
180
315
|
// A function declaration is hoisted with its value, unless it's a worklet: the Babel plugin
|
|
181
316
|
// turns those into `const name = factory(...)`, which isn't set until that line runs.
|
|
182
317
|
if (def.type === 'FunctionName' && def.node.type === 'FunctionDeclaration' && !isWorklet(def.node)) {
|
|
@@ -190,11 +325,35 @@ function readyAt(variable, isWorklet) {
|
|
|
190
325
|
}
|
|
191
326
|
/** `declare const`, `declare function` and the rest: types only, gone at run time. */
|
|
192
327
|
function isAmbient(def) {
|
|
328
|
+
// Flow has a node type for each, such as DeclareVariable.
|
|
329
|
+
if (def.node.type.startsWith('Declare'))
|
|
330
|
+
return true;
|
|
193
331
|
return Boolean(def.node.declare || def.parent?.declare);
|
|
194
332
|
}
|
|
195
|
-
|
|
333
|
+
/**
|
|
334
|
+
* Written to, not read, the way Babel's `isReferenced` sees it, which is what the plugin captures
|
|
335
|
+
* by: the left of `=` or `+=`, and destructuring targets. A plain `for (x of ...)` target and
|
|
336
|
+
* `x++` count as reads.
|
|
337
|
+
*/
|
|
338
|
+
function isAssignmentTarget(identifier) {
|
|
339
|
+
// Every identifier in a `through` list has a parent.
|
|
340
|
+
const parent = identifier.parent;
|
|
341
|
+
switch (parent.type) {
|
|
342
|
+
case 'AssignmentExpression':
|
|
343
|
+
case 'AssignmentPattern':
|
|
344
|
+
return parent.left === identifier;
|
|
345
|
+
case 'ArrayPattern':
|
|
346
|
+
case 'RestElement':
|
|
347
|
+
return true;
|
|
348
|
+
case 'Property':
|
|
349
|
+
return parent.value === identifier && parent.parent.type === 'ObjectPattern';
|
|
350
|
+
default:
|
|
351
|
+
return false;
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
function isInTypePosition(identifier, until, positions) {
|
|
196
355
|
for (let node = identifier.parent; node && node !== until; node = node.parent) {
|
|
197
|
-
if (
|
|
356
|
+
if (positions.has(node.type))
|
|
198
357
|
return true;
|
|
199
358
|
}
|
|
200
359
|
return false;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@itin-labs/eslint-plugin-worklet-order",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "ESLint rule that catches React Native worklets which capture a variable before it is set, the mistake that crashes on the UI thread.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"eslint",
|
|
@@ -45,25 +45,23 @@
|
|
|
45
45
|
"typecheck": "tsc",
|
|
46
46
|
"lint": "eslint . && prettier --check .",
|
|
47
47
|
"format": "prettier --write .",
|
|
48
|
-
"check:package": "publint --strict
|
|
48
|
+
"check:package": "publint --strict",
|
|
49
49
|
"changeset": "changeset",
|
|
50
50
|
"version-packages": "changeset version && npm install --package-lock-only",
|
|
51
|
-
"release": "npm test && npm run build && npm run check:package &&
|
|
51
|
+
"release": "npm test && npm run build && npm run check:package && npm stage publish"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
|
-
"@arethetypeswrong/cli": "^0.18.5",
|
|
55
54
|
"@changesets/cli": "^3.0.3",
|
|
56
55
|
"@eslint/js": "^10.0.1",
|
|
57
|
-
"@size-limit/file": "^14.3.0",
|
|
58
56
|
"@types/estree": "^1.0.11",
|
|
59
57
|
"@types/node": "^24.19.2",
|
|
60
58
|
"eslint": "^10.15.0",
|
|
61
59
|
"eslint-config-prettier": "^10.1.8",
|
|
62
60
|
"expect-type": "^1.4.0",
|
|
63
61
|
"fast-check": "^4.11.0",
|
|
62
|
+
"hermes-eslint": "^0.37.0",
|
|
64
63
|
"prettier": "^3.10.1",
|
|
65
64
|
"publint": "^0.3.25",
|
|
66
|
-
"size-limit": "^14.3.0",
|
|
67
65
|
"typescript": "^6.0.3",
|
|
68
66
|
"typescript-eslint": "^8.74.0"
|
|
69
67
|
}
|