@eslint-react/core
Advanced tools
+27
-34
@@ -912,34 +912,2 @@ import { findImportSource, findProperty, findVariable, getVariableInitializer } from "@eslint-react/var"; | ||
| /** | ||
| * Check if a function node should be excluded based on provided detection hints | ||
| * | ||
| * @param node The function node to check | ||
| * @param hint Component detection hints as bit flags | ||
| * @returns `true` if the function matches an exclusion hint | ||
| */ | ||
| function shouldExcludeBasedOnHint(node, hint) { | ||
| switch (true) { | ||
| 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); | ||
| case ast.isOneOf([AST_NODE_TYPES.ArrowFunctionExpression, AST_NODE_TYPES.FunctionExpression])(node) && node.parent.type === AST_NODE_TYPES.MethodDefinition: return !!(hint & ComponentDetectionHint.DoNotIncludeFunctionDefinedOnClassMethod); | ||
| case ast.isOneOf([AST_NODE_TYPES.ArrowFunctionExpression, AST_NODE_TYPES.FunctionExpression])(node) && node.parent.type === AST_NODE_TYPES.Property: return !!(hint & ComponentDetectionHint.DoNotIncludeFunctionDefinedOnClassProperty); | ||
| case node.parent.type === AST_NODE_TYPES.ArrayPattern: return !!(hint & ComponentDetectionHint.DoNotIncludeFunctionDefinedInArrayPattern); | ||
| case node.parent.type === AST_NODE_TYPES.ArrayExpression: return !!(hint & ComponentDetectionHint.DoNotIncludeFunctionDefinedInArrayExpression); | ||
| 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); | ||
| 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); | ||
| } | ||
| return false; | ||
| } | ||
| /** | ||
| * Determine if the node is an argument within `createElement`'s children list (3rd argument onwards) | ||
| * | ||
| * @param context The rule context | ||
| * @param node The AST node to check | ||
| * @returns `true` if the node is passed as a child to `createElement` | ||
| */ | ||
| function isChildrenOfCreateElement(context, node) { | ||
| const parent = node.parent; | ||
| if (parent?.type !== AST_NODE_TYPES.CallExpression) return false; | ||
| if (!isCreateElementCall(context, parent)) return false; | ||
| return parent.arguments.slice(2).some((arg) => arg === node); | ||
| } | ||
| /** | ||
| * Determine if a function node represents a valid React component definition | ||
@@ -954,4 +922,29 @@ * | ||
| if (!isFunctionWithLooseComponentName(context, node, true)) return false; | ||
| if (isChildrenOfCreateElement(context, node) || isRenderMethodCallback(node)) return false; | ||
| if (shouldExcludeBasedOnHint(node, hint)) return false; | ||
| switch (true) { | ||
| case node.parent.type === AST_NODE_TYPES.CallExpression && isCreateElementCall(context, node.parent) && node.parent.arguments.slice(2).some((arg) => arg === node): return false; | ||
| case isRenderMethodCallback(node): return false; | ||
| } | ||
| switch (true) { | ||
| 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: | ||
| if (hint & ComponentDetectionHint.DoNotIncludeFunctionDefinedOnObjectMethod) return false; | ||
| break; | ||
| case ast.isOneOf([AST_NODE_TYPES.ArrowFunctionExpression, AST_NODE_TYPES.FunctionExpression])(node) && node.parent.type === AST_NODE_TYPES.MethodDefinition: | ||
| if (hint & ComponentDetectionHint.DoNotIncludeFunctionDefinedOnClassMethod) return false; | ||
| break; | ||
| case ast.isOneOf([AST_NODE_TYPES.ArrowFunctionExpression, AST_NODE_TYPES.FunctionExpression])(node) && node.parent.type === AST_NODE_TYPES.Property: | ||
| if (hint & ComponentDetectionHint.DoNotIncludeFunctionDefinedOnClassProperty) return false; | ||
| break; | ||
| case node.parent.type === AST_NODE_TYPES.ArrayPattern: | ||
| if (hint & ComponentDetectionHint.DoNotIncludeFunctionDefinedInArrayPattern) return false; | ||
| break; | ||
| case node.parent.type === AST_NODE_TYPES.ArrayExpression: | ||
| if (hint & ComponentDetectionHint.DoNotIncludeFunctionDefinedInArrayExpression) return false; | ||
| break; | ||
| 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": | ||
| if (hint & ComponentDetectionHint.DoNotIncludeFunctionDefinedAsArrayMapCallback) return false; | ||
| break; | ||
| 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": | ||
| if (hint & ComponentDetectionHint.DoNotIncludeFunctionDefinedAsArrayFlatMapCallback) return false; | ||
| break; | ||
| } | ||
| const significantParent = ast.findParentNode(node, ast.isOneOf([ | ||
@@ -958,0 +951,0 @@ AST_NODE_TYPES.JSXExpressionContainer, |
+5
-5
| { | ||
| "name": "@eslint-react/core", | ||
| "version": "3.0.0-beta.48", | ||
| "version": "3.0.0-beta.49", | ||
| "description": "ESLint React's ESLint utility module for static analysis of React core APIs and patterns.", | ||
@@ -37,6 +37,6 @@ "homepage": "https://github.com/Rel1cx/eslint-react", | ||
| "ts-pattern": "^5.9.0", | ||
| "@eslint-react/ast": "3.0.0-beta.48", | ||
| "@eslint-react/eff": "3.0.0-beta.48", | ||
| "@eslint-react/shared": "3.0.0-beta.48", | ||
| "@eslint-react/var": "3.0.0-beta.48" | ||
| "@eslint-react/ast": "3.0.0-beta.49", | ||
| "@eslint-react/eff": "3.0.0-beta.49", | ||
| "@eslint-react/shared": "3.0.0-beta.49", | ||
| "@eslint-react/var": "3.0.0-beta.49" | ||
| }, | ||
@@ -43,0 +43,0 @@ "devDependencies": { |
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
91554
-0.64%2053
-0.48%+ Added
+ Added
+ Added
+ Added
- Removed
- Removed
- Removed
- Removed