eslint-plugin-react-hooks-extra 1.24.0-beta.0 → 1.24.0-beta.3
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/dist/index.js +37 -73
- package/dist/index.mjs +38 -74
- package/package.json +10 -10
package/dist/index.js
CHANGED
|
@@ -31,7 +31,7 @@ var VAR5__namespace = /*#__PURE__*/_interopNamespace(VAR5);
|
|
|
31
31
|
|
|
32
32
|
// package.json
|
|
33
33
|
var name = "eslint-plugin-react-hooks-extra";
|
|
34
|
-
var version = "1.24.0-beta.
|
|
34
|
+
var version = "1.24.0-beta.3";
|
|
35
35
|
var createRule = shared.createRuleForPlugin("hooks-extra");
|
|
36
36
|
function isFromHookCall(name2, context, settings, predicate = eff.returnTrue) {
|
|
37
37
|
const hookAlias = settings.additionalHooks?.[name2] ?? [];
|
|
@@ -164,10 +164,10 @@ var no_direct_set_state_in_use_effect_default = createRule({
|
|
|
164
164
|
const setupFunctionRef = { current: null };
|
|
165
165
|
const setupFunctionIdentifiers = [];
|
|
166
166
|
const indFunctionCalls = [];
|
|
167
|
-
const indSetStateCalls = /* @__PURE__ */ new
|
|
168
|
-
const indSetStateCallsInUseEffectArg0 = /* @__PURE__ */ new
|
|
167
|
+
const indSetStateCalls = /* @__PURE__ */ new Map();
|
|
168
|
+
const indSetStateCallsInUseEffectArg0 = /* @__PURE__ */ new Map();
|
|
169
169
|
const indSetStateCallsInUseEffectSetup = /* @__PURE__ */ new Map();
|
|
170
|
-
const indSetStateCallsInUseMemoOrCallback = /* @__PURE__ */ new
|
|
170
|
+
const indSetStateCallsInUseMemoOrCallback = /* @__PURE__ */ new Map();
|
|
171
171
|
const onSetupFunctionEnter = (node) => {
|
|
172
172
|
setupFunctionRef.current = node;
|
|
173
173
|
};
|
|
@@ -203,13 +203,10 @@ var no_direct_set_state_in_use_effect_default = createRule({
|
|
|
203
203
|
CallExpression(node) {
|
|
204
204
|
const setupFunction = setupFunctionRef.current;
|
|
205
205
|
const pEntry = functionEntries.at(-1);
|
|
206
|
-
if (pEntry
|
|
206
|
+
if (pEntry == null || pEntry.node.async) {
|
|
207
207
|
return;
|
|
208
208
|
}
|
|
209
209
|
tsPattern.match(getCallKind(node)).with("setState", () => {
|
|
210
|
-
if (pEntry == null) {
|
|
211
|
-
return;
|
|
212
|
-
}
|
|
213
210
|
switch (true) {
|
|
214
211
|
case (pEntry.node === setupFunction || pEntry.kind === "immediate"): {
|
|
215
212
|
context.report({
|
|
@@ -222,26 +219,16 @@ var no_direct_set_state_in_use_effect_default = createRule({
|
|
|
222
219
|
return;
|
|
223
220
|
}
|
|
224
221
|
default: {
|
|
225
|
-
const
|
|
226
|
-
if (
|
|
227
|
-
|
|
228
|
-
indSetStateCalls.set(pEntry.node, [...calls, node]);
|
|
229
|
-
return;
|
|
230
|
-
}
|
|
231
|
-
const init = variableDeclarator.init;
|
|
232
|
-
const prevs = indSetStateCallsInUseMemoOrCallback.get(init) ?? [];
|
|
233
|
-
indSetStateCallsInUseMemoOrCallback.set(init, [...prevs, node]);
|
|
222
|
+
const vd = AST__namespace.findParentNode(node, isVariableDeclaratorFromHookCall);
|
|
223
|
+
if (vd == null) eff.getOrUpdate(indSetStateCalls, pEntry.node, () => []).push(node);
|
|
224
|
+
else eff.getOrUpdate(indSetStateCallsInUseMemoOrCallback, vd.init, () => []).push(node);
|
|
234
225
|
}
|
|
235
226
|
}
|
|
236
227
|
}).with("useEffect", () => {
|
|
237
|
-
if (AST__namespace.isFunction(node.arguments.at(0)))
|
|
238
|
-
return;
|
|
239
|
-
}
|
|
228
|
+
if (AST__namespace.isFunction(node.arguments.at(0))) return;
|
|
240
229
|
setupFunctionIdentifiers.push(...AST__namespace.getNestedIdentifiers(node));
|
|
241
230
|
}).with("other", () => {
|
|
242
|
-
if (pEntry
|
|
243
|
-
return;
|
|
244
|
-
}
|
|
231
|
+
if (pEntry.node !== setupFunction) return;
|
|
245
232
|
indFunctionCalls.push(node);
|
|
246
233
|
}).otherwise(() => eff._);
|
|
247
234
|
},
|
|
@@ -261,12 +248,10 @@ var no_direct_set_state_in_use_effect_default = createRule({
|
|
|
261
248
|
if (!isUseMemoCall2(parent)) {
|
|
262
249
|
break;
|
|
263
250
|
}
|
|
264
|
-
const
|
|
265
|
-
if (
|
|
266
|
-
|
|
251
|
+
const vd = AST__namespace.findParentNode(parent, isVariableDeclaratorFromHookCall);
|
|
252
|
+
if (vd != null) {
|
|
253
|
+
eff.getOrUpdate(indSetStateCallsInUseEffectArg0, vd.init, () => []).push(node);
|
|
267
254
|
}
|
|
268
|
-
const calls = indSetStateCallsInUseEffectArg0.get(variableDeclarator.init) ?? [];
|
|
269
|
-
indSetStateCallsInUseEffectArg0.set(variableDeclarator.init, [...calls, node]);
|
|
270
255
|
break;
|
|
271
256
|
}
|
|
272
257
|
case types.AST_NODE_TYPES.CallExpression: {
|
|
@@ -274,18 +259,15 @@ var no_direct_set_state_in_use_effect_default = createRule({
|
|
|
274
259
|
break;
|
|
275
260
|
}
|
|
276
261
|
if (isUseCallbackCall2(node.parent)) {
|
|
277
|
-
const
|
|
278
|
-
if (
|
|
279
|
-
|
|
262
|
+
const vd = AST__namespace.findParentNode(node.parent, isVariableDeclaratorFromHookCall);
|
|
263
|
+
if (vd != null) {
|
|
264
|
+
eff.getOrUpdate(indSetStateCallsInUseEffectArg0, vd.init, () => []).push(node);
|
|
280
265
|
}
|
|
281
|
-
|
|
282
|
-
indSetStateCallsInUseEffectArg0.set(variableDeclarator.init, [...prevs, node]);
|
|
266
|
+
break;
|
|
283
267
|
}
|
|
284
268
|
if (isUseEffectLikeCall(node.parent)) {
|
|
285
|
-
|
|
286
|
-
indSetStateCallsInUseEffectSetup.set(node.parent, [...prevs, node]);
|
|
269
|
+
eff.getOrUpdate(indSetStateCallsInUseEffectSetup, node.parent, () => []).push(node);
|
|
287
270
|
}
|
|
288
|
-
break;
|
|
289
271
|
}
|
|
290
272
|
}
|
|
291
273
|
},
|
|
@@ -381,10 +363,10 @@ var no_direct_set_state_in_use_layout_effect_default = createRule({
|
|
|
381
363
|
const setupFunctionRef = { current: null };
|
|
382
364
|
const setupFunctionIdentifiers = [];
|
|
383
365
|
const indFunctionCalls = [];
|
|
384
|
-
const indSetStateCalls = /* @__PURE__ */ new
|
|
385
|
-
const indSetStateCallsInUseLayoutEffectArg0 = /* @__PURE__ */ new
|
|
366
|
+
const indSetStateCalls = /* @__PURE__ */ new Map();
|
|
367
|
+
const indSetStateCallsInUseLayoutEffectArg0 = /* @__PURE__ */ new Map();
|
|
386
368
|
const indSetStateCallsInUseLayoutEffectSetup = /* @__PURE__ */ new Map();
|
|
387
|
-
const indSetStateCallsInUseMemoOrCallback = /* @__PURE__ */ new
|
|
369
|
+
const indSetStateCallsInUseMemoOrCallback = /* @__PURE__ */ new Map();
|
|
388
370
|
const onSetupFunctionEnter = (node) => {
|
|
389
371
|
setupFunctionRef.current = node;
|
|
390
372
|
};
|
|
@@ -420,13 +402,10 @@ var no_direct_set_state_in_use_layout_effect_default = createRule({
|
|
|
420
402
|
CallExpression(node) {
|
|
421
403
|
const setupFunction = setupFunctionRef.current;
|
|
422
404
|
const pEntry = functionEntries.at(-1);
|
|
423
|
-
if (pEntry
|
|
405
|
+
if (pEntry == null || pEntry.node.async) {
|
|
424
406
|
return;
|
|
425
407
|
}
|
|
426
408
|
tsPattern.match(getCallKind(node)).with("setState", () => {
|
|
427
|
-
if (pEntry == null) {
|
|
428
|
-
return;
|
|
429
|
-
}
|
|
430
409
|
switch (true) {
|
|
431
410
|
case (pEntry.node === setupFunction || pEntry.kind === "immediate"): {
|
|
432
411
|
context.report({
|
|
@@ -439,26 +418,16 @@ var no_direct_set_state_in_use_layout_effect_default = createRule({
|
|
|
439
418
|
return;
|
|
440
419
|
}
|
|
441
420
|
default: {
|
|
442
|
-
const
|
|
443
|
-
if (
|
|
444
|
-
|
|
445
|
-
indSetStateCalls.set(pEntry.node, [...calls, node]);
|
|
446
|
-
return;
|
|
447
|
-
}
|
|
448
|
-
const init = variableDeclarator.init;
|
|
449
|
-
const prevs = indSetStateCallsInUseMemoOrCallback.get(init) ?? [];
|
|
450
|
-
indSetStateCallsInUseMemoOrCallback.set(init, [...prevs, node]);
|
|
421
|
+
const vd = AST__namespace.findParentNode(node, isVariableDeclaratorFromHookCall);
|
|
422
|
+
if (vd == null) eff.getOrUpdate(indSetStateCalls, pEntry.node, () => []).push(node);
|
|
423
|
+
else eff.getOrUpdate(indSetStateCallsInUseMemoOrCallback, vd.init, () => []).push(node);
|
|
451
424
|
}
|
|
452
425
|
}
|
|
453
426
|
}).with("useLayoutEffect", () => {
|
|
454
|
-
if (AST__namespace.isFunction(node.arguments.at(0)))
|
|
455
|
-
return;
|
|
456
|
-
}
|
|
427
|
+
if (AST__namespace.isFunction(node.arguments.at(0))) return;
|
|
457
428
|
setupFunctionIdentifiers.push(...AST__namespace.getNestedIdentifiers(node));
|
|
458
429
|
}).with("other", () => {
|
|
459
|
-
if (pEntry
|
|
460
|
-
return;
|
|
461
|
-
}
|
|
430
|
+
if (pEntry.node !== setupFunction) return;
|
|
462
431
|
indFunctionCalls.push(node);
|
|
463
432
|
}).otherwise(() => eff._);
|
|
464
433
|
},
|
|
@@ -478,12 +447,10 @@ var no_direct_set_state_in_use_layout_effect_default = createRule({
|
|
|
478
447
|
if (!isUseMemoCall2(parent)) {
|
|
479
448
|
break;
|
|
480
449
|
}
|
|
481
|
-
const
|
|
482
|
-
if (
|
|
483
|
-
|
|
450
|
+
const vd = AST__namespace.findParentNode(parent, isVariableDeclaratorFromHookCall);
|
|
451
|
+
if (vd != null) {
|
|
452
|
+
eff.getOrUpdate(indSetStateCallsInUseLayoutEffectArg0, vd.init, () => []).push(node);
|
|
484
453
|
}
|
|
485
|
-
const calls = indSetStateCallsInUseLayoutEffectArg0.get(variableDeclarator.init) ?? [];
|
|
486
|
-
indSetStateCallsInUseLayoutEffectArg0.set(variableDeclarator.init, [...calls, node]);
|
|
487
454
|
break;
|
|
488
455
|
}
|
|
489
456
|
case types.AST_NODE_TYPES.CallExpression: {
|
|
@@ -491,18 +458,15 @@ var no_direct_set_state_in_use_layout_effect_default = createRule({
|
|
|
491
458
|
break;
|
|
492
459
|
}
|
|
493
460
|
if (isUseCallbackCall2(node.parent)) {
|
|
494
|
-
const
|
|
495
|
-
if (
|
|
496
|
-
|
|
461
|
+
const vd = AST__namespace.findParentNode(node.parent, isVariableDeclaratorFromHookCall);
|
|
462
|
+
if (vd != null) {
|
|
463
|
+
eff.getOrUpdate(indSetStateCallsInUseLayoutEffectArg0, vd.init, () => []).push(node);
|
|
497
464
|
}
|
|
498
|
-
|
|
499
|
-
indSetStateCallsInUseLayoutEffectArg0.set(variableDeclarator.init, [...prevs, node]);
|
|
465
|
+
break;
|
|
500
466
|
}
|
|
501
467
|
if (isUseLayoutEffectLikeCall(node.parent)) {
|
|
502
|
-
|
|
503
|
-
indSetStateCallsInUseLayoutEffectSetup.set(node.parent, [...prevs, node]);
|
|
468
|
+
eff.getOrUpdate(indSetStateCallsInUseLayoutEffectSetup, node.parent, () => []).push(node);
|
|
504
469
|
}
|
|
505
|
-
break;
|
|
506
470
|
}
|
|
507
471
|
}
|
|
508
472
|
},
|
|
@@ -625,7 +589,7 @@ var no_unnecessary_use_callback_default = createRule({
|
|
|
625
589
|
}
|
|
626
590
|
return variableNode;
|
|
627
591
|
}).otherwise(() => eff._);
|
|
628
|
-
if (arg0Node
|
|
592
|
+
if (arg0Node == null) return;
|
|
629
593
|
const arg0NodeScope = context.sourceCode.getScope(arg0Node);
|
|
630
594
|
const arg0NodeReferences = VAR5__namespace.getChidScopes(arg0NodeScope).flatMap((x) => x.references);
|
|
631
595
|
const isReferencedToComponentScope = arg0NodeReferences.some((x) => x.resolved?.scope.block === component);
|
|
@@ -708,7 +672,7 @@ var no_unnecessary_use_memo_default = createRule({
|
|
|
708
672
|
}
|
|
709
673
|
return variableNode;
|
|
710
674
|
}).otherwise(() => eff._);
|
|
711
|
-
if (arg0Node
|
|
675
|
+
if (arg0Node == null) return;
|
|
712
676
|
const arg0NodeScope = context.sourceCode.getScope(arg0Node);
|
|
713
677
|
const arg0NodeReferences = VAR5__namespace.getChidScopes(arg0NodeScope).flatMap((x) => x.references);
|
|
714
678
|
const isReferencedToComponentScope = arg0NodeReferences.some((x) => x.resolved?.scope.block === component);
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as AST from '@eslint-react/ast';
|
|
2
2
|
import { isReactHookCallWithNameAlias, isReactHookCall, isUseCallbackCall, isReactHookCallWithNameLoose, isUseMemoCall, useHookCollector, isUseStateCall, isReactHookName } from '@eslint-react/core';
|
|
3
|
-
import { _, identity, returnTrue } from '@eslint-react/eff';
|
|
3
|
+
import { getOrUpdate, _, identity, returnTrue } from '@eslint-react/eff';
|
|
4
4
|
import { createRuleForPlugin, getSettingsFromContext } from '@eslint-react/shared';
|
|
5
5
|
import * as VAR5 from '@eslint-react/var';
|
|
6
6
|
import { AST_NODE_TYPES } from '@typescript-eslint/types';
|
|
@@ -8,7 +8,7 @@ import { match } from 'ts-pattern';
|
|
|
8
8
|
|
|
9
9
|
// package.json
|
|
10
10
|
var name = "eslint-plugin-react-hooks-extra";
|
|
11
|
-
var version = "1.24.0-beta.
|
|
11
|
+
var version = "1.24.0-beta.3";
|
|
12
12
|
var createRule = createRuleForPlugin("hooks-extra");
|
|
13
13
|
function isFromHookCall(name2, context, settings, predicate = returnTrue) {
|
|
14
14
|
const hookAlias = settings.additionalHooks?.[name2] ?? [];
|
|
@@ -141,10 +141,10 @@ var no_direct_set_state_in_use_effect_default = createRule({
|
|
|
141
141
|
const setupFunctionRef = { current: null };
|
|
142
142
|
const setupFunctionIdentifiers = [];
|
|
143
143
|
const indFunctionCalls = [];
|
|
144
|
-
const indSetStateCalls = /* @__PURE__ */ new
|
|
145
|
-
const indSetStateCallsInUseEffectArg0 = /* @__PURE__ */ new
|
|
144
|
+
const indSetStateCalls = /* @__PURE__ */ new Map();
|
|
145
|
+
const indSetStateCallsInUseEffectArg0 = /* @__PURE__ */ new Map();
|
|
146
146
|
const indSetStateCallsInUseEffectSetup = /* @__PURE__ */ new Map();
|
|
147
|
-
const indSetStateCallsInUseMemoOrCallback = /* @__PURE__ */ new
|
|
147
|
+
const indSetStateCallsInUseMemoOrCallback = /* @__PURE__ */ new Map();
|
|
148
148
|
const onSetupFunctionEnter = (node) => {
|
|
149
149
|
setupFunctionRef.current = node;
|
|
150
150
|
};
|
|
@@ -180,13 +180,10 @@ var no_direct_set_state_in_use_effect_default = createRule({
|
|
|
180
180
|
CallExpression(node) {
|
|
181
181
|
const setupFunction = setupFunctionRef.current;
|
|
182
182
|
const pEntry = functionEntries.at(-1);
|
|
183
|
-
if (pEntry
|
|
183
|
+
if (pEntry == null || pEntry.node.async) {
|
|
184
184
|
return;
|
|
185
185
|
}
|
|
186
186
|
match(getCallKind(node)).with("setState", () => {
|
|
187
|
-
if (pEntry == null) {
|
|
188
|
-
return;
|
|
189
|
-
}
|
|
190
187
|
switch (true) {
|
|
191
188
|
case (pEntry.node === setupFunction || pEntry.kind === "immediate"): {
|
|
192
189
|
context.report({
|
|
@@ -199,26 +196,16 @@ var no_direct_set_state_in_use_effect_default = createRule({
|
|
|
199
196
|
return;
|
|
200
197
|
}
|
|
201
198
|
default: {
|
|
202
|
-
const
|
|
203
|
-
if (
|
|
204
|
-
|
|
205
|
-
indSetStateCalls.set(pEntry.node, [...calls, node]);
|
|
206
|
-
return;
|
|
207
|
-
}
|
|
208
|
-
const init = variableDeclarator.init;
|
|
209
|
-
const prevs = indSetStateCallsInUseMemoOrCallback.get(init) ?? [];
|
|
210
|
-
indSetStateCallsInUseMemoOrCallback.set(init, [...prevs, node]);
|
|
199
|
+
const vd = AST.findParentNode(node, isVariableDeclaratorFromHookCall);
|
|
200
|
+
if (vd == null) getOrUpdate(indSetStateCalls, pEntry.node, () => []).push(node);
|
|
201
|
+
else getOrUpdate(indSetStateCallsInUseMemoOrCallback, vd.init, () => []).push(node);
|
|
211
202
|
}
|
|
212
203
|
}
|
|
213
204
|
}).with("useEffect", () => {
|
|
214
|
-
if (AST.isFunction(node.arguments.at(0)))
|
|
215
|
-
return;
|
|
216
|
-
}
|
|
205
|
+
if (AST.isFunction(node.arguments.at(0))) return;
|
|
217
206
|
setupFunctionIdentifiers.push(...AST.getNestedIdentifiers(node));
|
|
218
207
|
}).with("other", () => {
|
|
219
|
-
if (pEntry
|
|
220
|
-
return;
|
|
221
|
-
}
|
|
208
|
+
if (pEntry.node !== setupFunction) return;
|
|
222
209
|
indFunctionCalls.push(node);
|
|
223
210
|
}).otherwise(() => _);
|
|
224
211
|
},
|
|
@@ -238,12 +225,10 @@ var no_direct_set_state_in_use_effect_default = createRule({
|
|
|
238
225
|
if (!isUseMemoCall2(parent)) {
|
|
239
226
|
break;
|
|
240
227
|
}
|
|
241
|
-
const
|
|
242
|
-
if (
|
|
243
|
-
|
|
228
|
+
const vd = AST.findParentNode(parent, isVariableDeclaratorFromHookCall);
|
|
229
|
+
if (vd != null) {
|
|
230
|
+
getOrUpdate(indSetStateCallsInUseEffectArg0, vd.init, () => []).push(node);
|
|
244
231
|
}
|
|
245
|
-
const calls = indSetStateCallsInUseEffectArg0.get(variableDeclarator.init) ?? [];
|
|
246
|
-
indSetStateCallsInUseEffectArg0.set(variableDeclarator.init, [...calls, node]);
|
|
247
232
|
break;
|
|
248
233
|
}
|
|
249
234
|
case AST_NODE_TYPES.CallExpression: {
|
|
@@ -251,18 +236,15 @@ var no_direct_set_state_in_use_effect_default = createRule({
|
|
|
251
236
|
break;
|
|
252
237
|
}
|
|
253
238
|
if (isUseCallbackCall2(node.parent)) {
|
|
254
|
-
const
|
|
255
|
-
if (
|
|
256
|
-
|
|
239
|
+
const vd = AST.findParentNode(node.parent, isVariableDeclaratorFromHookCall);
|
|
240
|
+
if (vd != null) {
|
|
241
|
+
getOrUpdate(indSetStateCallsInUseEffectArg0, vd.init, () => []).push(node);
|
|
257
242
|
}
|
|
258
|
-
|
|
259
|
-
indSetStateCallsInUseEffectArg0.set(variableDeclarator.init, [...prevs, node]);
|
|
243
|
+
break;
|
|
260
244
|
}
|
|
261
245
|
if (isUseEffectLikeCall(node.parent)) {
|
|
262
|
-
|
|
263
|
-
indSetStateCallsInUseEffectSetup.set(node.parent, [...prevs, node]);
|
|
246
|
+
getOrUpdate(indSetStateCallsInUseEffectSetup, node.parent, () => []).push(node);
|
|
264
247
|
}
|
|
265
|
-
break;
|
|
266
248
|
}
|
|
267
249
|
}
|
|
268
250
|
},
|
|
@@ -358,10 +340,10 @@ var no_direct_set_state_in_use_layout_effect_default = createRule({
|
|
|
358
340
|
const setupFunctionRef = { current: null };
|
|
359
341
|
const setupFunctionIdentifiers = [];
|
|
360
342
|
const indFunctionCalls = [];
|
|
361
|
-
const indSetStateCalls = /* @__PURE__ */ new
|
|
362
|
-
const indSetStateCallsInUseLayoutEffectArg0 = /* @__PURE__ */ new
|
|
343
|
+
const indSetStateCalls = /* @__PURE__ */ new Map();
|
|
344
|
+
const indSetStateCallsInUseLayoutEffectArg0 = /* @__PURE__ */ new Map();
|
|
363
345
|
const indSetStateCallsInUseLayoutEffectSetup = /* @__PURE__ */ new Map();
|
|
364
|
-
const indSetStateCallsInUseMemoOrCallback = /* @__PURE__ */ new
|
|
346
|
+
const indSetStateCallsInUseMemoOrCallback = /* @__PURE__ */ new Map();
|
|
365
347
|
const onSetupFunctionEnter = (node) => {
|
|
366
348
|
setupFunctionRef.current = node;
|
|
367
349
|
};
|
|
@@ -397,13 +379,10 @@ var no_direct_set_state_in_use_layout_effect_default = createRule({
|
|
|
397
379
|
CallExpression(node) {
|
|
398
380
|
const setupFunction = setupFunctionRef.current;
|
|
399
381
|
const pEntry = functionEntries.at(-1);
|
|
400
|
-
if (pEntry
|
|
382
|
+
if (pEntry == null || pEntry.node.async) {
|
|
401
383
|
return;
|
|
402
384
|
}
|
|
403
385
|
match(getCallKind(node)).with("setState", () => {
|
|
404
|
-
if (pEntry == null) {
|
|
405
|
-
return;
|
|
406
|
-
}
|
|
407
386
|
switch (true) {
|
|
408
387
|
case (pEntry.node === setupFunction || pEntry.kind === "immediate"): {
|
|
409
388
|
context.report({
|
|
@@ -416,26 +395,16 @@ var no_direct_set_state_in_use_layout_effect_default = createRule({
|
|
|
416
395
|
return;
|
|
417
396
|
}
|
|
418
397
|
default: {
|
|
419
|
-
const
|
|
420
|
-
if (
|
|
421
|
-
|
|
422
|
-
indSetStateCalls.set(pEntry.node, [...calls, node]);
|
|
423
|
-
return;
|
|
424
|
-
}
|
|
425
|
-
const init = variableDeclarator.init;
|
|
426
|
-
const prevs = indSetStateCallsInUseMemoOrCallback.get(init) ?? [];
|
|
427
|
-
indSetStateCallsInUseMemoOrCallback.set(init, [...prevs, node]);
|
|
398
|
+
const vd = AST.findParentNode(node, isVariableDeclaratorFromHookCall);
|
|
399
|
+
if (vd == null) getOrUpdate(indSetStateCalls, pEntry.node, () => []).push(node);
|
|
400
|
+
else getOrUpdate(indSetStateCallsInUseMemoOrCallback, vd.init, () => []).push(node);
|
|
428
401
|
}
|
|
429
402
|
}
|
|
430
403
|
}).with("useLayoutEffect", () => {
|
|
431
|
-
if (AST.isFunction(node.arguments.at(0)))
|
|
432
|
-
return;
|
|
433
|
-
}
|
|
404
|
+
if (AST.isFunction(node.arguments.at(0))) return;
|
|
434
405
|
setupFunctionIdentifiers.push(...AST.getNestedIdentifiers(node));
|
|
435
406
|
}).with("other", () => {
|
|
436
|
-
if (pEntry
|
|
437
|
-
return;
|
|
438
|
-
}
|
|
407
|
+
if (pEntry.node !== setupFunction) return;
|
|
439
408
|
indFunctionCalls.push(node);
|
|
440
409
|
}).otherwise(() => _);
|
|
441
410
|
},
|
|
@@ -455,12 +424,10 @@ var no_direct_set_state_in_use_layout_effect_default = createRule({
|
|
|
455
424
|
if (!isUseMemoCall2(parent)) {
|
|
456
425
|
break;
|
|
457
426
|
}
|
|
458
|
-
const
|
|
459
|
-
if (
|
|
460
|
-
|
|
427
|
+
const vd = AST.findParentNode(parent, isVariableDeclaratorFromHookCall);
|
|
428
|
+
if (vd != null) {
|
|
429
|
+
getOrUpdate(indSetStateCallsInUseLayoutEffectArg0, vd.init, () => []).push(node);
|
|
461
430
|
}
|
|
462
|
-
const calls = indSetStateCallsInUseLayoutEffectArg0.get(variableDeclarator.init) ?? [];
|
|
463
|
-
indSetStateCallsInUseLayoutEffectArg0.set(variableDeclarator.init, [...calls, node]);
|
|
464
431
|
break;
|
|
465
432
|
}
|
|
466
433
|
case AST_NODE_TYPES.CallExpression: {
|
|
@@ -468,18 +435,15 @@ var no_direct_set_state_in_use_layout_effect_default = createRule({
|
|
|
468
435
|
break;
|
|
469
436
|
}
|
|
470
437
|
if (isUseCallbackCall2(node.parent)) {
|
|
471
|
-
const
|
|
472
|
-
if (
|
|
473
|
-
|
|
438
|
+
const vd = AST.findParentNode(node.parent, isVariableDeclaratorFromHookCall);
|
|
439
|
+
if (vd != null) {
|
|
440
|
+
getOrUpdate(indSetStateCallsInUseLayoutEffectArg0, vd.init, () => []).push(node);
|
|
474
441
|
}
|
|
475
|
-
|
|
476
|
-
indSetStateCallsInUseLayoutEffectArg0.set(variableDeclarator.init, [...prevs, node]);
|
|
442
|
+
break;
|
|
477
443
|
}
|
|
478
444
|
if (isUseLayoutEffectLikeCall(node.parent)) {
|
|
479
|
-
|
|
480
|
-
indSetStateCallsInUseLayoutEffectSetup.set(node.parent, [...prevs, node]);
|
|
445
|
+
getOrUpdate(indSetStateCallsInUseLayoutEffectSetup, node.parent, () => []).push(node);
|
|
481
446
|
}
|
|
482
|
-
break;
|
|
483
447
|
}
|
|
484
448
|
}
|
|
485
449
|
},
|
|
@@ -602,7 +566,7 @@ var no_unnecessary_use_callback_default = createRule({
|
|
|
602
566
|
}
|
|
603
567
|
return variableNode;
|
|
604
568
|
}).otherwise(() => _);
|
|
605
|
-
if (arg0Node
|
|
569
|
+
if (arg0Node == null) return;
|
|
606
570
|
const arg0NodeScope = context.sourceCode.getScope(arg0Node);
|
|
607
571
|
const arg0NodeReferences = VAR5.getChidScopes(arg0NodeScope).flatMap((x) => x.references);
|
|
608
572
|
const isReferencedToComponentScope = arg0NodeReferences.some((x) => x.resolved?.scope.block === component);
|
|
@@ -685,7 +649,7 @@ var no_unnecessary_use_memo_default = createRule({
|
|
|
685
649
|
}
|
|
686
650
|
return variableNode;
|
|
687
651
|
}).otherwise(() => _);
|
|
688
|
-
if (arg0Node
|
|
652
|
+
if (arg0Node == null) return;
|
|
689
653
|
const arg0NodeScope = context.sourceCode.getScope(arg0Node);
|
|
690
654
|
const arg0NodeReferences = VAR5.getChidScopes(arg0NodeScope).flatMap((x) => x.references);
|
|
691
655
|
const isReferencedToComponentScope = arg0NodeReferences.some((x) => x.resolved?.scope.block === component);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-react-hooks-extra",
|
|
3
|
-
"version": "1.24.0-beta.
|
|
3
|
+
"version": "1.24.0-beta.3",
|
|
4
4
|
"description": "ESLint React's ESLint plugin for React Hooks related rules.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -48,17 +48,17 @@
|
|
|
48
48
|
"@typescript-eslint/utils": "^8.19.1",
|
|
49
49
|
"string-ts": "^2.2.0",
|
|
50
50
|
"ts-pattern": "^5.6.0",
|
|
51
|
-
"@eslint-react/ast": "1.24.0-beta.
|
|
52
|
-
"@eslint-react/core": "1.24.0-beta.
|
|
53
|
-
"@eslint-react/
|
|
54
|
-
"@eslint-react/
|
|
55
|
-
"@eslint-react/
|
|
56
|
-
"@eslint-react/
|
|
57
|
-
"@eslint-react/
|
|
51
|
+
"@eslint-react/ast": "1.24.0-beta.3",
|
|
52
|
+
"@eslint-react/core": "1.24.0-beta.3",
|
|
53
|
+
"@eslint-react/shared": "1.24.0-beta.3",
|
|
54
|
+
"@eslint-react/eff": "1.24.0-beta.3",
|
|
55
|
+
"@eslint-react/types": "1.24.0-beta.3",
|
|
56
|
+
"@eslint-react/var": "1.24.0-beta.3",
|
|
57
|
+
"@eslint-react/jsx": "1.24.0-beta.3"
|
|
58
58
|
},
|
|
59
59
|
"devDependencies": {
|
|
60
|
-
"@types/react": "^19.0.
|
|
61
|
-
"@types/react-dom": "^19.0.
|
|
60
|
+
"@types/react": "^19.0.6",
|
|
61
|
+
"@types/react-dom": "^19.0.3",
|
|
62
62
|
"tsup": "^8.3.5",
|
|
63
63
|
"@workspace/configs": "0.0.0"
|
|
64
64
|
},
|