@eslint-react/core 2.11.2 → 2.12.0-beta.0

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.d.ts CHANGED
@@ -84,42 +84,24 @@ type ComponentDetectionHint = bigint;
84
84
  * Hints for component collector
85
85
  */
86
86
  declare const ComponentDetectionHint: {
87
- /**
88
- * Skip function component defined on object method
89
- */
90
- readonly SkipObjectMethod: bigint;
91
- /**
92
- * Skip function component defined on class method
93
- */
94
- readonly SkipClassMethod: bigint;
95
- /**
96
- * Skip function component defined on class property
97
- */
98
- readonly SkipClassProperty: bigint;
99
- /**
100
- * Skip function component defined in array pattern
101
- */
102
- readonly SkipArrayPattern: bigint;
103
- /**
104
- * Skip function component defined in array expression
105
- */
106
- readonly SkipArrayExpression: bigint;
107
- /**
108
- * Skip function component defined as array map callback
109
- */
110
- readonly SkipArrayMapCallback: bigint;
87
+ readonly DoNotIncludeFunctionDefinedOnObjectMethod: bigint;
88
+ readonly DoNotIncludeFunctionDefinedOnClassMethod: bigint;
89
+ readonly DoNotIncludeFunctionDefinedOnClassProperty: bigint;
90
+ readonly DoNotIncludeFunctionDefinedInArrayPattern: bigint;
91
+ readonly DoNotIncludeFunctionDefinedInArrayExpression: bigint;
92
+ readonly DoNotIncludeFunctionDefinedAsArrayMapCallback: bigint;
111
93
  readonly None: 0n;
112
- readonly SkipUndefined: bigint;
113
- readonly SkipNullLiteral: bigint;
114
- readonly SkipBooleanLiteral: bigint;
115
- readonly SkipStringLiteral: bigint;
116
- readonly SkipNumberLiteral: bigint;
117
- readonly SkipBigIntLiteral: bigint;
118
- readonly SkipEmptyArray: bigint;
119
- readonly SkipCreateElement: bigint;
120
- readonly StrictArray: bigint;
121
- readonly StrictLogical: bigint;
122
- readonly StrictConditional: bigint;
94
+ readonly DoNotIncludeJsxWithNullValue: bigint;
95
+ readonly DoNotIncludeJsxWithNumberValue: bigint;
96
+ readonly DoNotIncludeJsxWithBigIntValue: bigint;
97
+ readonly DoNotIncludeJsxWithStringValue: bigint;
98
+ readonly DoNotIncludeJsxWithBooleanValue: bigint;
99
+ readonly DoNotIncludeJsxWithUndefinedValue: bigint;
100
+ readonly DoNotIncludeJsxWithEmptyArrayValue: bigint;
101
+ readonly DoNotIncludeJsxWithCreateElementValue: bigint;
102
+ readonly RequireAllArrayElementsToBeJsx: bigint;
103
+ readonly RequireBothSidesOfLogicalExpressionToBeJsx: bigint;
104
+ readonly RequireBothBranchesOfConditionalExpressionToBeJsx: bigint;
123
105
  };
124
106
  /**
125
107
  * Default component detection hint
@@ -561,7 +543,7 @@ type FindEnclosingComponentOrHookFilter = (n: TSESTree.Node, name: string | null
561
543
  * @param test Optional test function to customize component or hook identification
562
544
  * @returns The enclosing component or hook node, or `null` if none is ASAST.
563
545
  */
564
- declare function findEnclosingComponentOrHook(node: TSESTree.Node | unit, test?: FindEnclosingComponentOrHookFilter): TSESTree.ArrowFunctionExpression | TSESTree.FunctionDeclarationWithName | TSESTree.FunctionDeclarationWithOptionalName | TSESTree.FunctionExpression | undefined;
546
+ declare function findEnclosingComponentOrHook(node: TSESTree.Node | unit, test?: FindEnclosingComponentOrHookFilter): TSESTree.ArrowFunctionExpression | TSESTree.FunctionExpression | TSESTree.FunctionDeclarationWithName | TSESTree.FunctionDeclarationWithOptionalName | undefined;
565
547
  //#endregion
