@eslint-react/core 5.14.8 → 5.14.9
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 +1 -1
- package/dist/index.js +16 -28
- package/package.json +7 -7
package/dist/index.d.ts
CHANGED
|
@@ -287,7 +287,7 @@ type FunctionSemanticNode = ClientFunctionSemanticNode | ServerFunctionSemanticN
|
|
|
287
287
|
* @param node - The function node to analyze.
|
|
288
288
|
* @returns The identifier node if found, `null` otherwise.
|
|
289
289
|
*/
|
|
290
|
-
declare function getFunctionId(node: TSESTree.Expression | TSESTreeFunction): TSESTree.ArrayExpression | TSESTree.ArrayPattern | TSESTree.ArrowFunctionExpressionWithBlockBody | TSESTree.ArrowFunctionExpressionWithExpressionBody | TSESTree.AssignmentExpression | TSESTree.AwaitExpression | TSESTree.PrivateInExpression | TSESTree.SymmetricBinaryExpression | TSESTree.CallExpression | TSESTree.ChainExpression | TSESTree.ClassExpression | TSESTree.ConditionalExpression | TSESTree.FunctionExpression | TSESTree.Identifier | TSESTree.ImportExpression | TSESTree.JSXElement | TSESTree.JSXFragment | TSESTree.BigIntLiteral | TSESTree.BooleanLiteral | TSESTree.NullLiteral | TSESTree.NumberLiteral | TSESTree.RegExpLiteral | TSESTree.StringLiteral | TSESTree.LogicalExpression | TSESTree.MemberExpressionComputedName | TSESTree.MemberExpressionNonComputedName | TSESTree.MetaProperty | TSESTree.NewExpression | TSESTree.ObjectExpression | TSESTree.ObjectPattern | TSESTree.
|
|
290
|
+
declare function getFunctionId(node: TSESTree.Expression | TSESTreeFunction): TSESTree.ArrayExpression | TSESTree.ArrayPattern | TSESTree.ArrowFunctionExpressionWithBlockBody | TSESTree.ArrowFunctionExpressionWithExpressionBody | TSESTree.AssignmentExpression | TSESTree.AwaitExpression | TSESTree.PrivateInExpression | TSESTree.SymmetricBinaryExpression | TSESTree.CallExpression | TSESTree.ChainExpression | TSESTree.ClassExpression | TSESTree.ConditionalExpression | TSESTree.FunctionExpression | TSESTree.Identifier | TSESTree.ImportExpression | TSESTree.JSXElement | TSESTree.JSXFragment | TSESTree.BigIntLiteral | TSESTree.BooleanLiteral | TSESTree.NullLiteral | TSESTree.NumberLiteral | TSESTree.RegExpLiteral | TSESTree.StringLiteral | TSESTree.TemplateLiteral | TSESTree.LogicalExpression | TSESTree.MemberExpressionComputedName | TSESTree.MemberExpressionNonComputedName | TSESTree.MetaProperty | TSESTree.NewExpression | TSESTree.ObjectExpression | TSESTree.ObjectPattern | TSESTree.SequenceExpression | TSESTree.Super | TSESTree.TaggedTemplateExpression | TSESTree.ThisExpression | TSESTree.TSAsExpression | TSESTree.TSInstantiationExpression | TSESTree.TSNonNullExpression | TSESTree.TSSatisfiesExpression | TSESTree.TSTypeAssertion | TSESTree.UnaryExpressionBitwiseNot | TSESTree.UnaryExpressionDelete | TSESTree.UnaryExpressionMinus | TSESTree.UnaryExpressionNot | TSESTree.UnaryExpressionPlus | TSESTree.UnaryExpressionTypeof | TSESTree.UnaryExpressionVoid | TSESTree.UpdateExpression | TSESTree.YieldNoStarExpression | TSESTree.YieldStarExpression | TSESTree.PrivateIdentifier | null;
|
|
291
291
|
/**
|
|
292
292
|
* Identifies the initialization path of a function node in the AST.
|
|
293
293
|
*
|
package/dist/index.js
CHANGED
|
@@ -325,7 +325,7 @@ function isRenderMethodCallback(node) {
|
|
|
325
325
|
*/
|
|
326
326
|
function isThisSetStateCall(node) {
|
|
327
327
|
const callee = Extract.unwrap(node.callee);
|
|
328
|
-
return callee.type === AST_NODE_TYPES.MemberExpression && callee.object.type === AST_NODE_TYPES.ThisExpression && Extract.
|
|
328
|
+
return callee.type === AST_NODE_TYPES.MemberExpression && callee.object.type === AST_NODE_TYPES.ThisExpression && Extract.getCalleeName(node) === "setState";
|
|
329
329
|
}
|
|
330
330
|
/**
|
|
331
331
|
* @param node The assignment expression node to check.
|
|
@@ -336,7 +336,7 @@ function isAssignmentToThisState(node) {
|
|
|
336
336
|
let current = Extract.unwrap(left);
|
|
337
337
|
while (current.type === AST_NODE_TYPES.MemberExpression) {
|
|
338
338
|
const { object, property } = current;
|
|
339
|
-
if (object.type === AST_NODE_TYPES.ThisExpression &&
|
|
339
|
+
if (object.type === AST_NODE_TYPES.ThisExpression && property.type === AST_NODE_TYPES.Identifier && property.name === "state") return true;
|
|
340
340
|
current = Extract.unwrap(object);
|
|
341
341
|
}
|
|
342
342
|
return false;
|
|
@@ -652,6 +652,7 @@ function isFunctionComponentDefinition(context, node, hint) {
|
|
|
652
652
|
let parent = node.parent;
|
|
653
653
|
while (Check.isTypeExpression(parent)) parent = parent.parent;
|
|
654
654
|
const parentCallee = parent.type === AST_NODE_TYPES.CallExpression ? Extract.unwrap(parent.callee) : null;
|
|
655
|
+
const parentCalleeName = parent.type === AST_NODE_TYPES.CallExpression ? Extract.getCalleeName(parent) : null;
|
|
655
656
|
switch (true) {
|
|
656
657
|
case Check.isOneOf([AST_NODE_TYPES.ArrowFunctionExpression, AST_NODE_TYPES.FunctionExpression])(node) && parent.type === AST_NODE_TYPES.Property && parent.parent.type === AST_NODE_TYPES.ObjectExpression:
|
|
657
658
|
if (hint & FunctionComponentDetectionHint.DoNotIncludeFunctionDefinedAsObjectMethod) return false;
|
|
@@ -668,10 +669,10 @@ function isFunctionComponentDefinition(context, node, hint) {
|
|
|
668
669
|
case parent.type === AST_NODE_TYPES.ArrayExpression:
|
|
669
670
|
if (hint & FunctionComponentDetectionHint.DoNotIncludeFunctionDefinedAsArrayExpressionElement) return false;
|
|
670
671
|
break;
|
|
671
|
-
case parentCallee != null && parentCallee.type === AST_NODE_TYPES.MemberExpression &&
|
|
672
|
+
case parentCallee != null && parentCallee.type === AST_NODE_TYPES.MemberExpression && parentCalleeName === "map":
|
|
672
673
|
if (hint & FunctionComponentDetectionHint.DoNotIncludeFunctionDefinedAsArrayMapCallback) return false;
|
|
673
674
|
break;
|
|
674
|
-
case parentCallee != null && parentCallee.type === AST_NODE_TYPES.MemberExpression &&
|
|
675
|
+
case parentCallee != null && parentCallee.type === AST_NODE_TYPES.MemberExpression && parentCalleeName === "flatMap":
|
|
675
676
|
if (hint & FunctionComponentDetectionHint.DoNotIncludeFunctionDefinedAsArrayFlatMapCallback) return false;
|
|
676
677
|
break;
|
|
677
678
|
case parent.type === AST_NODE_TYPES.CallExpression && getFunctionId(node) == null && !isFunctionComponentWrapperCall(context, parent) && !isCreateElementCall(context, parent):
|
|
@@ -756,10 +757,9 @@ function isHookDefinition(node) {
|
|
|
756
757
|
function isHookCall(node) {
|
|
757
758
|
if (node == null) return false;
|
|
758
759
|
if (node.type !== AST_NODE_TYPES.CallExpression) return false;
|
|
759
|
-
const
|
|
760
|
-
if (
|
|
761
|
-
|
|
762
|
-
return false;
|
|
760
|
+
const name = Extract.getCalleeName(node);
|
|
761
|
+
if (name == null) return false;
|
|
762
|
+
return isHookName(name);
|
|
763
763
|
}
|
|
764
764
|
/**
|
|
765
765
|
* Detect useEffect calls and variations (useLayoutEffect, etc.) using a regex pattern
|
|
@@ -770,12 +770,9 @@ function isHookCall(node) {
|
|
|
770
770
|
function isUseEffectLikeCall(node, additionalEffectHooks = { test: constFalse }) {
|
|
771
771
|
if (node == null) return false;
|
|
772
772
|
if (node.type !== AST_NODE_TYPES.CallExpression) return false;
|
|
773
|
-
const
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
if (callee.type === AST_NODE_TYPES.MemberExpression) return callee.property.type === AST_NODE_TYPES.Identifier && regexp.test(callee.property.name);
|
|
777
|
-
return false;
|
|
778
|
-
});
|
|
773
|
+
const name = Extract.getCalleeName(node);
|
|
774
|
+
if (name == null) return false;
|
|
775
|
+
return /^use\w*Effect$/u.test(name) || additionalEffectHooks.test(name);
|
|
779
776
|
}
|
|
780
777
|
/**
|
|
781
778
|
* Detect useState calls and variations using a regex pattern
|
|
@@ -786,12 +783,9 @@ function isUseEffectLikeCall(node, additionalEffectHooks = { test: constFalse })
|
|
|
786
783
|
function isUseStateLikeCall(node, additionalStateHooks = { test: constFalse }) {
|
|
787
784
|
if (node == null) return false;
|
|
788
785
|
if (node.type !== AST_NODE_TYPES.CallExpression) return false;
|
|
789
|
-
const
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
case callee.type === AST_NODE_TYPES.MemberExpression && callee.property.type === AST_NODE_TYPES.Identifier: return Extract.getPropertyName(callee.property) === "useState" || additionalStateHooks.test(callee.property.name);
|
|
793
|
-
}
|
|
794
|
-
return false;
|
|
786
|
+
const name = Extract.getCalleeName(node);
|
|
787
|
+
if (name == null) return false;
|
|
788
|
+
return name === "useState" || additionalStateHooks.test(name);
|
|
795
789
|
}
|
|
796
790
|
/**
|
|
797
791
|
* Determine if a node is the setup function passed to a useEffect-like hook
|
|
@@ -867,15 +861,9 @@ function isJsxLike(context, node, hint = DEFAULT_JSX_DETECTION_HINT) {
|
|
|
867
861
|
if (hint & JsxDetectionHint.RequireBothBranchesOfConditionalExpressionToBeJsx) return visit(node.consequent) && visit(node.alternate);
|
|
868
862
|
return visit(node.consequent) || visit(node.alternate);
|
|
869
863
|
case AST_NODE_TYPES.SequenceExpression: return visit(node.expressions.at(-1) ?? null);
|
|
870
|
-
case AST_NODE_TYPES.CallExpression:
|
|
864
|
+
case AST_NODE_TYPES.CallExpression:
|
|
871
865
|
if (hint & JsxDetectionHint.DoNotIncludeJsxWithCreateElementValue) return false;
|
|
872
|
-
|
|
873
|
-
switch (callee.type) {
|
|
874
|
-
case AST_NODE_TYPES.Identifier: return callee.name === "createElement";
|
|
875
|
-
case AST_NODE_TYPES.MemberExpression: return Extract.getPropertyName(callee.property) === "createElement";
|
|
876
|
-
default: return false;
|
|
877
|
-
}
|
|
878
|
-
}
|
|
866
|
+
return Extract.getCalleeName(node) === "createElement";
|
|
879
867
|
case AST_NODE_TYPES.Identifier:
|
|
880
868
|
if (node.name === "undefined") return !(hint & JsxDetectionHint.DoNotIncludeJsxWithUndefinedValue);
|
|
881
869
|
if (seen.has(node)) return false;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eslint-react/core",
|
|
3
|
-
"version": "5.14.
|
|
3
|
+
"version": "5.14.9",
|
|
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": {
|
|
@@ -33,17 +33,17 @@
|
|
|
33
33
|
"@typescript-eslint/types": "^8.63.0",
|
|
34
34
|
"@typescript-eslint/utils": "^8.63.0",
|
|
35
35
|
"ts-pattern": "^5.9.0",
|
|
36
|
-
"@eslint-react/ast": "5.14.
|
|
37
|
-
"@eslint-react/eslint": "5.14.
|
|
38
|
-
"@eslint-react/jsx": "5.14.
|
|
39
|
-
"@eslint-react/
|
|
40
|
-
"@eslint-react/
|
|
36
|
+
"@eslint-react/ast": "5.14.9",
|
|
37
|
+
"@eslint-react/eslint": "5.14.9",
|
|
38
|
+
"@eslint-react/jsx": "5.14.9",
|
|
39
|
+
"@eslint-react/shared": "5.14.9",
|
|
40
|
+
"@eslint-react/var": "5.14.9"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@typescript-eslint/parser": "^8.63.0",
|
|
44
44
|
"@typescript-eslint/typescript-estree": "^8.63.0",
|
|
45
45
|
"eslint": "^10.7.0",
|
|
46
|
-
"tsdown": "^0.22.
|
|
46
|
+
"tsdown": "^0.22.7",
|
|
47
47
|
"typescript": "6.0.3",
|
|
48
48
|
"vitest": "^4.1.10",
|
|
49
49
|
"@local/eff": "0.0.0",
|