eslint-plugin-react-hooks-extra 1.24.0-beta.1 → 1.24.0-beta.18

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.
Files changed (3) hide show
  1. package/dist/index.js +45 -75
  2. package/dist/index.mjs +46 -76
  3. package/package.json +13 -14
package/dist/index.js CHANGED
@@ -31,10 +31,10 @@ 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.1";
34
+ var version = "1.24.0-beta.18";
35
35
  var createRule = shared.createRuleForPlugin("hooks-extra");
36
36
  function isFromHookCall(name2, context, settings, predicate = eff.returnTrue) {
37
- const hookAlias = settings.additionalHooks?.[name2] ?? [];
37
+ const hookAlias = settings.additionalHooks[name2] ?? [];
38
38
  return (topLevelId) => {
39
39
  const variable = VAR5__namespace.findVariable(topLevelId, context.sourceCode.getScope(topLevelId));
40
40
  const variableNode = VAR5__namespace.getVariableNode(variable, 0);
@@ -74,7 +74,7 @@ function isSetFunctionCall(context, settings) {
74
74
  return false;
75
75
  }
76
76
  const indexScope = context.sourceCode.getScope(node);
77
- const indexValue = VAR5__namespace.toResolved({
77
+ const indexValue = VAR5__namespace.toStaticValue({
78
78
  kind: "lazy",
79
79
  node: index,
80
80
  initialScope: indexScope
@@ -94,7 +94,7 @@ function isSetFunctionCall(context, settings) {
94
94
  }
95
95
  const property = node.callee.property;
96
96
  const propertyScope = context.sourceCode.getScope(node);
97
- const propertyValue = VAR5__namespace.toResolved({
97
+ const propertyValue = VAR5__namespace.toStaticValue({
98
98
  kind: "lazy",
99
99
  node: property,
100
100
  initialScope: propertyScope
@@ -153,7 +153,7 @@ var no_direct_set_state_in_use_effect_default = createRule({
153
153
  return {};
154
154
  }
155
155
  const settings = shared.getSettingsFromContext(context);
156
- const additionalHooks = settings.additionalHooks ?? {};
156
+ const additionalHooks = settings.additionalHooks;
157
157
  const isUseEffectLikeCall = core.isReactHookCallWithNameAlias("useEffect", context, additionalHooks.useEffect ?? []);
158
158
  const isUseStateCall2 = core.isReactHookCallWithNameAlias("useState", context, additionalHooks.useState ?? []);
159
159
  const isUseMemoCall2 = core.isReactHookCallWithNameAlias("useMemo", context, additionalHooks.useMemo ?? []);
@@ -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 WeakMap();
168
- const indSetStateCallsInUseEffectArg0 = /* @__PURE__ */ new WeakMap();
167
+ const indSetStateCalls = /* @__PURE__ */ new Map();
168
+ const indSetStateCallsInUseEffectArg0 = /* @__PURE__ */ new Map();
169
169
  const indSetStateCallsInUseEffectSetup = /* @__PURE__ */ new Map();
170
- const indSetStateCallsInUseMemoOrCallback = /* @__PURE__ */ new WeakMap();
170
+ const indSetStateCallsInUseMemoOrCallback = /* @__PURE__ */ new Map();
171
171
  const onSetupFunctionEnter = (node) => {
172
172
  setupFunctionRef.current = node;
173
173
  };
@@ -176,14 +176,14 @@ var no_direct_set_state_in_use_effect_default = createRule({
176
176
  setupFunctionRef.current = null;
177
177
  }
178
178
  };
179
- function isSetupFunction(node) {
179
+ function isFunctionOfUseEffectSetup(node) {
180
180
  return node.parent?.type === types.AST_NODE_TYPES.CallExpression && node.parent.callee !== node && isUseEffectLikeCall(node.parent);
181
181
  }
182
182
  function getCallKind(node) {
183
183
  return tsPattern.match(node).when(isUseStateCall2, () => "useState").when(isUseEffectLikeCall, () => "useEffect").when(isSetStateCall, () => "setState").when(isThenCall, () => "then").otherwise(() => "other");
184
184
  }
185
185
  function getFunctionKind(node) {
186
- return tsPattern.match(node).when(isSetupFunction, () => "setup").when(AST__namespace.isFunctionOfImmediatelyInvoked, () => "immediate").otherwise(() => "other");
186
+ return tsPattern.match(node).when(isFunctionOfUseEffectSetup, () => "setup").when(AST__namespace.isFunctionOfImmediatelyInvoked, () => "immediate").otherwise(() => "other");
187
187
  }
188
188
  return {
189
189
  ":function"(node) {
@@ -219,26 +219,16 @@ var no_direct_set_state_in_use_effect_default = createRule({
219
219
  return;
220
220
  }
221
221
  default: {
222
- const variableDeclarator = AST__namespace.findParentNodeGuard(node, isVariableDeclaratorFromHookCall);
223
- if (variableDeclarator == null) {
224
- const calls = indSetStateCalls.get(pEntry.node) ?? [];
225
- indSetStateCalls.set(pEntry.node, [...calls, node]);
226
- return;
227
- }
228
- const init = variableDeclarator.init;
229
- const prevs = indSetStateCallsInUseMemoOrCallback.get(init) ?? [];
230
- 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);
231
225
  }
232
226
  }
233
227
  }).with("useEffect", () => {
234
- if (AST__namespace.isFunction(node.arguments.at(0))) {
235
- return;
236
- }
228
+ if (AST__namespace.isFunction(node.arguments.at(0))) return;
237
229
  setupFunctionIdentifiers.push(...AST__namespace.getNestedIdentifiers(node));
238
230
  }).with("other", () => {
239
- if (pEntry.node !== setupFunction) {
240
- return;
241
- }
231
+ if (pEntry.node !== setupFunction) return;
242
232
  indFunctionCalls.push(node);
243
233
  }).otherwise(() => eff._);
244
234
  },
@@ -258,12 +248,10 @@ var no_direct_set_state_in_use_effect_default = createRule({
258
248
  if (!isUseMemoCall2(parent)) {
259
249
  break;
260
250
  }
261
- const variableDeclarator = AST__namespace.findParentNodeGuard(parent, isVariableDeclaratorFromHookCall);
262
- if (variableDeclarator == null) {
263
- break;
251
+ const vd = AST__namespace.findParentNode(parent, isVariableDeclaratorFromHookCall);
252
+ if (vd != null) {
253
+ eff.getOrUpdate(indSetStateCallsInUseEffectArg0, vd.init, () => []).push(node);
264
254
  }
265
- const calls = indSetStateCallsInUseEffectArg0.get(variableDeclarator.init) ?? [];
266
- indSetStateCallsInUseEffectArg0.set(variableDeclarator.init, [...calls, node]);
267
255
  break;
268
256
  }
269
257
  case types.AST_NODE_TYPES.CallExpression: {
@@ -271,18 +259,15 @@ var no_direct_set_state_in_use_effect_default = createRule({
271
259
  break;
272
260
  }
273
261
  if (isUseCallbackCall2(node.parent)) {
274
- const variableDeclarator = AST__namespace.findParentNodeGuard(node.parent, isVariableDeclaratorFromHookCall);
275
- if (variableDeclarator == null) {
276
- break;
262
+ const vd = AST__namespace.findParentNode(node.parent, isVariableDeclaratorFromHookCall);
263
+ if (vd != null) {
264
+ eff.getOrUpdate(indSetStateCallsInUseEffectArg0, vd.init, () => []).push(node);
277
265
  }
278
- const prevs = indSetStateCallsInUseEffectArg0.get(variableDeclarator.init) ?? [];
279
- indSetStateCallsInUseEffectArg0.set(variableDeclarator.init, [...prevs, node]);
266
+ break;
280
267
  }
281
268
  if (isUseEffectLikeCall(node.parent)) {
282
- const prevs = indSetStateCallsInUseEffectArg0.get(node.parent) ?? [];
283
- indSetStateCallsInUseEffectSetup.set(node.parent, [...prevs, node]);
269
+ eff.getOrUpdate(indSetStateCallsInUseEffectSetup, node.parent, () => []).push(node);
284
270
  }
285
- break;
286
271
  }
287
272
  }
288
273
  },
@@ -363,7 +348,7 @@ var no_direct_set_state_in_use_layout_effect_default = createRule({
363
348
  return {};
364
349
  }
365
350
  const settings = shared.getSettingsFromContext(context);
366
- const additionalHooks = settings.additionalHooks ?? {};
351
+ const additionalHooks = settings.additionalHooks;
367
352
  const isUseLayoutEffectLikeCall = core.isReactHookCallWithNameAlias(
368
353
  "useLayoutEffect",
369
354
  context,
@@ -378,10 +363,10 @@ var no_direct_set_state_in_use_layout_effect_default = createRule({
378
363
  const setupFunctionRef = { current: null };
379
364
  const setupFunctionIdentifiers = [];
380
365
  const indFunctionCalls = [];
381
- const indSetStateCalls = /* @__PURE__ */ new WeakMap();
382
- const indSetStateCallsInUseLayoutEffectArg0 = /* @__PURE__ */ new WeakMap();
366
+ const indSetStateCalls = /* @__PURE__ */ new Map();
367
+ const indSetStateCallsInUseLayoutEffectArg0 = /* @__PURE__ */ new Map();
383
368
  const indSetStateCallsInUseLayoutEffectSetup = /* @__PURE__ */ new Map();
384
- const indSetStateCallsInUseMemoOrCallback = /* @__PURE__ */ new WeakMap();
369
+ const indSetStateCallsInUseMemoOrCallback = /* @__PURE__ */ new Map();
385
370
  const onSetupFunctionEnter = (node) => {
386
371
  setupFunctionRef.current = node;
387
372
  };
@@ -390,14 +375,14 @@ var no_direct_set_state_in_use_layout_effect_default = createRule({
390
375
  setupFunctionRef.current = null;
391
376
  }
392
377
  };
393
- function isSetupFunction(node) {
378
+ function isFunctionOfUseEffectSetup(node) {
394
379
  return node.parent?.type === types.AST_NODE_TYPES.CallExpression && node.parent.callee !== node && isUseLayoutEffectLikeCall(node.parent);
395
380
  }
396
381
  function getCallKind(node) {
397
382
  return tsPattern.match(node).when(isUseStateCall2, () => "useState").when(isUseLayoutEffectLikeCall, () => "useLayoutEffect").when(isSetStateCall, () => "setState").when(isThenCall, () => "then").otherwise(() => "other");
398
383
  }
399
384
  function getFunctionKind(node) {
400
- return tsPattern.match(node).when(isSetupFunction, () => "setup").when(AST__namespace.isFunctionOfImmediatelyInvoked, () => "immediate").otherwise(() => "other");
385
+ return tsPattern.match(node).when(isFunctionOfUseEffectSetup, () => "setup").when(AST__namespace.isFunctionOfImmediatelyInvoked, () => "immediate").otherwise(() => "other");
401
386
  }
402
387
  return {
403
388
  ":function"(node) {
@@ -433,26 +418,16 @@ var no_direct_set_state_in_use_layout_effect_default = createRule({
433
418
  return;
434
419
  }
435
420
  default: {
436
- const variableDeclarator = AST__namespace.findParentNodeGuard(node, isVariableDeclaratorFromHookCall);
437
- if (variableDeclarator == null) {
438
- const calls = indSetStateCalls.get(pEntry.node) ?? [];
439
- indSetStateCalls.set(pEntry.node, [...calls, node]);
440
- return;
441
- }
442
- const init = variableDeclarator.init;
443
- const prevs = indSetStateCallsInUseMemoOrCallback.get(init) ?? [];
444
- 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);
445
424
  }
446
425
  }
447
426
  }).with("useLayoutEffect", () => {
448
- if (AST__namespace.isFunction(node.arguments.at(0))) {
449
- return;
450
- }
427
+ if (AST__namespace.isFunction(node.arguments.at(0))) return;
451
428
  setupFunctionIdentifiers.push(...AST__namespace.getNestedIdentifiers(node));
452
429
  }).with("other", () => {
453
- if (pEntry.node !== setupFunction) {
454
- return;
455
- }
430
+ if (pEntry.node !== setupFunction) return;
456
431
  indFunctionCalls.push(node);
457
432
  }).otherwise(() => eff._);
458
433
  },
@@ -472,12 +447,10 @@ var no_direct_set_state_in_use_layout_effect_default = createRule({
472
447
  if (!isUseMemoCall2(parent)) {
473
448
  break;
474
449
  }
475
- const variableDeclarator = AST__namespace.findParentNodeGuard(parent, isVariableDeclaratorFromHookCall);
476
- if (variableDeclarator == null) {
477
- break;
450
+ const vd = AST__namespace.findParentNode(parent, isVariableDeclaratorFromHookCall);
451
+ if (vd != null) {
452
+ eff.getOrUpdate(indSetStateCallsInUseLayoutEffectArg0, vd.init, () => []).push(node);
478
453
  }
479
- const calls = indSetStateCallsInUseLayoutEffectArg0.get(variableDeclarator.init) ?? [];
480
- indSetStateCallsInUseLayoutEffectArg0.set(variableDeclarator.init, [...calls, node]);
481
454
  break;
482
455
  }
483
456
  case types.AST_NODE_TYPES.CallExpression: {
@@ -485,18 +458,15 @@ var no_direct_set_state_in_use_layout_effect_default = createRule({
485
458
  break;
486
459
  }
487
460
  if (isUseCallbackCall2(node.parent)) {
488
- const variableDeclarator = AST__namespace.findParentNodeGuard(node.parent, isVariableDeclaratorFromHookCall);
489
- if (variableDeclarator == null) {
490
- break;
461
+ const vd = AST__namespace.findParentNode(node.parent, isVariableDeclaratorFromHookCall);
462
+ if (vd != null) {
463
+ eff.getOrUpdate(indSetStateCallsInUseLayoutEffectArg0, vd.init, () => []).push(node);
491
464
  }
492
- const prevs = indSetStateCallsInUseLayoutEffectArg0.get(variableDeclarator.init) ?? [];
493
- indSetStateCallsInUseLayoutEffectArg0.set(variableDeclarator.init, [...prevs, node]);
465
+ break;
494
466
  }
495
467
  if (isUseLayoutEffectLikeCall(node.parent)) {
496
- const prevs = indSetStateCallsInUseLayoutEffectArg0.get(node.parent) ?? [];
497
- indSetStateCallsInUseLayoutEffectSetup.set(node.parent, [...prevs, node]);
468
+ eff.getOrUpdate(indSetStateCallsInUseLayoutEffectSetup, node.parent, () => []).push(node);
498
469
  }
499
- break;
500
470
  }
501
471
  }
502
472
  },
@@ -576,7 +546,7 @@ var no_unnecessary_use_callback_default = createRule({
576
546
  if (!context.sourceCode.text.includes("use")) {
577
547
  return {};
578
548
  }
579
- const alias = shared.getSettingsFromContext(context).additionalHooks?.useCallback ?? [];
549
+ const alias = shared.getSettingsFromContext(context).additionalHooks.useCallback ?? [];
580
550
  return {
581
551
  CallExpression(node) {
582
552
  if (!core.isReactHookCall(node)) {
@@ -655,7 +625,7 @@ var no_unnecessary_use_memo_default = createRule({
655
625
  if (!context.sourceCode.text.includes("use")) {
656
626
  return {};
657
627
  }
658
- const alias = shared.getSettingsFromContext(context).additionalHooks?.useMemo ?? [];
628
+ const alias = shared.getSettingsFromContext(context).additionalHooks.useMemo ?? [];
659
629
  return {
660
630
  CallExpression(node) {
661
631
  if (!core.isReactHookCall(node)) {
@@ -788,7 +758,7 @@ var prefer_use_state_lazy_initialization_default = createRule({
788
758
  if (!context.sourceCode.text.includes("use")) {
789
759
  return {};
790
760
  }
791
- const alias = shared.getSettingsFromContext(context).additionalHooks?.useState ?? [];
761
+ const alias = shared.getSettingsFromContext(context).additionalHooks.useState ?? [];
792
762
  return {
793
763
  CallExpression(node) {
794
764
  if (!core.isReactHookCall(node)) {
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,10 +8,10 @@ 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.1";
11
+ var version = "1.24.0-beta.18";
12
12
  var createRule = createRuleForPlugin("hooks-extra");
13
13
  function isFromHookCall(name2, context, settings, predicate = returnTrue) {
14
- const hookAlias = settings.additionalHooks?.[name2] ?? [];
14
+ const hookAlias = settings.additionalHooks[name2] ?? [];
15
15
  return (topLevelId) => {
16
16
  const variable = VAR5.findVariable(topLevelId, context.sourceCode.getScope(topLevelId));
17
17
  const variableNode = VAR5.getVariableNode(variable, 0);
@@ -51,7 +51,7 @@ function isSetFunctionCall(context, settings) {
51
51
  return false;
52
52
  }
53
53
  const indexScope = context.sourceCode.getScope(node);
54
- const indexValue = VAR5.toResolved({
54
+ const indexValue = VAR5.toStaticValue({
55
55
  kind: "lazy",
56
56
  node: index,
57
57
  initialScope: indexScope
@@ -71,7 +71,7 @@ function isSetFunctionCall(context, settings) {
71
71
  }
72
72
  const property = node.callee.property;
73
73
  const propertyScope = context.sourceCode.getScope(node);
74
- const propertyValue = VAR5.toResolved({
74
+ const propertyValue = VAR5.toStaticValue({
75
75
  kind: "lazy",
76
76
  node: property,
77
77
  initialScope: propertyScope
@@ -130,7 +130,7 @@ var no_direct_set_state_in_use_effect_default = createRule({
130
130
  return {};
131
131
  }
132
132
  const settings = getSettingsFromContext(context);
133
- const additionalHooks = settings.additionalHooks ?? {};
133
+ const additionalHooks = settings.additionalHooks;
134
134
  const isUseEffectLikeCall = isReactHookCallWithNameAlias("useEffect", context, additionalHooks.useEffect ?? []);
135
135
  const isUseStateCall2 = isReactHookCallWithNameAlias("useState", context, additionalHooks.useState ?? []);
136
136
  const isUseMemoCall2 = isReactHookCallWithNameAlias("useMemo", context, additionalHooks.useMemo ?? []);
@@ -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 WeakMap();
145
- const indSetStateCallsInUseEffectArg0 = /* @__PURE__ */ new WeakMap();
144
+ const indSetStateCalls = /* @__PURE__ */ new Map();
145
+ const indSetStateCallsInUseEffectArg0 = /* @__PURE__ */ new Map();
146
146
  const indSetStateCallsInUseEffectSetup = /* @__PURE__ */ new Map();
147
- const indSetStateCallsInUseMemoOrCallback = /* @__PURE__ */ new WeakMap();
147
+ const indSetStateCallsInUseMemoOrCallback = /* @__PURE__ */ new Map();
148
148
  const onSetupFunctionEnter = (node) => {
149
149
  setupFunctionRef.current = node;
150
150
  };
@@ -153,14 +153,14 @@ var no_direct_set_state_in_use_effect_default = createRule({
153
153
  setupFunctionRef.current = null;
154
154
  }
155
155
  };
156
- function isSetupFunction(node) {
156
+ function isFunctionOfUseEffectSetup(node) {
157
157
  return node.parent?.type === AST_NODE_TYPES.CallExpression && node.parent.callee !== node && isUseEffectLikeCall(node.parent);
158
158
  }
159
159
  function getCallKind(node) {
160
160
  return match(node).when(isUseStateCall2, () => "useState").when(isUseEffectLikeCall, () => "useEffect").when(isSetStateCall, () => "setState").when(isThenCall, () => "then").otherwise(() => "other");
161
161
  }
162
162
  function getFunctionKind(node) {
163
- return match(node).when(isSetupFunction, () => "setup").when(AST.isFunctionOfImmediatelyInvoked, () => "immediate").otherwise(() => "other");
163
+ return match(node).when(isFunctionOfUseEffectSetup, () => "setup").when(AST.isFunctionOfImmediatelyInvoked, () => "immediate").otherwise(() => "other");
164
164
  }
165
165
  return {
166
166
  ":function"(node) {
@@ -196,26 +196,16 @@ var no_direct_set_state_in_use_effect_default = createRule({
196
196
  return;
197
197
  }
198
198
  default: {
199
- const variableDeclarator = AST.findParentNodeGuard(node, isVariableDeclaratorFromHookCall);
200
- if (variableDeclarator == null) {
201
- const calls = indSetStateCalls.get(pEntry.node) ?? [];
202
- indSetStateCalls.set(pEntry.node, [...calls, node]);
203
- return;
204
- }
205
- const init = variableDeclarator.init;
206
- const prevs = indSetStateCallsInUseMemoOrCallback.get(init) ?? [];
207
- 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);
208
202
  }
209
203
  }
210
204
  }).with("useEffect", () => {
211
- if (AST.isFunction(node.arguments.at(0))) {
212
- return;
213
- }
205
+ if (AST.isFunction(node.arguments.at(0))) return;
214
206
  setupFunctionIdentifiers.push(...AST.getNestedIdentifiers(node));
215
207
  }).with("other", () => {
216
- if (pEntry.node !== setupFunction) {
217
- return;
218
- }
208
+ if (pEntry.node !== setupFunction) return;
219
209
  indFunctionCalls.push(node);
220
210
  }).otherwise(() => _);
221
211
  },
@@ -235,12 +225,10 @@ var no_direct_set_state_in_use_effect_default = createRule({
235
225
  if (!isUseMemoCall2(parent)) {
236
226
  break;
237
227
  }
238
- const variableDeclarator = AST.findParentNodeGuard(parent, isVariableDeclaratorFromHookCall);
239
- if (variableDeclarator == null) {
240
- break;
228
+ const vd = AST.findParentNode(parent, isVariableDeclaratorFromHookCall);
229
+ if (vd != null) {
230
+ getOrUpdate(indSetStateCallsInUseEffectArg0, vd.init, () => []).push(node);
241
231
  }
242
- const calls = indSetStateCallsInUseEffectArg0.get(variableDeclarator.init) ?? [];
243
- indSetStateCallsInUseEffectArg0.set(variableDeclarator.init, [...calls, node]);
244
232
  break;
245
233
  }
246
234
  case AST_NODE_TYPES.CallExpression: {
@@ -248,18 +236,15 @@ var no_direct_set_state_in_use_effect_default = createRule({
248
236
  break;
249
237
  }
250
238
  if (isUseCallbackCall2(node.parent)) {
251
- const variableDeclarator = AST.findParentNodeGuard(node.parent, isVariableDeclaratorFromHookCall);
252
- if (variableDeclarator == null) {
253
- break;
239
+ const vd = AST.findParentNode(node.parent, isVariableDeclaratorFromHookCall);
240
+ if (vd != null) {
241
+ getOrUpdate(indSetStateCallsInUseEffectArg0, vd.init, () => []).push(node);
254
242
  }
255
- const prevs = indSetStateCallsInUseEffectArg0.get(variableDeclarator.init) ?? [];
256
- indSetStateCallsInUseEffectArg0.set(variableDeclarator.init, [...prevs, node]);
243
+ break;
257
244
  }
258
245
  if (isUseEffectLikeCall(node.parent)) {
259
- const prevs = indSetStateCallsInUseEffectArg0.get(node.parent) ?? [];
260
- indSetStateCallsInUseEffectSetup.set(node.parent, [...prevs, node]);
246
+ getOrUpdate(indSetStateCallsInUseEffectSetup, node.parent, () => []).push(node);
261
247
  }
262
- break;
263
248
  }
264
249
  }
265
250
  },
@@ -340,7 +325,7 @@ var no_direct_set_state_in_use_layout_effect_default = createRule({
340
325
  return {};
341
326
  }
342
327
  const settings = getSettingsFromContext(context);
343
- const additionalHooks = settings.additionalHooks ?? {};
328
+ const additionalHooks = settings.additionalHooks;
344
329
  const isUseLayoutEffectLikeCall = isReactHookCallWithNameAlias(
345
330
  "useLayoutEffect",
346
331
  context,
@@ -355,10 +340,10 @@ var no_direct_set_state_in_use_layout_effect_default = createRule({
355
340
  const setupFunctionRef = { current: null };
356
341
  const setupFunctionIdentifiers = [];
357
342
  const indFunctionCalls = [];
358
- const indSetStateCalls = /* @__PURE__ */ new WeakMap();
359
- const indSetStateCallsInUseLayoutEffectArg0 = /* @__PURE__ */ new WeakMap();
343
+ const indSetStateCalls = /* @__PURE__ */ new Map();
344
+ const indSetStateCallsInUseLayoutEffectArg0 = /* @__PURE__ */ new Map();
360
345
  const indSetStateCallsInUseLayoutEffectSetup = /* @__PURE__ */ new Map();
361
- const indSetStateCallsInUseMemoOrCallback = /* @__PURE__ */ new WeakMap();
346
+ const indSetStateCallsInUseMemoOrCallback = /* @__PURE__ */ new Map();
362
347
  const onSetupFunctionEnter = (node) => {
363
348
  setupFunctionRef.current = node;
364
349
  };
@@ -367,14 +352,14 @@ var no_direct_set_state_in_use_layout_effect_default = createRule({
367
352
  setupFunctionRef.current = null;
368
353
  }
369
354
  };
370
- function isSetupFunction(node) {
355
+ function isFunctionOfUseEffectSetup(node) {
371
356
  return node.parent?.type === AST_NODE_TYPES.CallExpression && node.parent.callee !== node && isUseLayoutEffectLikeCall(node.parent);
372
357
  }
373
358
  function getCallKind(node) {
374
359
  return match(node).when(isUseStateCall2, () => "useState").when(isUseLayoutEffectLikeCall, () => "useLayoutEffect").when(isSetStateCall, () => "setState").when(isThenCall, () => "then").otherwise(() => "other");
375
360
  }
376
361
  function getFunctionKind(node) {
377
- return match(node).when(isSetupFunction, () => "setup").when(AST.isFunctionOfImmediatelyInvoked, () => "immediate").otherwise(() => "other");
362
+ return match(node).when(isFunctionOfUseEffectSetup, () => "setup").when(AST.isFunctionOfImmediatelyInvoked, () => "immediate").otherwise(() => "other");
378
363
  }
379
364
  return {
380
365
  ":function"(node) {
@@ -410,26 +395,16 @@ var no_direct_set_state_in_use_layout_effect_default = createRule({
410
395
  return;
411
396
  }
412
397
  default: {
413
- const variableDeclarator = AST.findParentNodeGuard(node, isVariableDeclaratorFromHookCall);
414
- if (variableDeclarator == null) {
415
- const calls = indSetStateCalls.get(pEntry.node) ?? [];
416
- indSetStateCalls.set(pEntry.node, [...calls, node]);
417
- return;
418
- }
419
- const init = variableDeclarator.init;
420
- const prevs = indSetStateCallsInUseMemoOrCallback.get(init) ?? [];
421
- 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);
422
401
  }
423
402
  }
424
403
  }).with("useLayoutEffect", () => {
425
- if (AST.isFunction(node.arguments.at(0))) {
426
- return;
427
- }
404
+ if (AST.isFunction(node.arguments.at(0))) return;
428
405
  setupFunctionIdentifiers.push(...AST.getNestedIdentifiers(node));
429
406
  }).with("other", () => {
430
- if (pEntry.node !== setupFunction) {
431
- return;
432
- }
407
+ if (pEntry.node !== setupFunction) return;
433
408
  indFunctionCalls.push(node);
434
409
  }).otherwise(() => _);
435
410
  },
@@ -449,12 +424,10 @@ var no_direct_set_state_in_use_layout_effect_default = createRule({
449
424
  if (!isUseMemoCall2(parent)) {
450
425
  break;
451
426
  }
452
- const variableDeclarator = AST.findParentNodeGuard(parent, isVariableDeclaratorFromHookCall);
453
- if (variableDeclarator == null) {
454
- break;
427
+ const vd = AST.findParentNode(parent, isVariableDeclaratorFromHookCall);
428
+ if (vd != null) {
429
+ getOrUpdate(indSetStateCallsInUseLayoutEffectArg0, vd.init, () => []).push(node);
455
430
  }
456
- const calls = indSetStateCallsInUseLayoutEffectArg0.get(variableDeclarator.init) ?? [];
457
- indSetStateCallsInUseLayoutEffectArg0.set(variableDeclarator.init, [...calls, node]);
458
431
  break;
459
432
  }
460
433
  case AST_NODE_TYPES.CallExpression: {
@@ -462,18 +435,15 @@ var no_direct_set_state_in_use_layout_effect_default = createRule({
462
435
  break;
463
436
  }
464
437
  if (isUseCallbackCall2(node.parent)) {
465
- const variableDeclarator = AST.findParentNodeGuard(node.parent, isVariableDeclaratorFromHookCall);
466
- if (variableDeclarator == null) {
467
- break;
438
+ const vd = AST.findParentNode(node.parent, isVariableDeclaratorFromHookCall);
439
+ if (vd != null) {
440
+ getOrUpdate(indSetStateCallsInUseLayoutEffectArg0, vd.init, () => []).push(node);
468
441
  }
469
- const prevs = indSetStateCallsInUseLayoutEffectArg0.get(variableDeclarator.init) ?? [];
470
- indSetStateCallsInUseLayoutEffectArg0.set(variableDeclarator.init, [...prevs, node]);
442
+ break;
471
443
  }
472
444
  if (isUseLayoutEffectLikeCall(node.parent)) {
473
- const prevs = indSetStateCallsInUseLayoutEffectArg0.get(node.parent) ?? [];
474
- indSetStateCallsInUseLayoutEffectSetup.set(node.parent, [...prevs, node]);
445
+ getOrUpdate(indSetStateCallsInUseLayoutEffectSetup, node.parent, () => []).push(node);
475
446
  }
476
- break;
477
447
  }
478
448
  }
479
449
  },
@@ -553,7 +523,7 @@ var no_unnecessary_use_callback_default = createRule({
553
523
  if (!context.sourceCode.text.includes("use")) {
554
524
  return {};
555
525
  }
556
- const alias = getSettingsFromContext(context).additionalHooks?.useCallback ?? [];
526
+ const alias = getSettingsFromContext(context).additionalHooks.useCallback ?? [];
557
527
  return {
558
528
  CallExpression(node) {
559
529
  if (!isReactHookCall(node)) {
@@ -632,7 +602,7 @@ var no_unnecessary_use_memo_default = createRule({
632
602
  if (!context.sourceCode.text.includes("use")) {
633
603
  return {};
634
604
  }
635
- const alias = getSettingsFromContext(context).additionalHooks?.useMemo ?? [];
605
+ const alias = getSettingsFromContext(context).additionalHooks.useMemo ?? [];
636
606
  return {
637
607
  CallExpression(node) {
638
608
  if (!isReactHookCall(node)) {
@@ -765,7 +735,7 @@ var prefer_use_state_lazy_initialization_default = createRule({
765
735
  if (!context.sourceCode.text.includes("use")) {
766
736
  return {};
767
737
  }
768
- const alias = getSettingsFromContext(context).additionalHooks?.useState ?? [];
738
+ const alias = getSettingsFromContext(context).additionalHooks.useState ?? [];
769
739
  return {
770
740
  CallExpression(node) {
771
741
  if (!isReactHookCall(node)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-react-hooks-extra",
3
- "version": "1.24.0-beta.1",
3
+ "version": "1.24.0-beta.18",
4
4
  "description": "ESLint React's ESLint plugin for React Hooks related rules.",
5
5
  "keywords": [
6
6
  "react",
@@ -42,22 +42,21 @@
42
42
  "./package.json"
43
43
  ],
44
44
  "dependencies": {
45
- "@typescript-eslint/scope-manager": "^8.19.1",
46
- "@typescript-eslint/type-utils": "^8.19.1",
47
- "@typescript-eslint/types": "^8.19.1",
48
- "@typescript-eslint/utils": "^8.19.1",
45
+ "@typescript-eslint/scope-manager": "^8.20.0",
46
+ "@typescript-eslint/type-utils": "^8.20.0",
47
+ "@typescript-eslint/types": "^8.20.0",
48
+ "@typescript-eslint/utils": "^8.20.0",
49
49
  "string-ts": "^2.2.0",
50
- "ts-pattern": "^5.6.0",
51
- "@eslint-react/ast": "1.24.0-beta.1",
52
- "@eslint-react/eff": "1.24.0-beta.1",
53
- "@eslint-react/jsx": "1.24.0-beta.1",
54
- "@eslint-react/shared": "1.24.0-beta.1",
55
- "@eslint-react/var": "1.24.0-beta.1",
56
- "@eslint-react/core": "1.24.0-beta.1",
57
- "@eslint-react/types": "1.24.0-beta.1"
50
+ "ts-pattern": "^5.6.1",
51
+ "@eslint-react/core": "1.24.0-beta.18",
52
+ "@eslint-react/ast": "1.24.0-beta.18",
53
+ "@eslint-react/eff": "1.24.0-beta.18",
54
+ "@eslint-react/var": "1.24.0-beta.18",
55
+ "@eslint-react/shared": "1.24.0-beta.18",
56
+ "@eslint-react/jsx": "1.24.0-beta.18"
58
57
  },
59
58
  "devDependencies": {
60
- "@types/react": "^19.0.5",
59
+ "@types/react": "^19.0.7",
61
60
  "@types/react-dom": "^19.0.3",
62
61
  "tsup": "^8.3.5",
63
62
  "@workspace/configs": "0.0.0"