566
548
  //#region src/hierarchy/is-inside-component-or-hook.d.ts
567
549
  /**
@@ -759,7 +741,7 @@ declare function resolveJsxAttributeValue(context: RuleContext, attribute: ast.T
759
741
  readonly toStatic: () => string | number | bigint | boolean | RegExp | null;
760
742
  } | {
761
743
  readonly kind: "expression";
762
- readonly node: TSESTree.JSXEmptyExpression | TSESTree.Expression;
744
+ readonly node: TSESTree.Expression | TSESTree.JSXEmptyExpression;
763
745
  readonly toStatic: () => unknown;
764
746
  } | {
765
747
  readonly kind: "element";
@@ -767,7 +749,7 @@ declare function resolveJsxAttributeValue(context: RuleContext, attribute: ast.T
767
749
  readonly toStatic: () => undefined;
768
750
  } | {
769
751
  readonly kind: "spreadChild";
770
- readonly node: TSESTree.JSXEmptyExpression | TSESTree.Expression;
752
+ readonly node: TSESTree.Expression | TSESTree.JSXEmptyExpression;
771
753
  readonly toStatic: () => undefined;
772
754
  } | {
773
755
  readonly kind: "spreadProps";
@@ -815,17 +797,17 @@ declare function getJsxConfigFromAnnotation(context: RuleContext): JsxConfig;
815
797
  type JsxDetectionHint = bigint;
816
798
  declare const JsxDetectionHint: {
817
799
  readonly None: 0n;
818
- readonly SkipUndefined: bigint;
819
- readonly SkipNullLiteral: bigint;
820
- readonly SkipBooleanLiteral: bigint;
821
- readonly SkipStringLiteral: bigint;
822
- readonly SkipNumberLiteral: bigint;
823
- readonly SkipBigIntLiteral: bigint;
824
- readonly SkipEmptyArray: bigint;
825
- readonly SkipCreateElement: bigint;
826
- readonly StrictArray: bigint;
827
- readonly StrictLogical: bigint;
828
- readonly StrictConditional: bigint;
800
+ readonly DoNotIncludeJsxWithNullValue: bigint;
801
+ readonly DoNotIncludeJsxWithNumberValue: bigint;
802
+ readonly DoNotIncludeJsxWithBigIntValue: bigint;
803
+ readonly DoNotIncludeJsxWithStringValue: bigint;
804
+ readonly DoNotIncludeJsxWithBooleanValue: bigint;
805
+ readonly DoNotIncludeJsxWithUndefinedValue: bigint;
806
+ readonly DoNotIncludeJsxWithEmptyArrayValue: bigint;
807
+ readonly DoNotIncludeJsxWithCreateElementValue: bigint;
808
+ readonly RequireAllArrayElementsToBeJsx: bigint;
809
+ readonly RequireBothSidesOfLogicalExpressionToBeJsx: bigint;
810
+ readonly RequireBothBranchesOfConditionalExpressionToBeJsx: bigint;
829
811
  };
830
812
  /**
831
813
  * Default JSX detection configuration
package/dist/index.js CHANGED
@@ -513,23 +513,23 @@ function getJsxConfigFromAnnotation(context) {
513
513
  //#region src/jsx/jsx-detection.ts
514
514
  const JsxDetectionHint = {
515
515
  None: 0n,
516
- SkipUndefined: 1n << 0n,
517
- SkipNullLiteral: 1n << 1n,
518
- SkipBooleanLiteral: 1n << 2n,
519
- SkipStringLiteral: 1n << 3n,
520
- SkipNumberLiteral: 1n << 4n,
521
- SkipBigIntLiteral: 1n << 5n,
522
- SkipEmptyArray: 1n << 6n,
523
- SkipCreateElement: 1n << 7n,
524
- StrictArray: 1n << 8n,
525
- StrictLogical: 1n << 9n,
526
- StrictConditional: 1n << 10n
516
+ DoNotIncludeJsxWithNullValue: 1n << 0n,
517
+ DoNotIncludeJsxWithNumberValue: 1n << 1n,
518
+ DoNotIncludeJsxWithBigIntValue: 1n << 2n,
519
+ DoNotIncludeJsxWithStringValue: 1n << 3n,
520
+ DoNotIncludeJsxWithBooleanValue: 1n << 4n,
521
+ DoNotIncludeJsxWithUndefinedValue: 1n << 5n,
522
+ DoNotIncludeJsxWithEmptyArrayValue: 1n << 6n,
523
+ DoNotIncludeJsxWithCreateElementValue: 1n << 7n,
524
+ RequireAllArrayElementsToBeJsx: 1n << 8n,
525
+ RequireBothSidesOfLogicalExpressionToBeJsx: 1n << 9n,
526
+ RequireBothBranchesOfConditionalExpressionToBeJsx: 1n << 10n
527
527
  };
528
528
  /**
529
529
  * Default JSX detection configuration
530
530
  * Skips undefined and boolean literals (common in React)
531
531
  */
