@eslint-react/core 5.18.6 → 5.18.8
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 -14
- package/package.json +16 -16
package/dist/index.d.ts
CHANGED
|
@@ -434,7 +434,7 @@ type FunctionSemanticNode = ClientFunctionSemanticNode | ServerFunctionSemanticN
|
|
|
434
434
|
* @param node The function node to analyze.
|
|
435
435
|
* @returns The identifier node if found, `null` otherwise.
|
|
436
436
|
*/
|
|
437
|
-
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.
|
|
437
|
+
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.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.YieldNoStarExpression | TSESTree.YieldStarExpression | null;
|
|
438
438
|
/**
|
|
439
439
|
* Get the initialization path of a function node in the AST.
|
|
440
440
|
*
|
package/dist/index.js
CHANGED
|
@@ -196,8 +196,8 @@ function isClassComponent(node) {
|
|
|
196
196
|
if ("superClass" in node && node.superClass != null) {
|
|
197
197
|
const re = /^(?:Pure)?Component$/u;
|
|
198
198
|
switch (true) {
|
|
199
|
-
case node.superClass
|
|
200
|
-
case node.superClass.type === AST_NODE_TYPES.MemberExpression && node.superClass.property
|
|
199
|
+
case Check.isIdentifier(node.superClass): return re.test(node.superClass.name);
|
|
200
|
+
case node.superClass.type === AST_NODE_TYPES.MemberExpression && Check.isIdentifier(node.superClass.property): return re.test(node.superClass.property.name);
|
|
201
201
|
}
|
|
202
202
|
}
|
|
203
203
|
return false;
|
|
@@ -212,14 +212,14 @@ function isPureComponent(node) {
|
|
|
212
212
|
if ("superClass" in node && node.superClass != null) {
|
|
213
213
|
const re = /^PureComponent$/u;
|
|
214
214
|
switch (true) {
|
|
215
|
-
case node.superClass
|
|
216
|
-
case node.superClass.type === AST_NODE_TYPES.MemberExpression && node.superClass.property
|
|
215
|
+
case Check.isIdentifier(node.superClass): return re.test(node.superClass.name);
|
|
216
|
+
case node.superClass.type === AST_NODE_TYPES.MemberExpression && Check.isIdentifier(node.superClass.property): return re.test(node.superClass.property.name);
|
|
217
217
|
}
|
|
218
218
|
}
|
|
219
219
|
return false;
|
|
220
220
|
}
|
|
221
221
|
function createLifecycleChecker(methodName, isStatic = false) {
|
|
222
|
-
return (node) => Check.isPropertyOrMethod(node) && node.static === isStatic && node.key
|
|
222
|
+
return (node) => Check.isPropertyOrMethod(node) && node.static === isStatic && Check.isIdentifier(node.key) && node.key.name === methodName;
|
|
223
223
|
}
|
|
224
224
|
/** @deprecated Class components are legacy. */
|
|
225
225
|
const isRender = createLifecycleChecker("render");
|
|
@@ -264,7 +264,7 @@ const isGetDerivedStateFromError = createLifecycleChecker("getDerivedStateFromEr
|
|
|
264
264
|
* @deprecated Class components are legacy. This function exists only to support legacy rules.
|
|
265
265
|
*/
|
|
266
266
|
function isRenderMethodLike(node) {
|
|
267
|
-
return Check.isPropertyOrMethod(node) && node.key
|
|
267
|
+
return Check.isPropertyOrMethod(node) && Check.isIdentifier(node.key) && node.key.name.startsWith("render") && Check.isOneOf([AST_NODE_TYPES.ClassDeclaration, AST_NODE_TYPES.ClassExpression])(node.parent.parent);
|
|
268
268
|
}
|
|
269
269
|
/**
|
|
270
270
|
* Check if the function is a callback passed to a class component's render method.
|
|
@@ -274,7 +274,8 @@ function isRenderMethodLike(node) {
|
|
|
274
274
|
function isRenderMethodCallback(node) {
|
|
275
275
|
const parent = node.parent;
|
|
276
276
|
const greatGrandparent = parent.parent?.parent;
|
|
277
|
-
|
|
277
|
+
if (greatGrandparent == null) return false;
|
|
278
|
+
return isRenderMethodLike(parent) && isClassComponent(greatGrandparent);
|
|
278
279
|
}
|
|
279
280
|
/**
|
|
280
281
|
* Check if the call expression is a `this.setState(...)` call.
|
|
@@ -284,7 +285,7 @@ function isRenderMethodCallback(node) {
|
|
|
284
285
|
*/
|
|
285
286
|
function isThisSetStateCall(node) {
|
|
286
287
|
const callee = Extract.unwrap(node.callee);
|
|
287
|
-
return callee.type === AST_NODE_TYPES.MemberExpression && callee.object.type === AST_NODE_TYPES.ThisExpression && Extract.getCalleeName(node) === "setState";
|
|
288
|
+
return callee.type === AST_NODE_TYPES.MemberExpression && Extract.unwrap(callee.object).type === AST_NODE_TYPES.ThisExpression && Extract.getCalleeName(node) === "setState";
|
|
288
289
|
}
|
|
289
290
|
/**
|
|
290
291
|
* Check if the assignment expression assigns to `this.state`.
|
|
@@ -296,9 +297,10 @@ function isAssignmentToThisState(node) {
|
|
|
296
297
|
const { left } = node;
|
|
297
298
|
let current = Extract.unwrap(left);
|
|
298
299
|
while (current.type === AST_NODE_TYPES.MemberExpression) {
|
|
299
|
-
const
|
|
300
|
-
|
|
301
|
-
|
|
300
|
+
const object = Extract.unwrap(current.object);
|
|
301
|
+
const property = current.property;
|
|
302
|
+
if (object.type === AST_NODE_TYPES.ThisExpression && Check.isIdentifier(property, "state")) return true;
|
|
303
|
+
current = object;
|
|
302
304
|
}
|
|
303
305
|
return false;
|
|
304
306
|
}
|
|
@@ -522,7 +524,7 @@ function isFunctionHasCallInInitPath(callName, initPath) {
|
|
|
522
524
|
return initPath.some((node) => {
|
|
523
525
|
if (node.type !== AST_NODE_TYPES.CallExpression) return false;
|
|
524
526
|
const callee = Extract.unwrap(node.callee);
|
|
525
|
-
if (callee
|
|
527
|
+
if (Check.isIdentifier(callee)) return callee.name === callName;
|
|
526
528
|
if (callee.type === AST_NODE_TYPES.MemberExpression && "name" in callee.property) return callee.property.name === callName;
|
|
527
529
|
return false;
|
|
528
530
|
});
|
|
@@ -768,8 +770,8 @@ function isFunctionComponentNameLoose(name) {
|
|
|
768
770
|
function isFunctionWithLooseComponentName(context, fn, allowNone = false) {
|
|
769
771
|
const id = getFunctionComponentId(context, fn);
|
|
770
772
|
if (id == null) return allowNone;
|
|
771
|
-
if (id
|
|
772
|
-
if (id.type === AST_NODE_TYPES.MemberExpression && id.property
|
|
773
|
+
if (Check.isIdentifier(id)) return isFunctionComponentNameLoose(id.name);
|
|
774
|
+
if (id.type === AST_NODE_TYPES.MemberExpression && Check.isIdentifier(id.property)) return isFunctionComponentNameLoose(id.property.name);
|
|
773
775
|
return false;
|
|
774
776
|
}
|
|
775
777
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eslint-react/core",
|
|
3
|
-
"version": "5.18.
|
|
3
|
+
"version": "5.18.8",
|
|
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": {
|
|
@@ -29,25 +29,25 @@
|
|
|
29
29
|
"dist"
|
|
30
30
|
],
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@
|
|
33
|
-
"@
|
|
34
|
-
"@
|
|
35
|
-
"
|
|
36
|
-
"@eslint-
|
|
37
|
-
"@eslint
|
|
38
|
-
"@eslint
|
|
39
|
-
"
|
|
32
|
+
"@eslint-react/ast": "5.18.8",
|
|
33
|
+
"@eslint-react/eslint": "5.18.8",
|
|
34
|
+
"@eslint-react/shared": "5.18.8",
|
|
35
|
+
"@eslint-react/var": "5.18.8",
|
|
36
|
+
"@typescript-eslint/scope-manager": "^8.69.0",
|
|
37
|
+
"@typescript-eslint/types": "^8.69.0",
|
|
38
|
+
"@typescript-eslint/utils": "^8.69.0",
|
|
39
|
+
"ts-pattern": "^5.9.0"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@typescript-eslint/parser": "^8.67.0",
|
|
43
|
-
"@typescript-eslint/typescript-estree": "^8.67.0",
|
|
44
|
-
"eslint": "^10.8.1",
|
|
45
|
-
"tsdown": "^0.22.14",
|
|
46
|
-
"typescript": "6.0.3",
|
|
47
|
-
"vitest": "^4.1.10",
|
|
48
42
|
"@local/configs": "0.0.0",
|
|
49
43
|
"@local/eff": "0.0.0",
|
|
50
|
-
"@local/testkit": "0.0.0"
|
|
44
|
+
"@local/testkit": "0.0.0",
|
|
45
|
+
"@typescript-eslint/parser": "^8.69.0",
|
|
46
|
+
"@typescript-eslint/typescript-estree": "^8.69.0",
|
|
47
|
+
"eslint": "^10.9.1",
|
|
48
|
+
"tsdown": "^0.22.14",
|
|
49
|
+
"typescript": "6.0.3",
|
|
50
|
+
"vitest": "^4.1.11"
|
|
51
51
|
},
|
|
52
52
|
"peerDependencies": {
|
|
53
53
|
"eslint": "*",
|