@eslint-react/core 5.3.0-next.1 → 5.3.1-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 +1 -1
- package/dist/index.js +16 -10
- package/package.json +6 -6
package/dist/index.d.ts
CHANGED
|
@@ -315,7 +315,7 @@ type FunctionSemanticNode = ClientFunctionSemanticNode | ServerFunctionSemanticN
|
|
|
315
315
|
* @param node - The function node to analyze.
|
|
316
316
|
* @returns The identifier node if found, `null` otherwise.
|
|
317
317
|
*/
|
|
318
|
-
declare function getFunctionId(node: TSESTree.Expression | TSESTreeFunction): TSESTree.ArrayExpression | TSESTree.ArrayPattern | TSESTree.ArrowFunctionExpression | 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.
|
|
318
|
+
declare function getFunctionId(node: TSESTree.Expression | TSESTreeFunction): TSESTree.ArrayExpression | TSESTree.ArrayPattern | TSESTree.ArrowFunctionExpression | 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.PrivateIdentifier | TSESTree.SequenceExpression | TSESTree.Super | TSESTree.TaggedTemplateExpression | TSESTree.TemplateLiteral | 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.YieldExpression | null;
|
|
319
319
|
/**
|
|
320
320
|
* Identifies the initialization path of a function node in the AST.
|
|
321
321
|
*
|
package/dist/index.js
CHANGED
|
@@ -142,8 +142,9 @@ const compose = dual(2, (ab, bc) => (a) => bc(ab(a)));
|
|
|
142
142
|
function isAPI(api) {
|
|
143
143
|
const func = (context, node) => {
|
|
144
144
|
if (node == null) return false;
|
|
145
|
+
const expr = Extract.unwrap(node);
|
|
145
146
|
const getText = (n) => context.sourceCode.getText(n);
|
|
146
|
-
const name = Extract.getFullyQualifiedName(
|
|
147
|
+
const name = Extract.getFullyQualifiedName(expr, getText);
|
|
147
148
|
if (name === api) return true;
|
|
148
149
|
if (name.endsWith(`.${api}`)) return true;
|
|
149
150
|
return false;
|
|
@@ -776,8 +777,9 @@ function isHookDefinition(node) {
|
|
|
776
777
|
function isHookCall(node) {
|
|
777
778
|
if (node == null) return false;
|
|
778
779
|
if (node.type !== AST_NODE_TYPES.CallExpression) return false;
|
|
779
|
-
|
|
780
|
-
if (
|
|
780
|
+
const callee = Extract.unwrap(node.callee);
|
|
781
|
+
if (callee.type === AST_NODE_TYPES.Identifier) return isHookName(callee.name);
|
|
782
|
+
if (callee.type === AST_NODE_TYPES.MemberExpression) return callee.property.type === AST_NODE_TYPES.Identifier && isHookName(callee.property.name);
|
|
781
783
|
return false;
|
|
782
784
|
}
|
|
783
785
|
/**
|
|
@@ -789,9 +791,10 @@ function isHookCall(node) {
|
|
|
789
791
|
function isUseEffectLikeCall(node, additionalEffectHooks = { test: constFalse }) {
|
|
790
792
|
if (node == null) return false;
|
|
791
793
|
if (node.type !== AST_NODE_TYPES.CallExpression) return false;
|
|
794
|
+
const callee = Extract.unwrap(node.callee);
|
|
792
795
|
return [/^use\w*Effect$/u, additionalEffectHooks].some((regexp) => {
|
|
793
|
-
if (
|
|
794
|
-
if (
|
|
796
|
+
if (callee.type === AST_NODE_TYPES.Identifier) return regexp.test(callee.name);
|
|
797
|
+
if (callee.type === AST_NODE_TYPES.MemberExpression) return callee.property.type === AST_NODE_TYPES.Identifier && regexp.test(callee.property.name);
|
|
795
798
|
return false;
|
|
796
799
|
});
|
|
797
800
|
}
|
|
@@ -804,9 +807,10 @@ function isUseEffectLikeCall(node, additionalEffectHooks = { test: constFalse })
|
|
|
804
807
|
function isUseStateLikeCall(node, additionalStateHooks = { test: constFalse }) {
|
|
805
808
|
if (node == null) return false;
|
|
806
809
|
if (node.type !== AST_NODE_TYPES.CallExpression) return false;
|
|
810
|
+
const callee = Extract.unwrap(node.callee);
|
|
807
811
|
switch (true) {
|
|
808
|
-
case
|
|
809
|
-
case
|
|
812
|
+
case callee.type === AST_NODE_TYPES.Identifier: return callee.name === "useState" || additionalStateHooks.test(callee.name);
|
|
813
|
+
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);
|
|
810
814
|
}
|
|
811
815
|
return false;
|
|
812
816
|
}
|
|
@@ -816,7 +820,8 @@ function isUseStateLikeCall(node, additionalStateHooks = { test: constFalse }) {
|
|
|
816
820
|
*/
|
|
817
821
|
function isUseEffectSetupCallback(node) {
|
|
818
822
|
if (node == null) return false;
|
|
819
|
-
|
|
823
|
+
const expr = Extract.unwrap(node);
|
|
824
|
+
return expr.parent?.type === AST_NODE_TYPES.CallExpression && expr.parent.arguments.at(0) === expr && isUseEffectLikeCall(expr.parent);
|
|
820
825
|
}
|
|
821
826
|
/**
|
|
822
827
|
* Determine if a node is the cleanup function returned by a useEffect-like hook's setup function
|
|
@@ -824,8 +829,9 @@ function isUseEffectSetupCallback(node) {
|
|
|
824
829
|
*/
|
|
825
830
|
function isUseEffectCleanupCallback(node) {
|
|
826
831
|
if (node == null) return false;
|
|
827
|
-
const
|
|
828
|
-
const
|
|
832
|
+
const expr = Extract.unwrap(node);
|
|
833
|
+
const returnStatement = Traverse.findParent(expr, is(AST_NODE_TYPES.ReturnStatement));
|
|
834
|
+
const enclosingFunction = Traverse.findParent(expr, Check.isFunction);
|
|
829
835
|
if (enclosingFunction !== Traverse.findParent(returnStatement, Check.isFunction)) return false;
|
|
830
836
|
return isUseEffectSetupCallback(enclosingFunction);
|
|
831
837
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eslint-react/core",
|
|
3
|
-
"version": "5.3.
|
|
3
|
+
"version": "5.3.1-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,11 +34,11 @@
|
|
|
34
34
|
"@typescript-eslint/types": "^8.58.2",
|
|
35
35
|
"@typescript-eslint/utils": "^8.58.2",
|
|
36
36
|
"ts-pattern": "^5.9.0",
|
|
37
|
-
"@eslint-react/
|
|
38
|
-
"@eslint-react/
|
|
39
|
-
"@eslint-react/
|
|
40
|
-
"@eslint-react/
|
|
41
|
-
"@eslint-react/var": "5.3.
|
|
37
|
+
"@eslint-react/eslint": "5.3.1-beta.0",
|
|
38
|
+
"@eslint-react/ast": "5.3.1-beta.0",
|
|
39
|
+
"@eslint-react/jsx": "5.3.1-beta.0",
|
|
40
|
+
"@eslint-react/shared": "5.3.1-beta.0",
|
|
41
|
+
"@eslint-react/var": "5.3.1-beta.0"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"@typescript-eslint/typescript-estree": "^8.58.2",
|