@typescript-eslint/eslint-plugin 8.64.1-alpha.5 → 8.64.1-alpha.6
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/rules/unbound-method.js +36 -9
- package/package.json +8 -8
|
@@ -153,6 +153,31 @@ exports.default = (0, util_1.createRule)({
|
|
|
153
153
|
}
|
|
154
154
|
return false;
|
|
155
155
|
}
|
|
156
|
+
function checkUnionConstituentsAndReport(reportNode, propertyName, type) {
|
|
157
|
+
for (const intersectionPart of tsutils
|
|
158
|
+
.unionConstituents(type)
|
|
159
|
+
.flatMap(unionPart => tsutils.intersectionConstituents(unionPart))) {
|
|
160
|
+
const reported = checkIfMethodAndReport(reportNode, intersectionPart.getProperty(propertyName));
|
|
161
|
+
if (reported) {
|
|
162
|
+
return true;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
return false;
|
|
166
|
+
}
|
|
167
|
+
function getAccessedPropertyNames(node) {
|
|
168
|
+
if (!node.computed) {
|
|
169
|
+
return node.property.type === utils_1.AST_NODE_TYPES.Identifier
|
|
170
|
+
? [node.property.name]
|
|
171
|
+
: [];
|
|
172
|
+
}
|
|
173
|
+
return tsutils
|
|
174
|
+
.unionConstituents(services.getTypeAtLocation(node.property))
|
|
175
|
+
.flatMap(part => {
|
|
176
|
+
return part.isStringLiteral() || part.isNumberLiteral()
|
|
177
|
+
? [part.value.toString()]
|
|
178
|
+
: [];
|
|
179
|
+
});
|
|
180
|
+
}
|
|
156
181
|
function isNativelyBound(object, property) {
|
|
157
182
|
// We can't rely entirely on the type-level checks made at the end of this
|
|
158
183
|
// function, because sometimes type declarations don't come from the
|
|
@@ -181,7 +206,16 @@ exports.default = (0, util_1.createRule)({
|
|
|
181
206
|
if (isSafeUse(node) || isNativelyBound(node.object, node.property)) {
|
|
182
207
|
return;
|
|
183
208
|
}
|
|
184
|
-
|
|
209
|
+
const propertyNames = getAccessedPropertyNames(node);
|
|
210
|
+
if (propertyNames.length === 0) {
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
const objectType = services.getTypeAtLocation(node.object);
|
|
214
|
+
for (const propertyName of propertyNames) {
|
|
215
|
+
if (checkUnionConstituentsAndReport(node, propertyName, objectType)) {
|
|
216
|
+
break;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
185
219
|
},
|
|
186
220
|
ObjectPattern(node) {
|
|
187
221
|
if (isNodeInsideTypeDeclaration(node)) {
|
|
@@ -217,14 +251,7 @@ exports.default = (0, util_1.createRule)({
|
|
|
217
251
|
continue;
|
|
218
252
|
}
|
|
219
253
|
}
|
|
220
|
-
|
|
221
|
-
.unionConstituents(services.getTypeAtLocation(node))
|
|
222
|
-
.flatMap(unionPart => tsutils.intersectionConstituents(unionPart))) {
|
|
223
|
-
const reported = checkIfMethodAndReport(property.key, intersectionPart.getProperty(property.key.name));
|
|
224
|
-
if (reported) {
|
|
225
|
-
break;
|
|
226
|
-
}
|
|
227
|
-
}
|
|
254
|
+
checkUnionConstituentsAndReport(property.key, property.key.name, services.getTypeAtLocation(node));
|
|
228
255
|
}
|
|
229
256
|
},
|
|
230
257
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@typescript-eslint/eslint-plugin",
|
|
3
|
-
"version": "8.64.1-alpha.
|
|
3
|
+
"version": "8.64.1-alpha.6",
|
|
4
4
|
"description": "TypeScript plugin for ESLint",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist",
|
|
@@ -49,10 +49,10 @@
|
|
|
49
49
|
"ignore": "^7.0.5",
|
|
50
50
|
"natural-compare": "^1.4.0",
|
|
51
51
|
"ts-api-utils": "^2.5.0",
|
|
52
|
-
"@typescript-eslint/scope-manager": "8.64.1-alpha.
|
|
53
|
-
"@typescript-eslint/
|
|
54
|
-
"@typescript-eslint/
|
|
55
|
-
"@typescript-eslint/
|
|
52
|
+
"@typescript-eslint/scope-manager": "8.64.1-alpha.6",
|
|
53
|
+
"@typescript-eslint/type-utils": "8.64.1-alpha.6",
|
|
54
|
+
"@typescript-eslint/utils": "8.64.1-alpha.6",
|
|
55
|
+
"@typescript-eslint/visitor-keys": "8.64.1-alpha.6"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
58
|
"@types/json-schema": "^7.0.15",
|
|
@@ -76,13 +76,13 @@
|
|
|
76
76
|
"typescript": ">=4.8.4 <6.1.0",
|
|
77
77
|
"unist-util-visit": "^5.0.0",
|
|
78
78
|
"vitest": "^4.0.18",
|
|
79
|
-
"@typescript-eslint/rule-schema-to-typescript-types": "8.64.1-alpha.
|
|
80
|
-
"@typescript-eslint/rule-tester": "8.64.1-alpha.
|
|
79
|
+
"@typescript-eslint/rule-schema-to-typescript-types": "8.64.1-alpha.6",
|
|
80
|
+
"@typescript-eslint/rule-tester": "8.64.1-alpha.6"
|
|
81
81
|
},
|
|
82
82
|
"peerDependencies": {
|
|
83
83
|
"eslint": "^8.57.0 || ^9.0.0 || ^10.0.0",
|
|
84
84
|
"typescript": ">=4.8.4 <6.1.0",
|
|
85
|
-
"@typescript-eslint/parser": "^8.64.1-alpha.
|
|
85
|
+
"@typescript-eslint/parser": "^8.64.1-alpha.6"
|
|
86
86
|
},
|
|
87
87
|
"funding": {
|
|
88
88
|
"type": "opencollective",
|