eslint-plugin-react-hooks-extra 1.5.28-beta.3 → 1.5.28-beta.5

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
@@ -9,7 +9,7 @@ var astUtils = require('@typescript-eslint/utils/ast-utils');
9
9
 
10
10
  // package.json
11
11
  var name = "eslint-plugin-react-hooks-extra";
12
- var version = "1.5.28-beta.3";
12
+ var version = "1.5.28-beta.5";
13
13
  var createRule = shared.createRuleForPlugin("hooks-extra");
14
14
 
15
15
  // src/rules/ensure-custom-hooks-using-other-hooks.ts
@@ -470,20 +470,24 @@ var no_direct_set_state_in_use_effect_default = createRule({
470
470
  const functionStack = tools.MutList.make();
471
471
  const effectFunctionRef = tools.MutRef.make(null);
472
472
  const cleanUpFunctionRef = tools.MutRef.make(null);
473
- const indirectFunctionCalls = [];
473
+ const indirectFunctionCalls = tools.MutRef.make(tools.Chunk.empty());
474
474
  const indirectSetStateCalls = /* @__PURE__ */ new Map();
475
475
  return {
476
- Identifier(node) {
477
- const isInUseEffectCall = tools.MutRef.get(useEffectCallRef) !== null;
478
- const parentFn = tools.MutList.tail(functionStack)?.[0];
479
- const useEffectCall = tools.MutRef.get(useEffectCallRef);
480
- const isEffectFunction2 = useEffectCall && tools.O.isSome(ast.traverseUp(useEffectCall, (n2) => n2 === parentFn));
481
- if (isFromUseStateCall(node) && isInUseEffectCall && isEffectFunction2) {
482
- context.report({
483
- node,
484
- messageId: "NO_DIRECT_SET_STATE_IN_USE_EFFECT"
485
- });
476
+ ":function"(node) {
477
+ const functionKind = getFunctionKind(node);
478
+ tools.MutList.append(functionStack, [node, functionKind]);
479
+ $(functionKind).with("effect", () => {
480
+ tools.MutRef.set(effectFunctionRef, node);
481
+ }).with("cleanup", () => {
482
+ tools.MutRef.set(cleanUpFunctionRef, node);
483
+ }).otherwise(tools.F.constVoid);
484
+ },
485
+ ":function:exit"(node) {
486
+ const effectFn = tools.MutRef.get(effectFunctionRef);
487
+ if (effectFn === node) {
488
+ tools.MutRef.set(effectFunctionRef, null);
486
489
  }
490
+ tools.MutList.pop(functionStack);
487
491
  },
488
492
  CallExpression(node) {
489
493
  const effectFn = tools.MutRef.get(effectFunctionRef);
@@ -493,42 +497,27 @@ var no_direct_set_state_in_use_effect_default = createRule({
493
497
  $(callKind).with("setState", () => {
494
498
  if (!parentFn) return;
495
499
  if (parentFn !== effectFn && parentFnKind !== "immediate") {
496
- indirectSetStateCalls.set(parentFn, [...indirectSetStateCalls.get(parentFn) ?? [], node]);
500
+ const calls = indirectSetStateCalls.get(parentFn) ?? tools.Chunk.empty();
501
+ indirectSetStateCalls.set(parentFn, tools.Chunk.append(calls, node));
497
502
  return;
498
503
  }
499
504
  context.report({
500
- node,
501
- messageId: "NO_DIRECT_SET_STATE_IN_USE_EFFECT"
505
+ messageId: "NO_DIRECT_SET_STATE_IN_USE_EFFECT",
506
+ node
502
507
  });
503
508
  }).with("useEffect", () => {
504
509
  tools.MutRef.set(useEffectCallRef, node);
505
510
  }).with("other", () => {
506
- indirectFunctionCalls.push(node);
511
+ tools.MutRef.update(indirectFunctionCalls, tools.Chunk.append(node));
507
512
  }).otherwise(tools.F.constVoid);
508
513
  },
509
- ":function"(node) {
510
- const functionKind = getFunctionKind(node);
511
- tools.MutList.append(functionStack, [node, functionKind]);
512
- $(functionKind).with("effect", () => {
513
- tools.MutRef.set(effectFunctionRef, node);
514
- }).with("cleanup", () => {
515
- tools.MutRef.set(cleanUpFunctionRef, node);
516
- }).otherwise(tools.F.constVoid);
517
- },
518
- ":function:exit"(node) {
519
- const effectFn = tools.MutRef.get(effectFunctionRef);
520
- if (effectFn === node) {
521
- tools.MutRef.set(effectFunctionRef, null);
522
- }
523
- tools.MutList.pop(functionStack);
524
- },
525
514
  "CallExpression:exit"(node) {
526
515
  if (tools.MutRef.get(useEffectCallRef) === node) {
527
516
  tools.MutRef.set(useEffectCallRef, null);
528
517
  }
529
518
  },
530
519
  "Program:exit"() {
531
- for (const call of indirectFunctionCalls) {
520
+ for (const call of tools.Chunk.toReadonlyArray(tools.MutRef.get(indirectFunctionCalls))) {
532
521
  if (!("name" in call.callee)) continue;
533
522
  const { name: name2 } = call.callee;
534
523
  const setStateCalls = tools.F.pipe(
@@ -536,6 +525,7 @@ var no_direct_set_state_in_use_effect_default = createRule({
536
525
  tools.O.flatMap(_var.getVariableInit(0)),
537
526
  tools.O.filter(ast.isFunction),
538
527
  tools.O.flatMapNullable((init) => indirectSetStateCalls.get(init)),
528
+ tools.O.map(tools.Chunk.toReadonlyArray),
539
529
  tools.O.getOrElse(() => [])
540
530
  );
541
531
  for (const setStateCall of setStateCalls) {
@@ -635,20 +625,24 @@ var no_direct_set_state_in_use_layout_effect_default = createRule({
635
625
  const functionStack = tools.MutList.make();
636
626
  const effectFunctionRef = tools.MutRef.make(null);
637
627
  const cleanUpFunctionRef = tools.MutRef.make(null);
638
- const indirectFunctionCalls = [];
628
+ const indirectFunctionCalls = tools.MutRef.make(tools.Chunk.empty());
639
629
  const indirectSetStateCalls = /* @__PURE__ */ new Map();
640
630
  return {
641
- Identifier(node) {
642
- const isInUseLayoutEffectCall = tools.MutRef.get(useLayoutEffectCallRef) !== null;
643
- const parentFn = tools.MutList.tail(functionStack)?.[0];
644
- const useLayoutEffectCall = tools.MutRef.get(useLayoutEffectCallRef);
645
- const isEffectFunction2 = useLayoutEffectCall && tools.O.isSome(ast.traverseUp(useLayoutEffectCall, (n2) => n2 === parentFn));
646
- if (isFromUseStateCall(node) && isInUseLayoutEffectCall && isEffectFunction2) {
647
- context.report({
648
- node,
649
- messageId: "NO_DIRECT_SET_STATE_IN_USE_LAYOUT_EFFECT"
650
- });
631
+ ":function"(node) {
632
+ const functionKind = getFunctionKind(node);
633
+ tools.MutList.append(functionStack, [node, functionKind]);
634
+ $(functionKind).with("effect", () => {
635
+ tools.MutRef.set(effectFunctionRef, node);
636
+ }).with("cleanup", () => {
637
+ tools.MutRef.set(cleanUpFunctionRef, node);
638
+ }).otherwise(tools.F.constVoid);
639
+ },
640
+ ":function:exit"(node) {
641
+ const effectFn = tools.MutRef.get(effectFunctionRef);
642
+ if (effectFn === node) {
643
+ tools.MutRef.set(effectFunctionRef, null);
651
644
  }
645
+ tools.MutList.pop(functionStack);
652
646
  },
653
647
  CallExpression(node) {
654
648
  const effectFn = tools.MutRef.get(effectFunctionRef);
@@ -658,42 +652,27 @@ var no_direct_set_state_in_use_layout_effect_default = createRule({
658
652
  $(callKind).with("setState", () => {
659
653
  if (!parentFn) return;
660
654
  if (parentFn !== effectFn && parentFnKind !== "immediate") {
661
- indirectSetStateCalls.set(parentFn, [...indirectSetStateCalls.get(parentFn) ?? [], node]);
655
+ const calls = indirectSetStateCalls.get(parentFn) ?? tools.Chunk.empty();
656
+ indirectSetStateCalls.set(parentFn, tools.Chunk.append(calls, node));
662
657
  return;
663
658
  }
664
659
  context.report({
665
- node,
666
- messageId: "NO_DIRECT_SET_STATE_IN_USE_LAYOUT_EFFECT"
660
+ messageId: "NO_DIRECT_SET_STATE_IN_USE_LAYOUT_EFFECT",
661
+ node
667
662
  });
668
663
  }).with("useLayoutEffect", () => {
669
664
  tools.MutRef.set(useLayoutEffectCallRef, node);
670
665
  }).with("other", () => {
671
- indirectFunctionCalls.push(node);
666
+ tools.MutRef.update(indirectFunctionCalls, tools.Chunk.append(node));
672
667
  }).otherwise(tools.F.constVoid);
673
668
  },
674
- ":function"(node) {
675
- const functionKind = getFunctionKind(node);
676
- tools.MutList.append(functionStack, [node, functionKind]);
677
- $(functionKind).with("effect", () => {
678
- tools.MutRef.set(effectFunctionRef, node);
679
- }).with("cleanup", () => {
680
- tools.MutRef.set(cleanUpFunctionRef, node);
681
- }).otherwise(tools.F.constVoid);
682
- },
683
- ":function:exit"(node) {
684
- const effectFn = tools.MutRef.get(effectFunctionRef);
685
- if (effectFn === node) {
686
- tools.MutRef.set(effectFunctionRef, null);
687
- }
688
- tools.MutList.pop(functionStack);
689
- },
690
669
  "CallExpression:exit"(node) {
691
670
  if (tools.MutRef.get(useLayoutEffectCallRef) === node) {
692
671
  tools.MutRef.set(useLayoutEffectCallRef, null);
693
672
  }
694
673
  },
695
674
  "Program:exit"() {
696
- for (const call of indirectFunctionCalls) {
675
+ for (const call of tools.Chunk.toReadonlyArray(tools.MutRef.get(indirectFunctionCalls))) {
697
676
  if (!("name" in call.callee)) continue;
698
677
  const { name: name2 } = call.callee;
699
678
  const setStateCalls = tools.F.pipe(
@@ -701,6 +680,7 @@ var no_direct_set_state_in_use_layout_effect_default = createRule({
701
680
  tools.O.flatMap(_var.getVariableInit(0)),
702
681
  tools.O.filter(ast.isFunction),
703
682
  tools.O.flatMapNullable((init) => indirectSetStateCalls.get(init)),
683
+ tools.O.map(tools.Chunk.toReadonlyArray),
704
684
  tools.O.getOrElse(() => [])
705
685
  );
706
686
  for (const setStateCall of setStateCalls) {
package/dist/index.mjs CHANGED
@@ -1,13 +1,13 @@
1
1
  import { useHookCollector, isReactHookCall, isUseCallbackCall, isReactHookCallWithNameLoose, isUseMemoCall, isUseStateCall, isUseEffectCall, isUseLayoutEffectCall } from '@eslint-react/core';
2
2
  import { createRuleForPlugin, getESLintReactSettings } from '@eslint-react/shared';
3
- import { isFunction, NodeType, is, traverseUp, getNestedCallExpressions, isIIFE } from '@eslint-react/ast';
4
- import { F, O, MutRef, MutList } from '@eslint-react/tools';
3
+ import { isFunction, NodeType, is, getNestedCallExpressions, isIIFE } from '@eslint-react/ast';
4
+ import { F, O, MutRef, MutList, Chunk } from '@eslint-react/tools';
5
5
  import { findVariable, getVariableInit } from '@eslint-react/var';
6
6
  import { getStaticValue } from '@typescript-eslint/utils/ast-utils';
7
7
 
8
8
  // package.json
9
9
  var name = "eslint-plugin-react-hooks-extra";
10
- var version = "1.5.28-beta.3";
10
+ var version = "1.5.28-beta.5";
11
11
  var createRule = createRuleForPlugin("hooks-extra");
12
12
 
13
13
  // src/rules/ensure-custom-hooks-using-other-hooks.ts
@@ -468,20 +468,24 @@ var no_direct_set_state_in_use_effect_default = createRule({
468
468
  const functionStack = MutList.make();
469
469
  const effectFunctionRef = MutRef.make(null);
470
470
  const cleanUpFunctionRef = MutRef.make(null);
471
- const indirectFunctionCalls = [];
471
+ const indirectFunctionCalls = MutRef.make(Chunk.empty());
472
472
  const indirectSetStateCalls = /* @__PURE__ */ new Map();
473
473
  return {
474
- Identifier(node) {
475
- const isInUseEffectCall = MutRef.get(useEffectCallRef) !== null;
476
- const parentFn = MutList.tail(functionStack)?.[0];
477
- const useEffectCall = MutRef.get(useEffectCallRef);
478
- const isEffectFunction2 = useEffectCall && O.isSome(traverseUp(useEffectCall, (n2) => n2 === parentFn));
479
- if (isFromUseStateCall(node) && isInUseEffectCall && isEffectFunction2) {
480
- context.report({
481
- node,
482
- messageId: "NO_DIRECT_SET_STATE_IN_USE_EFFECT"
483
- });
474
+ ":function"(node) {
475
+ const functionKind = getFunctionKind(node);
476
+ MutList.append(functionStack, [node, functionKind]);
477
+ $(functionKind).with("effect", () => {
478
+ MutRef.set(effectFunctionRef, node);
479
+ }).with("cleanup", () => {
480
+ MutRef.set(cleanUpFunctionRef, node);
481
+ }).otherwise(F.constVoid);
482
+ },
483
+ ":function:exit"(node) {
484
+ const effectFn = MutRef.get(effectFunctionRef);
485
+ if (effectFn === node) {
486
+ MutRef.set(effectFunctionRef, null);
484
487
  }
488
+ MutList.pop(functionStack);
485
489
  },
486
490
  CallExpression(node) {
487
491
  const effectFn = MutRef.get(effectFunctionRef);
@@ -491,42 +495,27 @@ var no_direct_set_state_in_use_effect_default = createRule({
491
495
  $(callKind).with("setState", () => {
492
496
  if (!parentFn) return;
493
497
  if (parentFn !== effectFn && parentFnKind !== "immediate") {
494
- indirectSetStateCalls.set(parentFn, [...indirectSetStateCalls.get(parentFn) ?? [], node]);
498
+ const calls = indirectSetStateCalls.get(parentFn) ?? Chunk.empty();
499
+ indirectSetStateCalls.set(parentFn, Chunk.append(calls, node));
495
500
  return;
496
501
  }
497
502
  context.report({
498
- node,
499
- messageId: "NO_DIRECT_SET_STATE_IN_USE_EFFECT"
503
+ messageId: "NO_DIRECT_SET_STATE_IN_USE_EFFECT",
504
+ node
500
505
  });
501
506
  }).with("useEffect", () => {
502
507
  MutRef.set(useEffectCallRef, node);
503
508
  }).with("other", () => {
504
- indirectFunctionCalls.push(node);
509
+ MutRef.update(indirectFunctionCalls, Chunk.append(node));
505
510
  }).otherwise(F.constVoid);
506
511
  },
507
- ":function"(node) {
508
- const functionKind = getFunctionKind(node);
509
- MutList.append(functionStack, [node, functionKind]);
510
- $(functionKind).with("effect", () => {
511
- MutRef.set(effectFunctionRef, node);
512
- }).with("cleanup", () => {
513
- MutRef.set(cleanUpFunctionRef, node);
514
- }).otherwise(F.constVoid);
515
- },
516
- ":function:exit"(node) {
517
- const effectFn = MutRef.get(effectFunctionRef);
518
- if (effectFn === node) {
519
- MutRef.set(effectFunctionRef, null);
520
- }
521
- MutList.pop(functionStack);
522
- },
523
512
  "CallExpression:exit"(node) {
524
513
  if (MutRef.get(useEffectCallRef) === node) {
525
514
  MutRef.set(useEffectCallRef, null);
526
515
  }
527
516
  },
528
517
  "Program:exit"() {
529
- for (const call of indirectFunctionCalls) {
518
+ for (const call of Chunk.toReadonlyArray(MutRef.get(indirectFunctionCalls))) {
530
519
  if (!("name" in call.callee)) continue;
531
520
  const { name: name2 } = call.callee;
532
521
  const setStateCalls = F.pipe(
@@ -534,6 +523,7 @@ var no_direct_set_state_in_use_effect_default = createRule({
534
523
  O.flatMap(getVariableInit(0)),
535
524
  O.filter(isFunction),
536
525
  O.flatMapNullable((init) => indirectSetStateCalls.get(init)),
526
+ O.map(Chunk.toReadonlyArray),
537
527
  O.getOrElse(() => [])
538
528
  );
539
529
  for (const setStateCall of setStateCalls) {
@@ -633,20 +623,24 @@ var no_direct_set_state_in_use_layout_effect_default = createRule({
633
623
  const functionStack = MutList.make();
634
624
  const effectFunctionRef = MutRef.make(null);
635
625
  const cleanUpFunctionRef = MutRef.make(null);
636
- const indirectFunctionCalls = [];
626
+ const indirectFunctionCalls = MutRef.make(Chunk.empty());
637
627
  const indirectSetStateCalls = /* @__PURE__ */ new Map();
638
628
  return {
639
- Identifier(node) {
640
- const isInUseLayoutEffectCall = MutRef.get(useLayoutEffectCallRef) !== null;
641
- const parentFn = MutList.tail(functionStack)?.[0];
642
- const useLayoutEffectCall = MutRef.get(useLayoutEffectCallRef);
643
- const isEffectFunction2 = useLayoutEffectCall && O.isSome(traverseUp(useLayoutEffectCall, (n2) => n2 === parentFn));
644
- if (isFromUseStateCall(node) && isInUseLayoutEffectCall && isEffectFunction2) {
645
- context.report({
646
- node,
647
- messageId: "NO_DIRECT_SET_STATE_IN_USE_LAYOUT_EFFECT"
648
- });
629
+ ":function"(node) {
630
+ const functionKind = getFunctionKind(node);
631
+ MutList.append(functionStack, [node, functionKind]);
632
+ $(functionKind).with("effect", () => {
633
+ MutRef.set(effectFunctionRef, node);
634
+ }).with("cleanup", () => {
635
+ MutRef.set(cleanUpFunctionRef, node);
636
+ }).otherwise(F.constVoid);
637
+ },
638
+ ":function:exit"(node) {
639
+ const effectFn = MutRef.get(effectFunctionRef);
640
+ if (effectFn === node) {
641
+ MutRef.set(effectFunctionRef, null);
649
642
  }
643
+ MutList.pop(functionStack);
650
644
  },
651
645
  CallExpression(node) {
652
646
  const effectFn = MutRef.get(effectFunctionRef);
@@ -656,42 +650,27 @@ var no_direct_set_state_in_use_layout_effect_default = createRule({
656
650
  $(callKind).with("setState", () => {
657
651
  if (!parentFn) return;
658
652
  if (parentFn !== effectFn && parentFnKind !== "immediate") {
659
- indirectSetStateCalls.set(parentFn, [...indirectSetStateCalls.get(parentFn) ?? [], node]);
653
+ const calls = indirectSetStateCalls.get(parentFn) ?? Chunk.empty();
654
+ indirectSetStateCalls.set(parentFn, Chunk.append(calls, node));
660
655
  return;
661
656
  }
662
657
  context.report({
663
- node,
664
- messageId: "NO_DIRECT_SET_STATE_IN_USE_LAYOUT_EFFECT"
658
+ messageId: "NO_DIRECT_SET_STATE_IN_USE_LAYOUT_EFFECT",
659
+ node
665
660
  });
666
661
  }).with("useLayoutEffect", () => {
667
662
  MutRef.set(useLayoutEffectCallRef, node);
668
663
  }).with("other", () => {
669
- indirectFunctionCalls.push(node);
664
+ MutRef.update(indirectFunctionCalls, Chunk.append(node));
670
665
  }).otherwise(F.constVoid);
671
666
  },
672
- ":function"(node) {
673
- const functionKind = getFunctionKind(node);
674
- MutList.append(functionStack, [node, functionKind]);
675
- $(functionKind).with("effect", () => {
676
- MutRef.set(effectFunctionRef, node);
677
- }).with("cleanup", () => {
678
- MutRef.set(cleanUpFunctionRef, node);
679
- }).otherwise(F.constVoid);
680
- },
681
- ":function:exit"(node) {
682
- const effectFn = MutRef.get(effectFunctionRef);
683
- if (effectFn === node) {
684
- MutRef.set(effectFunctionRef, null);
685
- }
686
- MutList.pop(functionStack);
687
- },
688
667
  "CallExpression:exit"(node) {
689
668
  if (MutRef.get(useLayoutEffectCallRef) === node) {
690
669
  MutRef.set(useLayoutEffectCallRef, null);
691
670
  }
692
671
  },
693
672
  "Program:exit"() {
694
- for (const call of indirectFunctionCalls) {
673
+ for (const call of Chunk.toReadonlyArray(MutRef.get(indirectFunctionCalls))) {
695
674
  if (!("name" in call.callee)) continue;
696
675
  const { name: name2 } = call.callee;
697
676
  const setStateCalls = F.pipe(
@@ -699,6 +678,7 @@ var no_direct_set_state_in_use_layout_effect_default = createRule({
699
678
  O.flatMap(getVariableInit(0)),
700
679
  O.filter(isFunction),
701
680
  O.flatMapNullable((init) => indirectSetStateCalls.get(init)),
681
+ O.map(Chunk.toReadonlyArray),
702
682
  O.getOrElse(() => [])
703
683
  );
704
684
  for (const setStateCall of setStateCalls) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-react-hooks-extra",
3
- "version": "1.5.28-beta.3",
3
+ "version": "1.5.28-beta.5",
4
4
  "description": "ESLint React's ESLint plugin for React Hooks related rules.",
5
5
  "homepage": "https://github.com/rel1cx/eslint-react",
6
6
  "bugs": {
@@ -39,13 +39,13 @@
39
39
  "@typescript-eslint/type-utils": "^7.16.1",
40
40
  "@typescript-eslint/types": "^7.16.1",
41
41
  "@typescript-eslint/utils": "^7.16.1",
42
- "@eslint-react/ast": "1.5.28-beta.3",
43
- "@eslint-react/core": "1.5.28-beta.3",
44
- "@eslint-react/jsx": "1.5.28-beta.3",
45
- "@eslint-react/shared": "1.5.28-beta.3",
46
- "@eslint-react/tools": "1.5.28-beta.3",
47
- "@eslint-react/types": "1.5.28-beta.3",
48
- "@eslint-react/var": "1.5.28-beta.3"
42
+ "@eslint-react/core": "1.5.28-beta.5",
43
+ "@eslint-react/ast": "1.5.28-beta.5",
44
+ "@eslint-react/shared": "1.5.28-beta.5",
45
+ "@eslint-react/jsx": "1.5.28-beta.5",
46
+ "@eslint-react/types": "1.5.28-beta.5",
47
+ "@eslint-react/var": "1.5.28-beta.5",
48
+ "@eslint-react/tools": "1.5.28-beta.5"
49
49
  },
50
50
  "devDependencies": {
51
51
  "string-ts": "2.2.0",