@eslint-react/var 5.2.1-next.3 → 5.2.2-next.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.js +20 -21
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { isIdentifier } from "@eslint-react/ast";
|
|
1
|
+
import { Check, Compare, Extract, Traverse, isOneOf } from "@eslint-react/ast";
|
|
3
2
|
import { DefinitionType } from "@typescript-eslint/scope-manager";
|
|
4
3
|
import { AST_NODE_TYPES } from "@typescript-eslint/types";
|
|
5
4
|
import { findVariable, getStaticValue } from "@typescript-eslint/utils/ast-utils";
|
|
@@ -52,7 +51,7 @@ function resolve(context, node, options) {
|
|
|
52
51
|
if ("declarations" in init) return null;
|
|
53
52
|
return init;
|
|
54
53
|
}
|
|
55
|
-
case DefinitionType.Parameter: return
|
|
54
|
+
case DefinitionType.Parameter: return Check.isFunction(def.node) ? def.node : null;
|
|
56
55
|
case DefinitionType.TSEnumName: return def.node;
|
|
57
56
|
case DefinitionType.TSEnumMember: return def.node.initializer ?? null;
|
|
58
57
|
case DefinitionType.ImportBinding: return null;
|
|
@@ -128,23 +127,23 @@ function computeObjectType(context, node) {
|
|
|
128
127
|
return computeObjectType(context, node.expressions[node.expressions.length - 1] ?? null);
|
|
129
128
|
case AST_NODE_TYPES.CallExpression:
|
|
130
129
|
switch (true) {
|
|
131
|
-
case
|
|
132
|
-
case
|
|
133
|
-
case
|
|
134
|
-
case
|
|
130
|
+
case Check.identifier(node.callee, "Boolean"): return null;
|
|
131
|
+
case Check.identifier(node.callee, "String"): return null;
|
|
132
|
+
case Check.identifier(node.callee, "Number"): return null;
|
|
133
|
+
case Check.identifier(node.callee, "Object"): return {
|
|
135
134
|
kind: "plain",
|
|
136
135
|
node
|
|
137
136
|
};
|
|
138
|
-
case
|
|
137
|
+
case Check.identifier(node.callee, "Array"): return {
|
|
139
138
|
kind: "array",
|
|
140
139
|
node
|
|
141
140
|
};
|
|
142
|
-
case
|
|
141
|
+
case Check.identifier(node.callee, "RegExp"): return {
|
|
143
142
|
kind: "regexp",
|
|
144
143
|
node
|
|
145
144
|
};
|
|
146
145
|
}
|
|
147
|
-
if (node.callee.type === AST_NODE_TYPES.MemberExpression &&
|
|
146
|
+
if (node.callee.type === AST_NODE_TYPES.MemberExpression && Check.identifier(node.callee.object) && Check.identifier(node.callee.property)) {
|
|
148
147
|
const objName = node.callee.object.name;
|
|
149
148
|
const methodName = node.callee.property.name;
|
|
150
149
|
switch (objName) {
|
|
@@ -338,8 +337,8 @@ const thisBlockTypes = [
|
|
|
338
337
|
* @returns `true` if node value equal
|
|
339
338
|
*/
|
|
340
339
|
function isValueEqual(context, a, b) {
|
|
341
|
-
a =
|
|
342
|
-
b =
|
|
340
|
+
a = Check.isTypeExpression(a) ? Extract.unwrapped(a) : a;
|
|
341
|
+
b = Check.isTypeExpression(b) ? Extract.unwrapped(b) : b;
|
|
343
342
|
const [aScope, bScope] = [context.sourceCode.getScope(a), context.sourceCode.getScope(b)];
|
|
344
343
|
switch (true) {
|
|
345
344
|
case a === b: return true;
|
|
@@ -357,12 +356,12 @@ function isValueEqual(context, a, b) {
|
|
|
357
356
|
const aDefParentParent = aDef?.parent?.parent;
|
|
358
357
|
const bDefParentParent = bDef?.parent?.parent;
|
|
359
358
|
switch (true) {
|
|
360
|
-
case aDefNodeParent?.type === AST_NODE_TYPES.CallExpression && bDefNodeParent?.type === AST_NODE_TYPES.CallExpression &&
|
|
361
|
-
if (!
|
|
359
|
+
case aDefNodeParent?.type === AST_NODE_TYPES.CallExpression && bDefNodeParent?.type === AST_NODE_TYPES.CallExpression && Check.isFunction(aDefNode) && Check.isFunction(bDefNode): {
|
|
360
|
+
if (!Compare.areEqual(aDefNodeParent.callee, bDefNodeParent.callee)) return false;
|
|
362
361
|
const aParams = aDefNode.params;
|
|
363
362
|
const bParams = bDefNode.params;
|
|
364
|
-
const aPos = aParams.findIndex((x) =>
|
|
365
|
-
const bPos = bParams.findIndex((x) =>
|
|
363
|
+
const aPos = aParams.findIndex((x) => Compare.areEqual(x, a));
|
|
364
|
+
const bPos = bParams.findIndex((x) => Compare.areEqual(x, b));
|
|
366
365
|
return aPos !== -1 && bPos !== -1 && aPos === bPos;
|
|
367
366
|
}
|
|
368
367
|
case aDefParentParent?.type === AST_NODE_TYPES.ForOfStatement && bDefParentParent?.type === AST_NODE_TYPES.ForOfStatement: {
|
|
@@ -371,17 +370,17 @@ function isValueEqual(context, a, b) {
|
|
|
371
370
|
if (aLeft.type !== bLeft.type) return false;
|
|
372
371
|
const aRight = aDefParentParent.right;
|
|
373
372
|
const bRight = bDefParentParent.right;
|
|
374
|
-
if (!
|
|
373
|
+
if (!Compare.areEqual(aRight, bRight)) return false;
|
|
375
374
|
if (aDefParentParent === bDefParentParent) return aVar != null && bVar != null && aVar === bVar;
|
|
376
375
|
return true;
|
|
377
376
|
}
|
|
378
377
|
default: return aVar != null && bVar != null && aVar === bVar;
|
|
379
378
|
}
|
|
380
379
|
}
|
|
381
|
-
case a.type === AST_NODE_TYPES.MemberExpression && b.type === AST_NODE_TYPES.MemberExpression: return (a.computed && b.computed ? isValueEqual(context, a.property, b.property) :
|
|
380
|
+
case a.type === AST_NODE_TYPES.MemberExpression && b.type === AST_NODE_TYPES.MemberExpression: return (a.computed && b.computed ? isValueEqual(context, a.property, b.property) : Compare.areEqual(a.property, b.property)) && isValueEqual(context, a.object, b.object);
|
|
382
381
|
case a.type === AST_NODE_TYPES.ThisExpression && b.type === AST_NODE_TYPES.ThisExpression:
|
|
383
382
|
if (aScope.block === bScope.block) return true;
|
|
384
|
-
return
|
|
383
|
+
return Traverse.findParent(a, isOneOf(thisBlockTypes)) === Traverse.findParent(b, isOneOf(thisBlockTypes));
|
|
385
384
|
default: {
|
|
386
385
|
const aStatic = getStaticValue(a, aScope);
|
|
387
386
|
const bStatic = getStaticValue(b, bScope);
|
|
@@ -402,7 +401,7 @@ function isValueEqual(context, a, b) {
|
|
|
402
401
|
* @internal
|
|
403
402
|
*/
|
|
404
403
|
function isAssignmentTargetEqual(context, a, b) {
|
|
405
|
-
return
|
|
404
|
+
return Compare.areEqual(a, b) || isValueEqual(context, a, b);
|
|
406
405
|
}
|
|
407
406
|
|
|
408
407
|
//#endregion
|
|
@@ -437,7 +436,7 @@ function resolveImportSource(name, initialScope, visited = /* @__PURE__ */ new S
|
|
|
437
436
|
if (init.type === AST_NODE_TYPES.MemberExpression && init.object.type === AST_NODE_TYPES.Identifier) return resolveImportSource(init.object.name, initialScope, visited);
|
|
438
437
|
if (init.type === AST_NODE_TYPES.Identifier) return resolveImportSource(init.name, initialScope, visited);
|
|
439
438
|
const arg0 = getRequireExpressionArguments(init)?.[0];
|
|
440
|
-
if (arg0 == null || !
|
|
439
|
+
if (arg0 == null || !Check.literal(arg0, "string")) return null;
|
|
441
440
|
return arg0.value;
|
|
442
441
|
}
|
|
443
442
|
if (parent?.type === AST_NODE_TYPES.ImportDeclaration) return parent.source.value;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eslint-react/var",
|
|
3
|
-
"version": "5.2.
|
|
3
|
+
"version": "5.2.2-next.0",
|
|
4
4
|
"description": "ESLint React's TSESTree AST utility module for static analysis of variables.",
|
|
5
5
|
"homepage": "https://github.com/Rel1cx/eslint-react",
|
|
6
6
|
"bugs": {
|
|
@@ -34,9 +34,9 @@
|
|
|
34
34
|
"@typescript-eslint/types": "^8.58.1",
|
|
35
35
|
"@typescript-eslint/utils": "^8.58.1",
|
|
36
36
|
"ts-pattern": "^5.9.0",
|
|
37
|
-
"@eslint-react/
|
|
38
|
-
"@eslint-react/
|
|
39
|
-
"@eslint-react/
|
|
37
|
+
"@eslint-react/ast": "5.2.2-next.0",
|
|
38
|
+
"@eslint-react/eslint": "5.2.2-next.0",
|
|
39
|
+
"@eslint-react/shared": "5.2.2-next.0"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@typescript-eslint/typescript-estree": "^8.58.1",
|