eslint-plugin-react-hooks-extra 1.6.0-next.2 → 1.6.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
@@ -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.6.0-next.2";
12
+ var version = "1.6.0-next.4";
13
13
  var createRule = shared.createRuleForPlugin("hooks-extra");
14
14
 
15
15
  // src/rules/ensure-custom-hooks-using-other-hooks.ts
@@ -415,20 +415,19 @@ var no_direct_set_state_in_use_effect_default = createRule({
415
415
  }
416
416
  function isCleanUpFunction(_2) {
417
417
  }
418
- function isFromUseStateCall(id) {
419
- return tools.F.pipe(
420
- $(id).with({ type: ast.NodeType.Identifier }, (n2) => tools.O.some(n2.name)).with({
421
- type: ast.NodeType.MemberExpression,
422
- object: { type: ast.NodeType.Identifier }
423
- }, (n2) => tools.O.some(n2.object.name)).otherwise(tools.O.none),
424
- tools.O.flatMap(_var.findVariable(context.sourceCode.getScope(id))),
418
+ function isFromUseStateCall(topLevelId) {
419
+ const useStateCall = tools.F.pipe(
420
+ _var.findVariable(topLevelId, context.sourceCode.getScope(topLevelId)),
425
421
  tools.O.flatMap(_var.getVariableNode(0)),
426
422
  tools.O.filter(ast.is(ast.NodeType.CallExpression)),
427
- tools.O.exists(isUseStateCallWithAlias)
423
+ tools.O.filter(isUseStateCallWithAlias)
428
424
  );
425
+ if (tools.O.isNone(useStateCall)) return false;
426
+ const { parent } = useStateCall.value;
427
+ return !a({ id: { elements: [{ name: topLevelId.name }] } }, parent);
429
428
  }
430
429
  function isSetStateCall(node) {
431
- const id = $(node.callee).with({ type: ast.NodeType.Identifier }, tools.O.some).with({ type: ast.NodeType.MemberExpression }, (n2) => {
430
+ const topLevelId = $(node.callee).with({ type: ast.NodeType.Identifier }, tools.O.some).with({ type: ast.NodeType.MemberExpression }, (n2) => {
432
431
  if (!("name" in n2.object)) return tools.O.none();
433
432
  const initialScope = context.sourceCode.getScope(n2);
434
433
  const property = astUtils.getStaticValue(n2.property, initialScope);
@@ -451,7 +450,7 @@ var no_direct_set_state_in_use_effect_default = createRule({
451
450
  if (value?.value === 1) return tools.O.fromNullable(n2.callee.object);
452
451
  return tools.O.none();
453
452
  }).otherwise(tools.O.none);
454
- return tools.O.exists(id, isFromUseStateCall);
453
+ return tools.O.exists(topLevelId, isFromUseStateCall);
455
454
  }
456
455
  function isThenCall(node) {
457
456
  if (node.callee.type !== ast.NodeType.MemberExpression) return false;
@@ -579,20 +578,19 @@ var no_direct_set_state_in_use_layout_effect_default = createRule({
579
578
  }
580
579
  function isCleanUpFunction(_2) {
581
580
  }
582
- function isFromUseStateCall(id) {
583
- return tools.F.pipe(
584
- $(id).with({ type: ast.NodeType.Identifier }, (n2) => tools.O.some(n2.name)).with({
585
- type: ast.NodeType.MemberExpression,
586
- object: { type: ast.NodeType.Identifier }
587
- }, (n2) => tools.O.some(n2.object.name)).otherwise(tools.O.none),
588
- tools.O.flatMap(_var.findVariable(context.sourceCode.getScope(id))),
581
+ function isFromUseStateCall(topLevelId) {
582
+ const useStateCall = tools.F.pipe(
583
+ _var.findVariable(topLevelId, context.sourceCode.getScope(topLevelId)),
589
584
  tools.O.flatMap(_var.getVariableNode(0)),
590
585
  tools.O.filter(ast.is(ast.NodeType.CallExpression)),
591
- tools.O.exists(isUseStateCallWithAlias)
586
+ tools.O.filter(isUseStateCallWithAlias)
592
587
  );
588
+ if (tools.O.isNone(useStateCall)) return false;
589
+ const { parent } = useStateCall.value;
590
+ return !a({ id: { elements: [{ name: topLevelId.name }] } }, parent);
593
591
  }
594
592
  function isSetStateCall(node) {
595
- const id = $(node.callee).with({ type: ast.NodeType.Identifier }, tools.O.some).with({ type: ast.NodeType.MemberExpression }, (n2) => {
593
+ const topLevelId = $(node.callee).with({ type: ast.NodeType.Identifier }, tools.O.some).with({ type: ast.NodeType.MemberExpression }, (n2) => {
596
594
  if (!("name" in n2.object)) return tools.O.none();
597
595
  const initialScope = context.sourceCode.getScope(n2);
598
596
  const property = astUtils.getStaticValue(n2.property, initialScope);
@@ -615,7 +613,7 @@ var no_direct_set_state_in_use_layout_effect_default = createRule({
615
613
  if (value?.value === 1) return tools.O.fromNullable(n2.callee.object);
616
614
  return tools.O.none();
617
615
  }).otherwise(tools.O.none);
618
- return tools.O.exists(id, isFromUseStateCall);
616
+ return tools.O.exists(topLevelId, isFromUseStateCall);
619
617
  }
620
618
  function isThenCall(node) {
621
619
  if (node.callee.type !== ast.NodeType.MemberExpression) return false;
package/dist/index.mjs CHANGED
@@ -7,7 +7,7 @@ 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.6.0-next.2";
10
+ var version = "1.6.0-next.4";
11
11
  var createRule = createRuleForPlugin("hooks-extra");
12
12
 
13
13
  // src/rules/ensure-custom-hooks-using-other-hooks.ts
@@ -413,20 +413,19 @@ var no_direct_set_state_in_use_effect_default = createRule({
413
413
  }
414
414
  function isCleanUpFunction(_2) {
415
415
  }
416
- function isFromUseStateCall(id) {
417
- return F.pipe(
418
- $(id).with({ type: NodeType.Identifier }, (n2) => O.some(n2.name)).with({
419
- type: NodeType.MemberExpression,
420
- object: { type: NodeType.Identifier }
421
- }, (n2) => O.some(n2.object.name)).otherwise(O.none),
422
- O.flatMap(findVariable(context.sourceCode.getScope(id))),
416
+ function isFromUseStateCall(topLevelId) {
417
+ const useStateCall = F.pipe(
418
+ findVariable(topLevelId, context.sourceCode.getScope(topLevelId)),
423
419
  O.flatMap(getVariableNode(0)),
424
420
  O.filter(is(NodeType.CallExpression)),
425
- O.exists(isUseStateCallWithAlias)
421
+ O.filter(isUseStateCallWithAlias)
426
422
  );
423
+ if (O.isNone(useStateCall)) return false;
424
+ const { parent } = useStateCall.value;
425
+ return !a({ id: { elements: [{ name: topLevelId.name }] } }, parent);
427
426
  }
428
427
  function isSetStateCall(node) {
429
- const id = $(node.callee).with({ type: NodeType.Identifier }, O.some).with({ type: NodeType.MemberExpression }, (n2) => {
428
+ const topLevelId = $(node.callee).with({ type: NodeType.Identifier }, O.some).with({ type: NodeType.MemberExpression }, (n2) => {
430
429
  if (!("name" in n2.object)) return O.none();
431
430
  const initialScope = context.sourceCode.getScope(n2);
432
431
  const property = getStaticValue(n2.property, initialScope);
@@ -449,7 +448,7 @@ var no_direct_set_state_in_use_effect_default = createRule({
449
448
  if (value?.value === 1) return O.fromNullable(n2.callee.object);
450
449
  return O.none();
451
450
  }).otherwise(O.none);
452
- return O.exists(id, isFromUseStateCall);
451
+ return O.exists(topLevelId, isFromUseStateCall);
453
452
  }
454
453
  function isThenCall(node) {
455
454
  if (node.callee.type !== NodeType.MemberExpression) return false;
@@ -577,20 +576,19 @@ var no_direct_set_state_in_use_layout_effect_default = createRule({
577
576
  }
578
577
  function isCleanUpFunction(_2) {
579
578
  }
580
- function isFromUseStateCall(id) {
581
- return F.pipe(
582
- $(id).with({ type: NodeType.Identifier }, (n2) => O.some(n2.name)).with({
583
- type: NodeType.MemberExpression,
584
- object: { type: NodeType.Identifier }
585
- }, (n2) => O.some(n2.object.name)).otherwise(O.none),
586
- O.flatMap(findVariable(context.sourceCode.getScope(id))),
579
+ function isFromUseStateCall(topLevelId) {
580
+ const useStateCall = F.pipe(
581
+ findVariable(topLevelId, context.sourceCode.getScope(topLevelId)),
587
582
  O.flatMap(getVariableNode(0)),
588
583
  O.filter(is(NodeType.CallExpression)),
589
- O.exists(isUseStateCallWithAlias)
584
+ O.filter(isUseStateCallWithAlias)
590
585
  );
586
+ if (O.isNone(useStateCall)) return false;
587
+ const { parent } = useStateCall.value;
588
+ return !a({ id: { elements: [{ name: topLevelId.name }] } }, parent);
591
589
  }
592
590
  function isSetStateCall(node) {
593
- const id = $(node.callee).with({ type: NodeType.Identifier }, O.some).with({ type: NodeType.MemberExpression }, (n2) => {
591
+ const topLevelId = $(node.callee).with({ type: NodeType.Identifier }, O.some).with({ type: NodeType.MemberExpression }, (n2) => {
594
592
  if (!("name" in n2.object)) return O.none();
595
593
  const initialScope = context.sourceCode.getScope(n2);
596
594
  const property = getStaticValue(n2.property, initialScope);
@@ -613,7 +611,7 @@ var no_direct_set_state_in_use_layout_effect_default = createRule({
613
611
  if (value?.value === 1) return O.fromNullable(n2.callee.object);
614
612
  return O.none();
615
613
  }).otherwise(O.none);
616
- return O.exists(id, isFromUseStateCall);
614
+ return O.exists(topLevelId, isFromUseStateCall);
617
615
  }
618
616
  function isThenCall(node) {
619
617
  if (node.callee.type !== NodeType.MemberExpression) return false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-react-hooks-extra",
3
- "version": "1.6.0-next.2",
3
+ "version": "1.6.0-next.4",
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.17.0",
40
40
  "@typescript-eslint/types": "^7.17.0",
41
41
  "@typescript-eslint/utils": "^7.17.0",
42
- "@eslint-react/ast": "1.6.0-next.2",
43
- "@eslint-react/core": "1.6.0-next.2",
44
- "@eslint-react/jsx": "1.6.0-next.2",
45
- "@eslint-react/shared": "1.6.0-next.2",
46
- "@eslint-react/var": "1.6.0-next.2",
47
- "@eslint-react/types": "1.6.0-next.2",
48
- "@eslint-react/tools": "1.6.0-next.2"
42
+ "@eslint-react/ast": "1.6.0-next.4",
43
+ "@eslint-react/jsx": "1.6.0-next.4",
44
+ "@eslint-react/core": "1.6.0-next.4",
45
+ "@eslint-react/shared": "1.6.0-next.4",
46
+ "@eslint-react/tools": "1.6.0-next.4",
47
+ "@eslint-react/types": "1.6.0-next.4",
48
+ "@eslint-react/var": "1.6.0-next.4"
49
49
  },
50
50
  "devDependencies": {
51
51
  "@types/react": "^18.3.3",