@eslint-react/core 5.2.3-next.1 → 5.2.4-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 +0 -6
- package/dist/index.js +13 -16
- package/package.json +6 -6
package/dist/index.d.ts
CHANGED
|
@@ -338,12 +338,6 @@ declare function isFunctionHasCallInInitPath(callName: string, initPath: Functio
|
|
|
338
338
|
* @returns `true` if the function is empty, `false` otherwise.
|
|
339
339
|
*/
|
|
340
340
|
declare function isFunctionEmpty(node: TSESTreeFunction): boolean;
|
|
341
|
-
/**
|
|
342
|
-
* Gets all directive expression statements from the top of a function body.
|
|
343
|
-
*
|
|
344
|
-
* @param node - The function AST node.
|
|
345
|
-
* @returns An array of directive expression statements.
|
|
346
|
-
*/
|
|
347
341
|
declare function getFunctionDirectives(node: TSESTreeFunction): TSESTreeDirective[];
|
|
348
342
|
/**
|
|
349
343
|
* Checks if a directive with the given name exists in the function directives.
|
package/dist/index.js
CHANGED
|
@@ -145,7 +145,7 @@ function isAPI(api) {
|
|
|
145
145
|
const func = (context, node) => {
|
|
146
146
|
if (node == null) return false;
|
|
147
147
|
const getText = (n) => context.sourceCode.getText(n);
|
|
148
|
-
const name = Extract.
|
|
148
|
+
const name = Extract.getFullyQualifiedName(node, getText);
|
|
149
149
|
if (name === api) return true;
|
|
150
150
|
if (name.endsWith(`.${api}`)) return true;
|
|
151
151
|
return false;
|
|
@@ -161,7 +161,7 @@ function isAPICall(api) {
|
|
|
161
161
|
const func = (context, node) => {
|
|
162
162
|
if (node == null) return false;
|
|
163
163
|
if (node.type !== AST_NODE_TYPES.CallExpression) return false;
|
|
164
|
-
return isAPI(api)(context, Extract.
|
|
164
|
+
return isAPI(api)(context, Extract.unwrap(node.callee));
|
|
165
165
|
};
|
|
166
166
|
return dual(2, func);
|
|
167
167
|
}
|
|
@@ -367,7 +367,7 @@ function isRenderMethodCallback(node) {
|
|
|
367
367
|
*/
|
|
368
368
|
function isThisSetStateCall(node) {
|
|
369
369
|
const { callee } = node;
|
|
370
|
-
return callee.type === AST_NODE_TYPES.MemberExpression &&
|
|
370
|
+
return callee.type === AST_NODE_TYPES.MemberExpression && callee.object.type === AST_NODE_TYPES.ThisExpression && callee.property.type === AST_NODE_TYPES.Identifier && callee.property.name === "setState";
|
|
371
371
|
}
|
|
372
372
|
/**
|
|
373
373
|
* @param node The assignment expression node to check.
|
|
@@ -375,7 +375,7 @@ function isThisSetStateCall(node) {
|
|
|
375
375
|
*/
|
|
376
376
|
function isAssignmentToThisState(node) {
|
|
377
377
|
const { left } = node;
|
|
378
|
-
return left.type === AST_NODE_TYPES.MemberExpression &&
|
|
378
|
+
return left.type === AST_NODE_TYPES.MemberExpression && left.object.type === AST_NODE_TYPES.ThisExpression && Extract.getPropertyName(left.property) === "state";
|
|
379
379
|
}
|
|
380
380
|
|
|
381
381
|
//#endregion
|
|
@@ -394,7 +394,7 @@ function getClassComponentCollector(context) {
|
|
|
394
394
|
if (!isClassComponent(node)) return;
|
|
395
395
|
const id = getClassId(node);
|
|
396
396
|
const key = ulid();
|
|
397
|
-
const name = id == null ? null : Extract.
|
|
397
|
+
const name = id == null ? null : Extract.getFullyQualifiedName(id, getText);
|
|
398
398
|
components.set(key, {
|
|
399
399
|
id,
|
|
400
400
|
key,
|
|
@@ -521,17 +521,14 @@ function isFunctionHasCallInInitPath(callName, initPath) {
|
|
|
521
521
|
function isFunctionEmpty(node) {
|
|
522
522
|
return node.body.type === AST_NODE_TYPES.BlockStatement && node.body.body.length === 0;
|
|
523
523
|
}
|
|
524
|
-
/**
|
|
525
|
-
* Gets all directive expression statements from the top of a function body.
|
|
526
|
-
*
|
|
527
|
-
* @param node - The function AST node.
|
|
528
|
-
* @returns An array of directive expression statements.
|
|
529
|
-
*/
|
|
530
524
|
function getFunctionDirectives(node) {
|
|
531
525
|
const directives = [];
|
|
532
526
|
if (node.body.type !== AST_NODE_TYPES.BlockStatement) return directives;
|
|
527
|
+
function isDirective(node) {
|
|
528
|
+
return node.type === AST_NODE_TYPES.ExpressionStatement && node.directive != null;
|
|
529
|
+
}
|
|
533
530
|
for (const stmt of node.body.body) {
|
|
534
|
-
if (!
|
|
531
|
+
if (!isDirective(stmt)) continue;
|
|
535
532
|
directives.push(stmt);
|
|
536
533
|
}
|
|
537
534
|
return directives;
|
|
@@ -814,7 +811,7 @@ function isUseStateLikeCall(node, additionalStateHooks = { test: constFalse }) {
|
|
|
814
811
|
if (node.type !== AST_NODE_TYPES.CallExpression) return false;
|
|
815
812
|
switch (true) {
|
|
816
813
|
case node.callee.type === AST_NODE_TYPES.Identifier: return node.callee.name === "useState" || additionalStateHooks.test(node.callee.name);
|
|
817
|
-
case node.callee.type === AST_NODE_TYPES.MemberExpression && node.callee.property.type === AST_NODE_TYPES.Identifier: return Extract.
|
|
814
|
+
case node.callee.type === AST_NODE_TYPES.MemberExpression && node.callee.property.type === AST_NODE_TYPES.Identifier: return Extract.getPropertyName(node.callee.property) === "useState" || additionalStateHooks.test(node.callee.property.name);
|
|
818
815
|
}
|
|
819
816
|
return false;
|
|
820
817
|
}
|
|
@@ -856,9 +853,9 @@ function getFunctionComponentCollector(context, options = {}) {
|
|
|
856
853
|
const key = ulid();
|
|
857
854
|
const exp = Traverse.findParent(node, (n) => n.type === AST_NODE_TYPES.ExportDefaultDeclaration);
|
|
858
855
|
const isExportDefault = exp != null;
|
|
859
|
-
const isExportDefaultDeclaration = exp != null && Extract.
|
|
856
|
+
const isExportDefaultDeclaration = exp != null && Extract.unwrap(exp.declaration) === node;
|
|
860
857
|
const id = getFunctionComponentId(context, node);
|
|
861
|
-
const name = id == null ? null : Extract.
|
|
858
|
+
const name = id == null ? null : Extract.getFullyQualifiedName(id, getText);
|
|
862
859
|
const initPath = getFunctionInitPath(node);
|
|
863
860
|
const directives = getFunctionDirectives(node);
|
|
864
861
|
const entry = {
|
|
@@ -950,7 +947,7 @@ function getHookCollector(context) {
|
|
|
950
947
|
id,
|
|
951
948
|
key,
|
|
952
949
|
kind: "hook",
|
|
953
|
-
name: id == null ? null : Extract.
|
|
950
|
+
name: id == null ? null : Extract.getFullyQualifiedName(id, getText),
|
|
954
951
|
directives: [],
|
|
955
952
|
flag: 0n,
|
|
956
953
|
hint: 0n,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eslint-react/core",
|
|
3
|
-
"version": "5.2.
|
|
3
|
+
"version": "5.2.4-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": {
|
|
@@ -35,11 +35,11 @@
|
|
|
35
35
|
"@typescript-eslint/utils": "^8.58.2",
|
|
36
36
|
"ts-pattern": "^5.9.0",
|
|
37
37
|
"ulid": "^3.0.2",
|
|
38
|
-
"@eslint-react/
|
|
39
|
-
"@eslint-react/
|
|
40
|
-
"@eslint-react/jsx": "5.2.
|
|
41
|
-
"@eslint-react/
|
|
42
|
-
"@eslint-react/
|
|
38
|
+
"@eslint-react/eslint": "5.2.4-beta.0",
|
|
39
|
+
"@eslint-react/ast": "5.2.4-beta.0",
|
|
40
|
+
"@eslint-react/jsx": "5.2.4-beta.0",
|
|
41
|
+
"@eslint-react/shared": "5.2.4-beta.0",
|
|
42
|
+
"@eslint-react/var": "5.2.4-beta.0"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"@typescript-eslint/typescript-estree": "^8.58.2",
|