532
- const DEFAULT_JSX_DETECTION_HINT = 0n | JsxDetectionHint.SkipUndefined | JsxDetectionHint.SkipBooleanLiteral;
532
+ const DEFAULT_JSX_DETECTION_HINT = 0n | JsxDetectionHint.DoNotIncludeJsxWithNumberValue | JsxDetectionHint.DoNotIncludeJsxWithBigIntValue | JsxDetectionHint.DoNotIncludeJsxWithBooleanValue | JsxDetectionHint.DoNotIncludeJsxWithStringValue | JsxDetectionHint.DoNotIncludeJsxWithUndefinedValue;
533
533
  /**
534
534
  * Check if a node is a `JSXText` or a `Literal` node
535
535
  * @param node The AST node to check
@@ -555,26 +555,26 @@ function isJsxLike(code, node, hint = DEFAULT_JSX_DETECTION_HINT) {
555
555
  switch (node.type) {
556
556
  case AST_NODE_TYPES.Literal:
557
557
  switch (typeof node.value) {
558
- case "boolean": return !(hint & JsxDetectionHint.SkipBooleanLiteral);
559
- case "string": return !(hint & JsxDetectionHint.SkipStringLiteral);
560
- case "number": return !(hint & JsxDetectionHint.SkipNumberLiteral);
561
- case "bigint": return !(hint & JsxDetectionHint.SkipBigIntLiteral);
558
+ case "boolean": return !(hint & JsxDetectionHint.DoNotIncludeJsxWithBooleanValue);
559
+ case "string": return !(hint & JsxDetectionHint.DoNotIncludeJsxWithStringValue);
560
+ case "number": return !(hint & JsxDetectionHint.DoNotIncludeJsxWithNumberValue);
561
+ case "bigint": return !(hint & JsxDetectionHint.DoNotIncludeJsxWithBigIntValue);
562
562
  }
563
- if (node.value == null) return !(hint & JsxDetectionHint.SkipNullLiteral);
563
+ if (node.value == null) return !(hint & JsxDetectionHint.DoNotIncludeJsxWithNullValue);
564
564
  return false;
565
- case AST_NODE_TYPES.TemplateLiteral: return !(hint & JsxDetectionHint.SkipStringLiteral);
565
+ case AST_NODE_TYPES.TemplateLiteral: return !(hint & JsxDetectionHint.DoNotIncludeJsxWithStringValue);
566
566
  case AST_NODE_TYPES.ArrayExpression:
567
- if (node.elements.length === 0) return !(hint & JsxDetectionHint.SkipEmptyArray);
568
- if (hint & JsxDetectionHint.StrictArray) return node.elements.every((n) => isJsxLike(code, n, hint));
567
+ if (node.elements.length === 0) return !(hint & JsxDetectionHint.DoNotIncludeJsxWithEmptyArrayValue);
568
+ if (hint & JsxDetectionHint.RequireAllArrayElementsToBeJsx) return node.elements.every((n) => isJsxLike(code, n, hint));
569
569
  return node.elements.some((n) => isJsxLike(code, n, hint));
570
570
  case AST_NODE_TYPES.LogicalExpression:
571
- if (hint & JsxDetectionHint.StrictLogical) return isJsxLike(code, node.left, hint) && isJsxLike(code, node.right, hint);
571
+ if (hint & JsxDetectionHint.RequireBothSidesOfLogicalExpressionToBeJsx) return isJsxLike(code, node.left, hint) && isJsxLike(code, node.right, hint);
572
572
  return isJsxLike(code, node.left, hint) || isJsxLike(code, node.right, hint);
573
573
  case AST_NODE_TYPES.ConditionalExpression: {
574
574
  function leftHasJSX(node) {
575
575
  if (Array.isArray(node.consequent)) {
576
- if (node.consequent.length === 0) return !(hint & JsxDetectionHint.SkipEmptyArray);
577
- if (hint & JsxDetectionHint.StrictArray) return node.consequent.every((n) => isJsxLike(code, n, hint));
576
+ if (node.consequent.length === 0) return !(hint & JsxDetectionHint.DoNotIncludeJsxWithEmptyArrayValue);
577
+ if (hint & JsxDetectionHint.RequireAllArrayElementsToBeJsx) return node.consequent.every((n) => isJsxLike(code, n, hint));
578
578
  return node.consequent.some((n) => isJsxLike(code, n, hint));
579
579
  }
580
580
  return isJsxLike(code, node.consequent, hint);
@@ -582,12 +582,12 @@ function isJsxLike(code, node, hint = DEFAULT_JSX_DETECTION_HINT) {
582
582
  function rightHasJSX(node) {
583
583
  return isJsxLike(code, node.alternate, hint);
584
584
  }
585
- if (hint & JsxDetectionHint.StrictConditional) return leftHasJSX(node) && rightHasJSX(node);
585
+ if (hint & JsxDetectionHint.RequireBothBranchesOfConditionalExpressionToBeJsx) return leftHasJSX(node) && rightHasJSX(node);
586
586
  return leftHasJSX(node) || rightHasJSX(node);
587
587
  }
588
588
  case AST_NODE_TYPES.SequenceExpression: return isJsxLike(code, node.expressions.at(-1), hint);
589
589
  case AST_NODE_TYPES.CallExpression:
590
- if (hint & JsxDetectionHint.SkipCreateElement) return false;
590
+ if (hint & JsxDetectionHint.DoNotIncludeJsxWithCreateElementValue) return false;
591
591
  switch (node.callee.type) {
592
592
  case AST_NODE_TYPES.Identifier: return node.callee.name === "createElement";
593
593
  case AST_NODE_TYPES.MemberExpression: return node.callee.property.type === AST_NODE_TYPES.Identifier && node.callee.property.name === "createElement";
@@ -595,7 +595,7 @@ function isJsxLike(code, node, hint = DEFAULT_JSX_DETECTION_HINT) {
595
595
  return false;
596
596
  case AST_NODE_TYPES.Identifier: {
597
597
  const { name } = node;
598
- if (name === "undefined") return !(hint & JsxDetectionHint.SkipUndefined);
598
+ if (name === "undefined") return !(hint & JsxDetectionHint.DoNotIncludeJsxWithUndefinedValue);
599
599
  if (ast.isJSXTagNameExpression(node)) return true;
600
600
  return isJsxLike(code, getVariableDefinitionNode(findVariable(name, code.getScope(node)), 0), hint);
601
601
  }
@@ -672,17 +672,17 @@ function findParentJsxAttribute(node, test = constTrue) {
672
672
  */
