@eslint-react/var 4.2.0-beta.1 → 4.2.0-beta.2
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 -2
- package/dist/index.js +27 -11
- package/package.json +5 -5
package/dist/index.d.ts
CHANGED
|
@@ -43,11 +43,10 @@ declare function computeObjectType(context: RuleContext, node: TSESTree.Node | n
|
|
|
43
43
|
/**
|
|
44
44
|
* Finds the enclosing assignment target (variable, property, etc.) for a given node
|
|
45
45
|
*
|
|
46
|
-
* @todo Verify correctness and completeness of this function
|
|
47
46
|
* @param node The starting node
|
|
48
47
|
* @returns The enclosing assignment target node, or null if not found
|
|
49
48
|
*/
|
|
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.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;
|
|
49
|
+
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
50
|
/**
|
|
52
51
|
* Type representing the possible assignment targets returned by `findEnclosingAssignmentTarget`
|
|
53
52
|
*/
|
package/dist/index.js
CHANGED
|
@@ -117,14 +117,10 @@ function computeObjectType(context, node) {
|
|
|
117
117
|
if (initNode == null) return null;
|
|
118
118
|
return computeObjectType(context, initNode);
|
|
119
119
|
}
|
|
120
|
-
case AST_NODE_TYPES.MemberExpression:
|
|
121
|
-
if (!("object" in node)) return null;
|
|
122
|
-
return computeObjectType(context, node.object);
|
|
120
|
+
case AST_NODE_TYPES.MemberExpression: return computeObjectType(context, node.object);
|
|
123
121
|
case AST_NODE_TYPES.AssignmentExpression:
|
|
124
|
-
case AST_NODE_TYPES.AssignmentPattern:
|
|
125
|
-
|
|
126
|
-
return computeObjectType(context, node.right);
|
|
127
|
-
case AST_NODE_TYPES.LogicalExpression: return computeObjectType(context, node.right);
|
|
122
|
+
case AST_NODE_TYPES.AssignmentPattern: return computeObjectType(context, node.right);
|
|
123
|
+
case AST_NODE_TYPES.LogicalExpression: return computeObjectType(context, node.left) ?? computeObjectType(context, node.right);
|
|
128
124
|
case AST_NODE_TYPES.ConditionalExpression: return computeObjectType(context, node.consequent) ?? computeObjectType(context, node.alternate);
|
|
129
125
|
case AST_NODE_TYPES.SequenceExpression:
|
|
130
126
|
if (node.expressions.length === 0) return null;
|
|
@@ -147,6 +143,24 @@ function computeObjectType(context, node) {
|
|
|
147
143
|
node
|
|
148
144
|
};
|
|
149
145
|
}
|
|
146
|
+
if (node.callee.type === AST_NODE_TYPES.MemberExpression && isIdentifier(node.callee.object) && isIdentifier(node.callee.property)) {
|
|
147
|
+
const objName = node.callee.object.name;
|
|
148
|
+
const methodName = node.callee.property.name;
|
|
149
|
+
switch (objName) {
|
|
150
|
+
case "Array":
|
|
151
|
+
if (methodName === "from" || methodName === "of") return {
|
|
152
|
+
kind: "array",
|
|
153
|
+
node
|
|
154
|
+
};
|
|
155
|
+
break;
|
|
156
|
+
case "Object":
|
|
157
|
+
if (methodName === "create" || methodName === "assign" || methodName === "fromEntries") return {
|
|
158
|
+
kind: "plain",
|
|
159
|
+
node
|
|
160
|
+
};
|
|
161
|
+
break;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
150
164
|
return {
|
|
151
165
|
kind: "unknown",
|
|
152
166
|
node,
|
|
@@ -163,7 +177,6 @@ function computeObjectType(context, node) {
|
|
|
163
177
|
/**
|
|
164
178
|
* Finds the enclosing assignment target (variable, property, etc.) for a given node
|
|
165
179
|
*
|
|
166
|
-
* @todo Verify correctness and completeness of this function
|
|
167
180
|
* @param node The starting node
|
|
168
181
|
* @returns The enclosing assignment target node, or null if not found
|
|
169
182
|
*/
|
|
@@ -172,7 +185,8 @@ function findEnclosingAssignmentTarget(node) {
|
|
|
172
185
|
case node.type === AST_NODE_TYPES.VariableDeclarator: return node.id;
|
|
173
186
|
case node.type === AST_NODE_TYPES.AssignmentExpression: return node.left;
|
|
174
187
|
case node.type === AST_NODE_TYPES.PropertyDefinition: return node.key;
|
|
175
|
-
case node.type === AST_NODE_TYPES.
|
|
188
|
+
case node.type === AST_NODE_TYPES.ExportDefaultDeclaration: return node.declaration;
|
|
189
|
+
case node.type === AST_NODE_TYPES.BlockStatement || node.type === AST_NODE_TYPES.Program: return null;
|
|
176
190
|
default: return findEnclosingAssignmentTarget(node.parent);
|
|
177
191
|
}
|
|
178
192
|
}
|
|
@@ -226,12 +240,14 @@ function isValueEqual(context, a, b) {
|
|
|
226
240
|
if (aLeft.type !== bLeft.type) return false;
|
|
227
241
|
const aRight = aDefParentParent.right;
|
|
228
242
|
const bRight = bDefParentParent.right;
|
|
229
|
-
|
|
243
|
+
if (!ast.isNodeEqual(aRight, bRight)) return false;
|
|
244
|
+
if (aDefParentParent === bDefParentParent) return aVar != null && bVar != null && aVar === bVar;
|
|
245
|
+
return true;
|
|
230
246
|
}
|
|
231
247
|
default: return aVar != null && bVar != null && aVar === bVar;
|
|
232
248
|
}
|
|
233
249
|
}
|
|
234
|
-
case a.type === AST_NODE_TYPES.MemberExpression && b.type === AST_NODE_TYPES.MemberExpression: return ast.isNodeEqual(a.property, b.property) && isValueEqual(context, a.object, b.object);
|
|
250
|
+
case a.type === AST_NODE_TYPES.MemberExpression && b.type === AST_NODE_TYPES.MemberExpression: return (a.computed && b.computed ? isValueEqual(context, a.property, b.property) : ast.isNodeEqual(a.property, b.property)) && isValueEqual(context, a.object, b.object);
|
|
235
251
|
case a.type === AST_NODE_TYPES.ThisExpression && b.type === AST_NODE_TYPES.ThisExpression:
|
|
236
252
|
if (aScope.block === bScope.block) return true;
|
|
237
253
|
return ast.findParent(a, ast.isOneOf(thisBlockTypes)) === ast.findParent(b, ast.isOneOf(thisBlockTypes));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eslint-react/var",
|
|
3
|
-
"version": "4.2.0-beta.
|
|
3
|
+
"version": "4.2.0-beta.2",
|
|
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,14 +34,14 @@
|
|
|
34
34
|
"@typescript-eslint/types": "^8.58.0",
|
|
35
35
|
"@typescript-eslint/utils": "^8.58.0",
|
|
36
36
|
"ts-pattern": "^5.9.0",
|
|
37
|
-
"@eslint-react/ast": "4.2.0-beta.
|
|
38
|
-
"@eslint-react/shared": "4.2.0-beta.
|
|
37
|
+
"@eslint-react/ast": "4.2.0-beta.2",
|
|
38
|
+
"@eslint-react/shared": "4.2.0-beta.2"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@typescript-eslint/typescript-estree": "^8.58.0",
|
|
42
42
|
"tsdown": "^0.21.7",
|
|
43
|
-
"@local/
|
|
44
|
-
"@local/
|
|
43
|
+
"@local/configs": "0.0.0",
|
|
44
|
+
"@local/eff": "3.0.0-beta.72"
|
|
45
45
|
},
|
|
46
46
|
"peerDependencies": {
|
|
47
47
|
"eslint": "^10.0.0",
|