eslint-plugin-react-hooks-extra 1.10.1-next.4 → 1.10.1

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
@@ -11,7 +11,7 @@ var tsPattern = require('ts-pattern');
11
11
 
12
12
  // package.json
13
13
  var name = "eslint-plugin-react-hooks-extra";
14
- var version = "1.10.1-next.4";
14
+ var version = "1.10.1";
15
15
  var createRule = shared.createRuleForPlugin("hooks-extra");
16
16
  function isFromHookCall(name2, context, settings, predicate = tools.F.constTrue) {
17
17
  const hookAlias = settings.additionalHooks?.[name2] ?? [];
@@ -300,41 +300,41 @@ var no_direct_set_state_in_use_effect_default = createRule({
300
300
  const isSetStateCall = isSetFunctionCall(context, settings);
301
301
  const isIdFromUseStateCall = isFromUseStateCall(context, settings);
302
302
  const functionStack = [];
303
- const effectFunctionRef = tools.MutRef.make(null);
304
- const effectFunctionIdentifiers = [];
303
+ const setupFunctionRef = tools.MutRef.make(null);
304
+ const setupFunctionIdentifiers = [];
305
305
  const indirectFunctionCalls = [];
306
306
  const indirectSetStateCalls = /* @__PURE__ */ new WeakMap();
307
307
  const indirectSetStateCallsAsEFs = /* @__PURE__ */ new Map();
308
308
  const indirectSetStateCallsAsArgs = /* @__PURE__ */ new WeakMap();
309
309
  const indirectSetStateCallsInHooks = /* @__PURE__ */ new WeakMap();
310
- const onEffectFunctionEnter = (node) => {
311
- tools.MutRef.set(effectFunctionRef, node);
310
+ const onSetupFunctionEnter = (node) => {
311
+ tools.MutRef.set(setupFunctionRef, node);
312
312
  };
313
- const onEffectFunctionExit = (node) => {
314
- tools.MutRef.update(effectFunctionRef, (current) => current === node ? null : current);
313
+ const onSetupFunctionExit = (node) => {
314
+ tools.MutRef.update(setupFunctionRef, (current) => current === node ? null : current);
315
315
  };
316
- function isEffectFunction(node) {
316
+ function isSetupFunction(node) {
317
317
  return node.parent?.type === types.AST_NODE_TYPES.CallExpression && node.parent.callee !== node && isUseEffectCall(node.parent);
318
318
  }
319
319
  function getCallKind(node) {
320
320
  return tsPattern.match(node).when(isUseStateCall2, () => "useState").when(isUseEffectCall, () => "useEffect").when(isSetStateCall, () => "setState").when(isThenCall, () => "then").otherwise(() => "other");
321
321
  }
322
322
  function getFunctionKind(node) {
323
- return tsPattern.match(node).when(isEffectFunction, () => "effect").when(ast.isFunctionOfImmediatelyInvoked, () => "immediate").otherwise(() => "other");
323
+ return tsPattern.match(node).when(isSetupFunction, () => "setup").when(ast.isFunctionOfImmediatelyInvoked, () => "immediate").otherwise(() => "other");
324
324
  }
325
325
  return {
326
326
  ":function"(node) {
327
327
  const functionKind = getFunctionKind(node);
328
328
  functionStack.push([node, functionKind]);
329
- if (functionKind === "effect") onEffectFunctionEnter(node);
329
+ if (functionKind === "setup") onSetupFunctionEnter(node);
330
330
  },
331
331
  ":function:exit"(node) {
332
332
  const [_, functionKind] = functionStack.at(-1) ?? [];
333
333
  functionStack.pop();
334
- if (functionKind === "effect") onEffectFunctionExit(node);
334
+ if (functionKind === "setup") onSetupFunctionExit(node);
335
335
  },
336
336
  CallExpression(node) {
337
- const effectFn = tools.MutRef.get(effectFunctionRef);
337
+ const effectFn = tools.MutRef.get(setupFunctionRef);
338
338
  const [parentFn, parentFnKind] = functionStack.at(-1) ?? [];
339
339
  if (parentFn?.async) return;
340
340
  tsPattern.match(getCallKind(node)).with("setState", () => {
@@ -359,10 +359,10 @@ var no_direct_set_state_in_use_effect_default = createRule({
359
359
  const [firstArg] = node.arguments;
360
360
  if (ast.isFunction(firstArg)) return;
361
361
  const identifiers = ast.getNestedIdentifiers(node);
362
- effectFunctionIdentifiers.push(...identifiers);
362
+ setupFunctionIdentifiers.push(...identifiers);
363
363
  }).with("other", () => {
364
- const isInEffectFunction = effectFn === parentFn;
365
- if (!isInEffectFunction) return;
364
+ const isInSetupFunction = effectFn === parentFn;
365
+ if (!isInSetupFunction) return;
366
366
  indirectFunctionCalls.push(node);
367
367
  }).otherwise(tools.F.constVoid);
368
368
  },
@@ -432,7 +432,7 @@ var no_direct_set_state_in_use_effect_default = createRule({
432
432
  });
433
433
  }
434
434
  }
435
- for (const id of effectFunctionIdentifiers) {
435
+ for (const id of setupFunctionIdentifiers) {
436
436
  const setStateCalls = getSetStateCalls(id.name, context.sourceCode.getScope(id));
437
437
  for (const setStateCall of setStateCalls) {
438
438
  context.report({
@@ -474,41 +474,41 @@ var no_direct_set_state_in_use_layout_effect_default = createRule({
474
474
  const isSetStateCall = isSetFunctionCall(context, settings);
475
475
  const isIdFromUseStateCall = isFromUseStateCall(context, settings);
476
476
  const functionStack = [];
477
- const effectFunctionRef = tools.MutRef.make(null);
478
- const effectFunctionIdentifiers = [];
477
+ const setupFunctionRef = tools.MutRef.make(null);
478
+ const setupFunctionIdentifiers = [];
479
479
  const indirectFunctionCalls = [];
480
480
  const indirectSetStateCalls = /* @__PURE__ */ new WeakMap();
481
481
  const indirectSetStateCallsAsEFs = /* @__PURE__ */ new Map();
482
482
  const indirectSetStateCallsAsArgs = /* @__PURE__ */ new WeakMap();
483
483
  const indirectSetStateCallsInHooks = /* @__PURE__ */ new WeakMap();
484
- const onEffectFunctionEnter = (node) => {
485
- tools.MutRef.set(effectFunctionRef, node);
484
+ const onSetupFunctionEnter = (node) => {
485
+ tools.MutRef.set(setupFunctionRef, node);
486
486
  };
487
- const onEffectFunctionExit = (node) => {
488
- tools.MutRef.update(effectFunctionRef, (current) => current === node ? null : current);
487
+ const onSetupFunctionExit = (node) => {
488
+ tools.MutRef.update(setupFunctionRef, (current) => current === node ? null : current);
489
489
  };
490
- function isEffectFunction(node) {
490
+ function isSetupFunction(node) {
491
491
  return node.parent?.type === types.AST_NODE_TYPES.CallExpression && node.parent.callee !== node && isUseEffectCall(node.parent);
492
492
  }
493
493
  function getCallKind(node) {
494
494
  return tsPattern.match(node).when(isUseStateCall2, () => "useState").when(isUseEffectCall, () => "useLayoutEffect").when(isSetStateCall, () => "setState").when(isThenCall, () => "then").otherwise(() => "other");
495
495
  }
496
496
  function getFunctionKind(node) {
497
- return tsPattern.match(node).when(isEffectFunction, () => "effect").when(ast.isFunctionOfImmediatelyInvoked, () => "immediate").otherwise(() => "other");
497
+ return tsPattern.match(node).when(isSetupFunction, () => "setup").when(ast.isFunctionOfImmediatelyInvoked, () => "immediate").otherwise(() => "other");
498
498
  }
499
499
  return {
500
500
  ":function"(node) {
501
501
  const functionKind = getFunctionKind(node);
502
502
  functionStack.push([node, functionKind]);
503
- if (functionKind === "effect") onEffectFunctionEnter(node);
503
+ if (functionKind === "setup") onSetupFunctionEnter(node);
504
504
  },
505
505
  ":function:exit"(node) {
506
506
  const [_, functionKind] = functionStack.at(-1) ?? [];
507
507
  functionStack.pop();
508
- if (functionKind === "effect") onEffectFunctionExit(node);
508
+ if (functionKind === "setup") onSetupFunctionExit(node);
509
509
  },
510
510
  CallExpression(node) {
511
- const effectFn = tools.MutRef.get(effectFunctionRef);
511
+ const effectFn = tools.MutRef.get(setupFunctionRef);
512
512
  const [parentFn, parentFnKind] = functionStack.at(-1) ?? [];
513
513
  if (parentFn?.async) return;
514
514
  tsPattern.match(getCallKind(node)).with("setState", () => {
@@ -533,10 +533,10 @@ var no_direct_set_state_in_use_layout_effect_default = createRule({
533
533
  const [firstArg] = node.arguments;
534
534
  if (ast.isFunction(firstArg)) return;
535
535
  const identifiers = ast.getNestedIdentifiers(node);
536
- effectFunctionIdentifiers.push(...identifiers);
536
+ setupFunctionIdentifiers.push(...identifiers);
537
537
  }).with("other", () => {
538
- const isInEffectFunction = effectFn === parentFn;
539
- if (!isInEffectFunction) return;
538
+ const isInSetupFunction = effectFn === parentFn;
539
+ if (!isInSetupFunction) return;
540
540
  indirectFunctionCalls.push(node);
541
541
  }).otherwise(tools.F.constVoid);
542
542
  },
@@ -606,7 +606,7 @@ var no_direct_set_state_in_use_layout_effect_default = createRule({
606
606
  });
607
607
  }
608
608
  }
609
- for (const id of effectFunctionIdentifiers) {
609
+ for (const id of setupFunctionIdentifiers) {
610
610
  const setStateCalls = getSetStateCalls(id.name, context.sourceCode.getScope(id));
611
611
  for (const setStateCall of setStateCalls) {
612
612
  context.report({
package/dist/index.mjs CHANGED
@@ -9,7 +9,7 @@ import { match, isMatching } from 'ts-pattern';
9
9
 
10
10
  // package.json
11
11
  var name = "eslint-plugin-react-hooks-extra";
12
- var version = "1.10.1-next.4";
12
+ var version = "1.10.1";
13
13
  var createRule = createRuleForPlugin("hooks-extra");
14
14
  function isFromHookCall(name2, context, settings, predicate = F.constTrue) {
15
15
  const hookAlias = settings.additionalHooks?.[name2] ?? [];
@@ -298,41 +298,41 @@ var no_direct_set_state_in_use_effect_default = createRule({
298
298
  const isSetStateCall = isSetFunctionCall(context, settings);
299
299
  const isIdFromUseStateCall = isFromUseStateCall(context, settings);
300
300
  const functionStack = [];
301
- const effectFunctionRef = MutRef.make(null);
302
- const effectFunctionIdentifiers = [];
301
+ const setupFunctionRef = MutRef.make(null);
302
+ const setupFunctionIdentifiers = [];
303
303
  const indirectFunctionCalls = [];
304
304
  const indirectSetStateCalls = /* @__PURE__ */ new WeakMap();
305
305
  const indirectSetStateCallsAsEFs = /* @__PURE__ */ new Map();
306
306
  const indirectSetStateCallsAsArgs = /* @__PURE__ */ new WeakMap();
307
307
  const indirectSetStateCallsInHooks = /* @__PURE__ */ new WeakMap();
308
- const onEffectFunctionEnter = (node) => {
309
- MutRef.set(effectFunctionRef, node);
308
+ const onSetupFunctionEnter = (node) => {
309
+ MutRef.set(setupFunctionRef, node);
310
310
  };
311
- const onEffectFunctionExit = (node) => {
312
- MutRef.update(effectFunctionRef, (current) => current === node ? null : current);
311
+ const onSetupFunctionExit = (node) => {
312
+ MutRef.update(setupFunctionRef, (current) => current === node ? null : current);
313
313
  };
314
- function isEffectFunction(node) {
314
+ function isSetupFunction(node) {
315
315
  return node.parent?.type === AST_NODE_TYPES.CallExpression && node.parent.callee !== node && isUseEffectCall(node.parent);
316
316
  }
317
317
  function getCallKind(node) {
318
318
  return match(node).when(isUseStateCall2, () => "useState").when(isUseEffectCall, () => "useEffect").when(isSetStateCall, () => "setState").when(isThenCall, () => "then").otherwise(() => "other");
319
319
  }
320
320
  function getFunctionKind(node) {
321
- return match(node).when(isEffectFunction, () => "effect").when(isFunctionOfImmediatelyInvoked, () => "immediate").otherwise(() => "other");
321
+ return match(node).when(isSetupFunction, () => "setup").when(isFunctionOfImmediatelyInvoked, () => "immediate").otherwise(() => "other");
322
322
  }
323
323
  return {
324
324
  ":function"(node) {
325
325
  const functionKind = getFunctionKind(node);
326
326
  functionStack.push([node, functionKind]);
327
- if (functionKind === "effect") onEffectFunctionEnter(node);
327
+ if (functionKind === "setup") onSetupFunctionEnter(node);
328
328
  },
329
329
  ":function:exit"(node) {
330
330
  const [_, functionKind] = functionStack.at(-1) ?? [];
331
331
  functionStack.pop();
332
- if (functionKind === "effect") onEffectFunctionExit(node);
332
+ if (functionKind === "setup") onSetupFunctionExit(node);
333
333
  },
334
334
  CallExpression(node) {
335
- const effectFn = MutRef.get(effectFunctionRef);
335
+ const effectFn = MutRef.get(setupFunctionRef);
336
336
  const [parentFn, parentFnKind] = functionStack.at(-1) ?? [];
337
337
  if (parentFn?.async) return;
338
338
  match(getCallKind(node)).with("setState", () => {
@@ -357,10 +357,10 @@ var no_direct_set_state_in_use_effect_default = createRule({
357
357
  const [firstArg] = node.arguments;
358
358
  if (isFunction(firstArg)) return;
359
359
  const identifiers = getNestedIdentifiers(node);
360
- effectFunctionIdentifiers.push(...identifiers);
360
+ setupFunctionIdentifiers.push(...identifiers);
361
361
  }).with("other", () => {
362
- const isInEffectFunction = effectFn === parentFn;
363
- if (!isInEffectFunction) return;
362
+ const isInSetupFunction = effectFn === parentFn;
363
+ if (!isInSetupFunction) return;
364
364
  indirectFunctionCalls.push(node);
365
365
  }).otherwise(F.constVoid);
366
366
  },
@@ -430,7 +430,7 @@ var no_direct_set_state_in_use_effect_default = createRule({
430
430
  });
431
431
  }
432
432
  }
433
- for (const id of effectFunctionIdentifiers) {
433
+ for (const id of setupFunctionIdentifiers) {
434
434
  const setStateCalls = getSetStateCalls(id.name, context.sourceCode.getScope(id));
435
435
  for (const setStateCall of setStateCalls) {
436
436
  context.report({
@@ -472,41 +472,41 @@ var no_direct_set_state_in_use_layout_effect_default = createRule({
472
472
  const isSetStateCall = isSetFunctionCall(context, settings);
473
473
  const isIdFromUseStateCall = isFromUseStateCall(context, settings);
474
474
  const functionStack = [];
475
- const effectFunctionRef = MutRef.make(null);
476
- const effectFunctionIdentifiers = [];
475
+ const setupFunctionRef = MutRef.make(null);
476
+ const setupFunctionIdentifiers = [];
477
477
  const indirectFunctionCalls = [];
478
478
  const indirectSetStateCalls = /* @__PURE__ */ new WeakMap();
479
479
  const indirectSetStateCallsAsEFs = /* @__PURE__ */ new Map();
480
480
  const indirectSetStateCallsAsArgs = /* @__PURE__ */ new WeakMap();
481
481
  const indirectSetStateCallsInHooks = /* @__PURE__ */ new WeakMap();
482
- const onEffectFunctionEnter = (node) => {
483
- MutRef.set(effectFunctionRef, node);
482
+ const onSetupFunctionEnter = (node) => {
483
+ MutRef.set(setupFunctionRef, node);
484
484
  };
485
- const onEffectFunctionExit = (node) => {
486
- MutRef.update(effectFunctionRef, (current) => current === node ? null : current);
485
+ const onSetupFunctionExit = (node) => {
486
+ MutRef.update(setupFunctionRef, (current) => current === node ? null : current);
487
487
  };
488
- function isEffectFunction(node) {
488
+ function isSetupFunction(node) {
489
489
  return node.parent?.type === AST_NODE_TYPES.CallExpression && node.parent.callee !== node && isUseEffectCall(node.parent);
490
490
  }
491
491
  function getCallKind(node) {
492
492
  return match(node).when(isUseStateCall2, () => "useState").when(isUseEffectCall, () => "useLayoutEffect").when(isSetStateCall, () => "setState").when(isThenCall, () => "then").otherwise(() => "other");
493
493
  }
494
494
  function getFunctionKind(node) {
495
- return match(node).when(isEffectFunction, () => "effect").when(isFunctionOfImmediatelyInvoked, () => "immediate").otherwise(() => "other");
495
+ return match(node).when(isSetupFunction, () => "setup").when(isFunctionOfImmediatelyInvoked, () => "immediate").otherwise(() => "other");
496
496
  }
497
497
  return {
498
498
  ":function"(node) {
499
499
  const functionKind = getFunctionKind(node);
500
500
  functionStack.push([node, functionKind]);
501
- if (functionKind === "effect") onEffectFunctionEnter(node);
501
+ if (functionKind === "setup") onSetupFunctionEnter(node);
502
502
  },
503
503
  ":function:exit"(node) {
504
504
  const [_, functionKind] = functionStack.at(-1) ?? [];
505
505
  functionStack.pop();
506
- if (functionKind === "effect") onEffectFunctionExit(node);
506
+ if (functionKind === "setup") onSetupFunctionExit(node);
507
507
  },
508
508
  CallExpression(node) {
509
- const effectFn = MutRef.get(effectFunctionRef);
509
+ const effectFn = MutRef.get(setupFunctionRef);
510
510
  const [parentFn, parentFnKind] = functionStack.at(-1) ?? [];
511
511
  if (parentFn?.async) return;
512
512
  match(getCallKind(node)).with("setState", () => {
@@ -531,10 +531,10 @@ var no_direct_set_state_in_use_layout_effect_default = createRule({
531
531
  const [firstArg] = node.arguments;
532
532
  if (isFunction(firstArg)) return;
533
533
  const identifiers = getNestedIdentifiers(node);
534
- effectFunctionIdentifiers.push(...identifiers);
534
+ setupFunctionIdentifiers.push(...identifiers);
535
535
  }).with("other", () => {
536
- const isInEffectFunction = effectFn === parentFn;
537
- if (!isInEffectFunction) return;
536
+ const isInSetupFunction = effectFn === parentFn;
537
+ if (!isInSetupFunction) return;
538
538
  indirectFunctionCalls.push(node);
539
539
  }).otherwise(F.constVoid);
540
540
  },
@@ -604,7 +604,7 @@ var no_direct_set_state_in_use_layout_effect_default = createRule({
604
604
  });
605
605
  }
606
606
  }
607
- for (const id of effectFunctionIdentifiers) {
607
+ for (const id of setupFunctionIdentifiers) {
608
608
  const setStateCalls = getSetStateCalls(id.name, context.sourceCode.getScope(id));
609
609
  for (const setStateCall of setStateCalls) {
610
610
  context.report({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-react-hooks-extra",
3
- "version": "1.10.1-next.4",
3
+ "version": "1.10.1",
4
4
  "description": "ESLint React's ESLint plugin for React Hooks related rules.",
5
5
  "keywords": [
6
6
  "eslint",
@@ -46,13 +46,13 @@
46
46
  "@typescript-eslint/types": "^8.1.0",
47
47
  "@typescript-eslint/utils": "^8.1.0",
48
48
  "ts-pattern": "^5.3.1",
49
- "@eslint-react/core": "1.10.1-next.4",
50
- "@eslint-react/ast": "1.10.1-next.4",
51
- "@eslint-react/jsx": "1.10.1-next.4",
52
- "@eslint-react/shared": "1.10.1-next.4",
53
- "@eslint-react/tools": "1.10.1-next.4",
54
- "@eslint-react/types": "1.10.1-next.4",
55
- "@eslint-react/var": "1.10.1-next.4"
49
+ "@eslint-react/ast": "1.10.1",
50
+ "@eslint-react/core": "1.10.1",
51
+ "@eslint-react/jsx": "1.10.1",
52
+ "@eslint-react/tools": "1.10.1",
53
+ "@eslint-react/var": "1.10.1",
54
+ "@eslint-react/types": "1.10.1",
55
+ "@eslint-react/shared": "1.10.1"
56
56
  },
57
57
  "devDependencies": {
58
58
  "@types/react": "^18.3.3",