673
673
  const ComponentDetectionHint = {
674
674
  ...JsxDetectionHint,
675
- SkipObjectMethod: 1n << 64n,
676
- SkipClassMethod: 1n << 65n,
677
- SkipClassProperty: 1n << 66n,
678
- SkipArrayPattern: 1n << 67n,
679
- SkipArrayExpression: 1n << 68n,
680
- SkipArrayMapCallback: 1n << 69n
675
+ DoNotIncludeFunctionDefinedOnObjectMethod: 1n << 64n,
676
+ DoNotIncludeFunctionDefinedOnClassMethod: 1n << 65n,
677
+ DoNotIncludeFunctionDefinedOnClassProperty: 1n << 66n,
678
+ DoNotIncludeFunctionDefinedInArrayPattern: 1n << 67n,
679
+ DoNotIncludeFunctionDefinedInArrayExpression: 1n << 68n,
680
+ DoNotIncludeFunctionDefinedAsArrayMapCallback: 1n << 69n
681
681
  };
682
682
  /**
683
683
  * Default component detection hint
684
684
  */
685
- const DEFAULT_COMPONENT_DETECTION_HINT = 0n | ComponentDetectionHint.SkipArrayExpression | ComponentDetectionHint.SkipArrayMapCallback | ComponentDetectionHint.SkipArrayPattern | ComponentDetectionHint.SkipBooleanLiteral | ComponentDetectionHint.SkipEmptyArray | ComponentDetectionHint.SkipNumberLiteral | ComponentDetectionHint.SkipStringLiteral | ComponentDetectionHint.SkipUndefined | ComponentDetectionHint.StrictArray | ComponentDetectionHint.StrictConditional | ComponentDetectionHint.StrictLogical;
685
+ const DEFAULT_COMPONENT_DETECTION_HINT = 0n | ComponentDetectionHint.DoNotIncludeJsxWithBigIntValue | ComponentDetectionHint.DoNotIncludeJsxWithBooleanValue | ComponentDetectionHint.DoNotIncludeJsxWithNumberValue | ComponentDetectionHint.DoNotIncludeJsxWithStringValue | ComponentDetectionHint.DoNotIncludeJsxWithUndefinedValue | ComponentDetectionHint.DoNotIncludeFunctionDefinedAsArrayMapCallback | ComponentDetectionHint.DoNotIncludeFunctionDefinedInArrayExpression | ComponentDetectionHint.DoNotIncludeFunctionDefinedInArrayPattern | ComponentDetectionHint.RequireAllArrayElementsToBeJsx | ComponentDetectionHint.RequireBothBranchesOfConditionalExpressionToBeJsx | ComponentDetectionHint.RequireBothSidesOfLogicalExpressionToBeJsx;
686
686
 
