@eslint-react/var 5.2.1-next.1 → 5.2.2-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 +14 -14
- package/dist/index.js +40 -41
- package/package.json +4 -4
package/dist/index.d.ts
CHANGED
|
@@ -40,19 +40,6 @@ type ObjectType = {
|
|
|
40
40
|
*/
|
|
41
41
|
declare function computeObjectType(context: RuleContext, node: TSESTree.Node | null): ObjectType | null;
|
|
42
42
|
//#endregion
|
|
43
|
-
//#region src/find-enclosing-assignment-target.d.ts
|
|
44
|
-
/**
|
|
45
|
-
* Finds the enclosing assignment target (variable, property, etc.) for a given node
|
|
46
|
-
*
|
|
47
|
-
* @param node The starting node
|
|
48
|
-
* @returns The enclosing assignment target node, or null if not found
|
|
49
|
-
*/
|
|
50
|
-
declare function findEnclosingAssignmentTarget(node: TSESTree.Node): TSESTree.ArrayExpression | TSESTree.ArrayPattern | TSESTree.ArrowFunctionExpression | TSESTree.AssignmentExpression | TSESTree.AwaitExpression | TSESTree.PrivateInExpression | TSESTree.SymmetricBinaryExpression | TSESTree.CallExpression | TSESTree.ChainExpression | TSESTree.ClassDeclarationWithOptionalName | TSESTree.ClassExpression | TSESTree.ConditionalExpression | TSESTree.FunctionDeclarationWithName | TSESTree.FunctionDeclarationWithOptionalName | 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.TSDeclareFunctionNoDeclare | TSESTree.TSDeclareFunctionWithDeclare | TSESTree.TSEnumDeclaration | TSESTree.TSInstantiationExpression | TSESTree.TSInterfaceDeclaration | TSESTree.TSModuleDeclarationGlobal | TSESTree.TSModuleDeclarationModuleWithIdentifierId | TSESTree.TSModuleDeclarationModuleWithStringIdDeclared | TSESTree.TSModuleDeclarationModuleWithStringIdNotDeclared | TSESTree.TSModuleDeclarationNamespace | TSESTree.TSNonNullExpression | TSESTree.TSSatisfiesExpression | TSESTree.TSTypeAliasDeclaration | TSESTree.TSTypeAssertion | TSESTree.UnaryExpressionBitwiseNot | TSESTree.UnaryExpressionDelete | TSESTree.UnaryExpressionMinus | TSESTree.UnaryExpressionNot | TSESTree.UnaryExpressionPlus | TSESTree.UnaryExpressionTypeof | TSESTree.UnaryExpressionVoid | TSESTree.UpdateExpression | TSESTree.ConstDeclaration | TSESTree.LetOrVarDeclaredDeclaration | TSESTree.LetOrVarNonDeclaredDeclaration | TSESTree.UsingInForOfDeclaration | TSESTree.UsingInNormalContextDeclaration | TSESTree.YieldExpression | null;
|
|
51
|
-
/**
|
|
52
|
-
* Type representing the possible assignment targets returned by `findEnclosingAssignmentTarget`
|
|
53
|
-
*/
|
|
54
|
-
type AssignmentTarget = ReturnType<typeof findEnclosingAssignmentTarget>;
|
|
55
|
-
//#endregion
|
|
56
43
|
//#region src/get-require-expression-arguments.d.ts
|
|
57
44
|
/**
|
|
58
45
|
* Get the arguments of a require expression
|
|
@@ -120,7 +107,20 @@ declare function resolve(context: RuleContext, node: TSESTree.Identifier, option
|
|
|
120
107
|
localOnly: boolean;
|
|
121
108
|
}>): TSESTree.Node | null;
|
|
122
109
|
//#endregion
|
|
110
|
+
//#region src/resolve-enclosing-assignment-target.d.ts
|
|
111
|
+
/**
|
|
112
|
+
* Finds the enclosing assignment target (variable, property, etc.) for a given node
|
|
113
|
+
*
|
|
114
|
+
* @param node The starting node
|
|
115
|
+
* @returns The enclosing assignment target node, or null if not found
|
|
116
|
+
*/
|
|
117
|
+
declare function resolveEnclosingAssignmentTarget(node: TSESTree.Node): TSESTree.ArrayExpression | TSESTree.ArrayPattern | TSESTree.ArrowFunctionExpression | TSESTree.AssignmentExpression | TSESTree.AwaitExpression | TSESTree.PrivateInExpression | TSESTree.SymmetricBinaryExpression | TSESTree.CallExpression | TSESTree.ChainExpression | TSESTree.ClassDeclarationWithOptionalName | TSESTree.ClassExpression | TSESTree.ConditionalExpression | TSESTree.FunctionDeclarationWithName | TSESTree.FunctionDeclarationWithOptionalName | 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.TSDeclareFunctionNoDeclare | TSESTree.TSDeclareFunctionWithDeclare | TSESTree.TSEnumDeclaration | TSESTree.TSInstantiationExpression | TSESTree.TSInterfaceDeclaration | TSESTree.TSModuleDeclarationGlobal | TSESTree.TSModuleDeclarationModuleWithIdentifierId | TSESTree.TSModuleDeclarationModuleWithStringIdDeclared | TSESTree.TSModuleDeclarationModuleWithStringIdNotDeclared | TSESTree.TSModuleDeclarationNamespace | TSESTree.TSNonNullExpression | TSESTree.TSSatisfiesExpression | TSESTree.TSTypeAliasDeclaration | TSESTree.TSTypeAssertion | TSESTree.UnaryExpressionBitwiseNot | TSESTree.UnaryExpressionDelete | TSESTree.UnaryExpressionMinus | TSESTree.UnaryExpressionNot | TSESTree.UnaryExpressionPlus | TSESTree.UnaryExpressionTypeof | TSESTree.UnaryExpressionVoid | TSESTree.UpdateExpression | TSESTree.ConstDeclaration | TSESTree.LetOrVarDeclaredDeclaration | TSESTree.LetOrVarNonDeclaredDeclaration | TSESTree.UsingInForOfDeclaration | TSESTree.UsingInNormalContextDeclaration | TSESTree.YieldExpression | null;
|
|
118
|
+
/**
|
|
119
|
+
* Type representing the possible assignment targets returned by `resolveEnclosingAssignmentTarget`
|
|
120
|
+
*/
|
|
121
|
+
type AssignmentTarget = ReturnType<typeof resolveEnclosingAssignmentTarget>;
|
|
122
|
+
//#endregion
|
|
123
123
|
//#region src/resolve-import-source.d.ts
|
|
124
124
|
declare function resolveImportSource(name: string, initialScope: Scope, visited?: Set<string>): string | null;
|
|
125
125
|
//#endregion
|
|
126
|
-
export { AssignmentTarget, ObjectType, computeObjectType,
|
|
126
|
+
export { AssignmentTarget, ObjectType, computeObjectType, getRequireExpressionArguments, isAssignmentTargetEqual, isValueEqual, resolve, resolveEnclosingAssignmentTarget, resolveImportSource };
|
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) {
|
|
@@ -173,25 +172,6 @@ function computeObjectType(context, node) {
|
|
|
173
172
|
}
|
|
174
173
|
}
|
|
175
174
|
|
|
176
|
-
//#endregion
|
|
177
|
-
//#region src/find-enclosing-assignment-target.ts
|
|
178
|
-
/**
|
|
179
|
-
* Finds the enclosing assignment target (variable, property, etc.) for a given node
|
|
180
|
-
*
|
|
181
|
-
* @param node The starting node
|
|
182
|
-
* @returns The enclosing assignment target node, or null if not found
|
|
183
|
-
*/
|
|
184
|
-
function findEnclosingAssignmentTarget(node) {
|
|
185
|
-
switch (true) {
|
|
186
|
-
case node.type === AST_NODE_TYPES.VariableDeclarator: return node.id;
|
|
187
|
-
case node.type === AST_NODE_TYPES.AssignmentExpression: return node.left;
|
|
188
|
-
case node.type === AST_NODE_TYPES.PropertyDefinition: return node.key;
|
|
189
|
-
case node.type === AST_NODE_TYPES.ExportDefaultDeclaration: return node.declaration;
|
|
190
|
-
case node.type === AST_NODE_TYPES.BlockStatement || node.type === AST_NODE_TYPES.Program: return null;
|
|
191
|
-
default: return findEnclosingAssignmentTarget(node.parent);
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
|
|
195
175
|
//#endregion
|
|
196
176
|
//#region ../../.pkgs/eff/dist/index.js
|
|
197
177
|
/**
|
|
@@ -357,8 +337,8 @@ const thisBlockTypes = [
|
|
|
357
337
|
* @returns `true` if node value equal
|
|
358
338
|
*/
|
|
359
339
|
function isValueEqual(context, a, b) {
|
|
360
|
-
a =
|
|
361
|
-
b =
|
|
340
|
+
a = Check.isTypeExpression(a) ? Extract.unwrapped(a) : a;
|
|
341
|
+
b = Check.isTypeExpression(b) ? Extract.unwrapped(b) : b;
|
|
362
342
|
const [aScope, bScope] = [context.sourceCode.getScope(a), context.sourceCode.getScope(b)];
|
|
363
343
|
switch (true) {
|
|
364
344
|
case a === b: return true;
|
|
@@ -376,12 +356,12 @@ function isValueEqual(context, a, b) {
|
|
|
376
356
|
const aDefParentParent = aDef?.parent?.parent;
|
|
377
357
|
const bDefParentParent = bDef?.parent?.parent;
|
|
378
358
|
switch (true) {
|
|
379
|
-
case aDefNodeParent?.type === AST_NODE_TYPES.CallExpression && bDefNodeParent?.type === AST_NODE_TYPES.CallExpression &&
|
|
380
|
-
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;
|
|
381
361
|
const aParams = aDefNode.params;
|
|
382
362
|
const bParams = bDefNode.params;
|
|
383
|
-
const aPos = aParams.findIndex((x) =>
|
|
384
|
-
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));
|
|
385
365
|
return aPos !== -1 && bPos !== -1 && aPos === bPos;
|
|
386
366
|
}
|
|
387
367
|
case aDefParentParent?.type === AST_NODE_TYPES.ForOfStatement && bDefParentParent?.type === AST_NODE_TYPES.ForOfStatement: {
|
|
@@ -390,17 +370,17 @@ function isValueEqual(context, a, b) {
|
|
|
390
370
|
if (aLeft.type !== bLeft.type) return false;
|
|
391
371
|
const aRight = aDefParentParent.right;
|
|
392
372
|
const bRight = bDefParentParent.right;
|
|
393
|
-
if (!
|
|
373
|
+
if (!Compare.areEqual(aRight, bRight)) return false;
|
|
394
374
|
if (aDefParentParent === bDefParentParent) return aVar != null && bVar != null && aVar === bVar;
|
|
395
375
|
return true;
|
|
396
376
|
}
|
|
397
377
|
default: return aVar != null && bVar != null && aVar === bVar;
|
|
398
378
|
}
|
|
399
379
|
}
|
|
400
|
-
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);
|
|
401
381
|
case a.type === AST_NODE_TYPES.ThisExpression && b.type === AST_NODE_TYPES.ThisExpression:
|
|
402
382
|
if (aScope.block === bScope.block) return true;
|
|
403
|
-
return
|
|
383
|
+
return Traverse.findParent(a, isOneOf(thisBlockTypes)) === Traverse.findParent(b, isOneOf(thisBlockTypes));
|
|
404
384
|
default: {
|
|
405
385
|
const aStatic = getStaticValue(a, aScope);
|
|
406
386
|
const bStatic = getStaticValue(b, bScope);
|
|
@@ -421,7 +401,26 @@ function isValueEqual(context, a, b) {
|
|
|
421
401
|
* @internal
|
|
422
402
|
*/
|
|
423
403
|
function isAssignmentTargetEqual(context, a, b) {
|
|
424
|
-
return
|
|
404
|
+
return Compare.areEqual(a, b) || isValueEqual(context, a, b);
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
//#endregion
|
|
408
|
+
//#region src/resolve-enclosing-assignment-target.ts
|
|
409
|
+
/**
|
|
410
|
+
* Finds the enclosing assignment target (variable, property, etc.) for a given node
|
|
411
|
+
*
|
|
412
|
+
* @param node The starting node
|
|
413
|
+
* @returns The enclosing assignment target node, or null if not found
|
|
414
|
+
*/
|
|
415
|
+
function resolveEnclosingAssignmentTarget(node) {
|
|
416
|
+
switch (true) {
|
|
417
|
+
case node.type === AST_NODE_TYPES.VariableDeclarator: return node.id;
|
|
418
|
+
case node.type === AST_NODE_TYPES.AssignmentExpression: return node.left;
|
|
419
|
+
case node.type === AST_NODE_TYPES.PropertyDefinition: return node.key;
|
|
420
|
+
case node.type === AST_NODE_TYPES.ExportDefaultDeclaration: return node.declaration;
|
|
421
|
+
case node.type === AST_NODE_TYPES.BlockStatement || node.type === AST_NODE_TYPES.Program: return null;
|
|
422
|
+
default: return resolveEnclosingAssignmentTarget(node.parent);
|
|
423
|
+
}
|
|
425
424
|
}
|
|
426
425
|
|
|
427
426
|
//#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;
|
|
@@ -445,4 +444,4 @@ function resolveImportSource(name, initialScope, visited = /* @__PURE__ */ new S
|
|
|
445
444
|
}
|
|
446
445
|
|
|
447
446
|
//#endregion
|
|
448
|
-
export { computeObjectType,
|
|
447
|
+
export { computeObjectType, getRequireExpressionArguments, isAssignmentTargetEqual, isValueEqual, resolve, resolveEnclosingAssignmentTarget, resolveImportSource };
|
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-beta.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/ast": "5.2.
|
|
38
|
-
"@eslint-react/
|
|
39
|
-
"@eslint-react/
|
|
37
|
+
"@eslint-react/ast": "5.2.2-beta.0",
|
|
38
|
+
"@eslint-react/shared": "5.2.2-beta.0",
|
|
39
|
+
"@eslint-react/eslint": "5.2.2-beta.0"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@typescript-eslint/typescript-estree": "^8.58.1",
|