@eslint-react/core 3.0.0-next.48 → 3.0.0-next.49

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.
Files changed (2) hide show
  1. package/dist/index.js +27 -34
  2. package/package.json +5 -5
package/dist/index.js CHANGED
@@ -909,38 +909,6 @@ const ComponentDetectionHint = {
909
909
  */
910
910
  const DEFAULT_COMPONENT_DETECTION_HINT = 0n | ComponentDetectionHint.DoNotIncludeJsxWithBigIntValue | ComponentDetectionHint.DoNotIncludeJsxWithBooleanValue | ComponentDetectionHint.DoNotIncludeJsxWithNumberValue | ComponentDetectionHint.DoNotIncludeJsxWithStringValue | ComponentDetectionHint.DoNotIncludeJsxWithUndefinedValue | ComponentDetectionHint.DoNotIncludeFunctionDefinedAsArrayFlatMapCallback | ComponentDetectionHint.DoNotIncludeFunctionDefinedAsArrayMapCallback | ComponentDetectionHint.DoNotIncludeFunctionDefinedInArrayExpression | ComponentDetectionHint.DoNotIncludeFunctionDefinedInArrayPattern | ComponentDetectionHint.RequireAllArrayElementsToBeJsx | ComponentDetectionHint.RequireBothBranchesOfConditionalExpressionToBeJsx | ComponentDetectionHint.RequireBothSidesOfLogicalExpressionToBeJsx;
911
911
  /**
912
- * Check if a function node should be excluded based on provided detection hints
913
- *
914
- * @param node The function node to check
915
- * @param hint Component detection hints as bit flags
916
- * @returns `true` if the function matches an exclusion hint
917
- */
918
- function shouldExcludeBasedOnHint(node, hint) {
919
- switch (true) {
920
- case 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 !!(hint & ComponentDetectionHint.DoNotIncludeFunctionDefinedOnObjectMethod);
921
- case ast.isOneOf([AST_NODE_TYPES.ArrowFunctionExpression, AST_NODE_TYPES.FunctionExpression])(node) && node.parent.type === AST_NODE_TYPES.MethodDefinition: return !!(hint & ComponentDetectionHint.DoNotIncludeFunctionDefinedOnClassMethod);
922
- case ast.isOneOf([AST_NODE_TYPES.ArrowFunctionExpression, AST_NODE_TYPES.FunctionExpression])(node) && node.parent.type === AST_NODE_TYPES.Property: return !!(hint & ComponentDetectionHint.DoNotIncludeFunctionDefinedOnClassProperty);
923
- case node.parent.type === AST_NODE_TYPES.ArrayPattern: return !!(hint & ComponentDetectionHint.DoNotIncludeFunctionDefinedInArrayPattern);
924
- case node.parent.type === AST_NODE_TYPES.ArrayExpression: return !!(hint & ComponentDetectionHint.DoNotIncludeFunctionDefinedInArrayExpression);
925
- case 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 !!(hint & ComponentDetectionHint.DoNotIncludeFunctionDefinedAsArrayMapCallback);
926
- case 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 === "flatMap": return !!(hint & ComponentDetectionHint.DoNotIncludeFunctionDefinedAsArrayFlatMapCallback);
927
- }
928
- return false;
929
- }
930
- /**
931
- * Determine if the node is an argument within `createElement`'s children list (3rd argument onwards)
932
- *
933
- * @param context The rule context
934
- * @param node The AST node to check
935
- * @returns `true` if the node is passed as a child to `createElement`
936
- */
937
- function isChildrenOfCreateElement(context, node) {
938
- const parent = node.parent;
939
- if (parent?.type !== AST_NODE_TYPES.CallExpression) return false;
940
- if (!isCreateElementCall(context, parent)) return false;
941
- return parent.arguments.slice(2).some((arg) => arg === node);
942
- }
943
- /**
944
912
  * Determine if a function node represents a valid React component definition
945
913
  *
946
914
  * @param context The rule context
@@ -950,8 +918,33 @@ function isChildrenOfCreateElement(context, node) {
950
918
  */
951
919
  function isComponentDefinition(context, node, hint) {
952
920
  if (!isFunctionWithLooseComponentName(context, node, true)) return false;
953
- if (isChildrenOfCreateElement(context, node) || isRenderMethodCallback(node)) return false;
954
- if (shouldExcludeBasedOnHint(node, hint)) return false;
921
+ switch (true) {
922
+ case node.parent.type === AST_NODE_TYPES.CallExpression && isCreateElementCall(context, node.parent) && node.parent.arguments.slice(2).some((arg) => arg === node): return false;
923
+ case isRenderMethodCallback(node): return false;
924
+ }
925
+ switch (true) {
926
+ case 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:
927
+ if (hint & ComponentDetectionHint.DoNotIncludeFunctionDefinedOnObjectMethod) return false;
928
+ break;
929
+ case ast.isOneOf([AST_NODE_TYPES.ArrowFunctionExpression, AST_NODE_TYPES.FunctionExpression])(node) && node.parent.type === AST_NODE_TYPES.MethodDefinition:
930
+ if (hint & ComponentDetectionHint.DoNotIncludeFunctionDefinedOnClassMethod) return false;
931
+ break;
932
+ case ast.isOneOf([AST_NODE_TYPES.ArrowFunctionExpression, AST_NODE_TYPES.FunctionExpression])(node) && node.parent.type === AST_NODE_TYPES.Property:
933
+ if (hint & ComponentDetectionHint.DoNotIncludeFunctionDefinedOnClassProperty) return false;
934
+ break;
935
+ case node.parent.type === AST_NODE_TYPES.ArrayPattern:
936
+ if (hint & ComponentDetectionHint.DoNotIncludeFunctionDefinedInArrayPattern) return false;
937
+ break;
938
+ case node.parent.type === AST_NODE_TYPES.ArrayExpression:
939
+ if (hint & ComponentDetectionHint.DoNotIncludeFunctionDefinedInArrayExpression) return false;
940
+ break;
941
+ case 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":
942
+ if (hint & ComponentDetectionHint.DoNotIncludeFunctionDefinedAsArrayMapCallback) return false;
943
+ break;
944
+ case 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 === "flatMap":
945
+ if (hint & ComponentDetectionHint.DoNotIncludeFunctionDefinedAsArrayFlatMapCallback) return false;
946
+ break;
947
+ }
955
948
  const significantParent = ast.findParentNode(node, ast.isOneOf([
956
949
  AST_NODE_TYPES.JSXExpressionContainer,
957
950
  AST_NODE_TYPES.ArrowFunctionExpression,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eslint-react/core",
3
- "version": "3.0.0-next.48",
3
+ "version": "3.0.0-next.49",
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,10 +34,10 @@
34
34
  "@typescript-eslint/types": "canary",
35
35
  "@typescript-eslint/utils": "canary",
36
36
  "ts-pattern": "^5.9.0",
37
- "@eslint-react/eff": "3.0.0-next.48",
38
- "@eslint-react/ast": "3.0.0-next.48",
39
- "@eslint-react/shared": "3.0.0-next.48",
40
- "@eslint-react/var": "3.0.0-next.48"
37
+ "@eslint-react/ast": "3.0.0-next.49",
38
+ "@eslint-react/var": "3.0.0-next.49",
39
+ "@eslint-react/shared": "3.0.0-next.49",
40
+ "@eslint-react/eff": "3.0.0-next.49"
41
41
  },
42
42
  "devDependencies": {
43
43
  "tsdown": "^0.20.3",