687
687
  //#endregion
688
688
  //#region src/component/component-is.ts
@@ -859,12 +859,12 @@ function isRenderMethodCallback(node) {
859
859
  */
860
860
  function shouldExcludeBasedOnHint(node, hint) {
861
861
  switch (true) {
862
- case hint & ComponentDetectionHint.SkipObjectMethod && ast.isOneOf([AST_NODE_TYPES.ArrowFunctionExpression, AST_NODE_TYPES.FunctionExpression])(node) && node.parent.type === AST_NODE_TYPES.Property && node.parent.parent.type === AST_NODE_TYPES.ObjectExpression: return true;
863
- case hint & ComponentDetectionHint.SkipClassMethod && ast.isOneOf([AST_NODE_TYPES.ArrowFunctionExpression, AST_NODE_TYPES.FunctionExpression])(node) && node.parent.type === AST_NODE_TYPES.MethodDefinition: return true;
864
- case hint & ComponentDetectionHint.SkipClassProperty && ast.isOneOf([AST_NODE_TYPES.ArrowFunctionExpression, AST_NODE_TYPES.FunctionExpression])(node) && node.parent.type === AST_NODE_TYPES.Property: return true;
865
- case hint & ComponentDetectionHint.SkipArrayPattern && node.parent.type === AST_NODE_TYPES.ArrayPattern: return true;
866
- case hint & ComponentDetectionHint.SkipArrayExpression && node.parent.type === AST_NODE_TYPES.ArrayExpression: return true;
867
- case hint & ComponentDetectionHint.SkipArrayMapCallback && node.parent.type === AST_NODE_TYPES.CallExpression && node.parent.callee.type === AST_NODE_TYPES.MemberExpression && node.parent.callee.property.type === AST_NODE_TYPES.Identifier && node.parent.callee.property.name === "map": return true;
862
+ case hint & ComponentDetectionHint.DoNotIncludeFunctionDefinedOnObjectMethod && ast.isOneOf([AST_NODE_TYPES.ArrowFunctionExpression, AST_NODE_TYPES.FunctionExpression])(node) && node.parent.type === AST_NODE_TYPES.Property && node.parent.parent.type === AST_NODE_TYPES.ObjectExpression: return true;
863
+ case hint & ComponentDetectionHint.DoNotIncludeFunctionDefinedOnClassMethod && ast.isOneOf([AST_NODE_TYPES.ArrowFunctionExpression, AST_NODE_TYPES.FunctionExpression])(node) && node.parent.type === AST_NODE_TYPES.MethodDefinition: return true;
864
+ case hint & ComponentDetectionHint.DoNotIncludeFunctionDefinedOnClassProperty && ast.isOneOf([AST_NODE_TYPES.ArrowFunctionExpression, AST_NODE_TYPES.FunctionExpression])(node) && node.parent.type === AST_NODE_TYPES.Property: return true;
865
+ case hint & ComponentDetectionHint.DoNotIncludeFunctionDefinedInArrayPattern && node.parent.type === AST_NODE_TYPES.ArrayPattern: return true;
866
+ case hint & ComponentDetectionHint.DoNotIncludeFunctionDefinedInArrayExpression && node.parent.type === AST_NODE_TYPES.ArrayExpression: return true;
867
+ case hint & ComponentDetectionHint.DoNotIncludeFunctionDefinedAsArrayMapCallback && node.parent.type === AST_NODE_TYPES.CallExpression && node.parent.callee.type === AST_NODE_TYPES.MemberExpression && node.parent.callee.property.type === AST_NODE_TYPES.Identifier && node.parent.callee.property.name === "map": return true;
868
868
  }
869
869
  return false;
870
870
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eslint-react/core",
3
- "version": "2.11.2",
3
+ "version": "2.12.0-beta.0",
4
4
  "description": "ESLint React's ESLint utility module for static analysis of React core APIs and patterns.",
5
5
  "homepage": "https://github.com/Rel1cx/eslint-react",
6
6
  "bugs": {
@@ -34,17 +34,17 @@
34
34
  "@typescript-eslint/types": "^8.54.0",
35
35
  "@typescript-eslint/utils": "^8.54.0",
36
36
  "ts-pattern": "^5.9.0",
37
- "@eslint-react/ast": "2.11.2",
38
- "@eslint-react/shared": "2.11.2",
39
- "@eslint-react/var": "2.11.2",
40
- "@eslint-react/eff": "2.11.2"
37
+ "@eslint-react/ast": "2.12.0-beta.0",
38
+ "@eslint-react/var": "2.12.0-beta.0",
39
+ "@eslint-react/shared": "2.12.0-beta.0",
40
+ "@eslint-react/eff": "2.12.0-beta.0"
41
41
  },
42
42
  "devDependencies": {
43
43
  "tsdown": "^0.20.3",
44
44
  "@local/configs": "0.0.0"
45
45
  },
46
46
  "peerDependencies": {
47
- "eslint": "^8.57.0 || ^9.0.0",
47
+ "eslint": "^8.57.0 || ^9.0.0 || ^10.0.0",
48
48
  "typescript": ">=4.8.4 <6.0.0"
49
49
  },
50
50
  "engines": {