eslint-plugin-react-hooks-extra 1.24.0-next.2 → 1.24.0-next.4

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 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-next.2";
34
+ var version = "1.24.0-next.4";
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 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
  };
@@ -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.findParentNode(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.findParentNode(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.findParentNode(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
  },
@@ -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
  };
@@ -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.findParentNode(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.findParentNode(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.findParentNode(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
  },
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-next.2";
11
+ var version = "1.24.0-next.4";
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 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
  };
@@ -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.findParentNode(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.findParentNode(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.findParentNode(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
  },
@@ -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
  };
@@ -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.findParentNode(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.findParentNode(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.findParentNode(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
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-react-hooks-extra",
3
- "version": "1.24.0-next.2",
3
+ "version": "1.24.0-next.4",
4
4
  "description": "ESLint React's ESLint plugin for React Hooks related rules.",
5
5
  "keywords": [
6
6
  "react",
@@ -48,13 +48,12 @@
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-next.2",
52
- "@eslint-react/core": "1.24.0-next.2",
53
- "@eslint-react/jsx": "1.24.0-next.2",
54
- "@eslint-react/eff": "1.24.0-next.2",
55
- "@eslint-react/shared": "1.24.0-next.2",
56
- "@eslint-react/types": "1.24.0-next.2",
57
- "@eslint-react/var": "1.24.0-next.2"
51
+ "@eslint-react/ast": "1.24.0-next.4",
52
+ "@eslint-react/core": "1.24.0-next.4",
53
+ "@eslint-react/eff": "1.24.0-next.4",
54
+ "@eslint-react/jsx": "1.24.0-next.4",
55
+ "@eslint-react/var": "1.24.0-next.4",
56
+ "@eslint-react/shared": "1.24.0-next.4"
58
57
  },
59
58
  "devDependencies": {
60
59
  "@types/react": "^19.0.6",