@typescript-eslint/eslint-plugin 8.60.1-alpha.2 → 8.60.1-alpha.4
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/no-base-to-string.js +2 -2
- package/dist/rules/no-confusing-void-expression.js +5 -5
- package/dist/rules/no-duplicate-type-constituents.js +14 -6
- package/dist/rules/no-unsafe-return.js +3 -3
- package/dist/rules/prefer-nullish-coalescing.js +4 -4
- package/dist/rules/strict-void-return.js +3 -0
- package/package.json +8 -8
|
@@ -289,8 +289,8 @@ exports.default = (0, util_1.createRule)({
|
|
|
289
289
|
if ((0, util_1.getTypeName)(checker, leftType) === 'string') {
|
|
290
290
|
checkExpression(node.right, rightType);
|
|
291
291
|
}
|
|
292
|
-
else if (
|
|
293
|
-
|
|
292
|
+
else if (node.left.type !== utils_1.AST_NODE_TYPES.PrivateIdentifier &&
|
|
293
|
+
(0, util_1.getTypeName)(checker, rightType) === 'string') {
|
|
294
294
|
checkExpression(node.left, leftType);
|
|
295
295
|
}
|
|
296
296
|
},
|
|
@@ -99,16 +99,16 @@ exports.default = (0, util_1.createRule)({
|
|
|
99
99
|
const services = (0, util_1.getParserServices)(context);
|
|
100
100
|
return {
|
|
101
101
|
'AwaitExpression, CallExpression, TaggedTemplateExpression'(node) {
|
|
102
|
-
const type = (0, util_1.getConstrainedTypeAtLocation)(services, node);
|
|
103
|
-
if (!tsutils.isTypeFlagSet(type, ts.TypeFlags.VoidLike)) {
|
|
104
|
-
// not a void expression
|
|
105
|
-
return;
|
|
106
|
-
}
|
|
107
102
|
const invalidAncestor = findInvalidAncestor(node);
|
|
108
103
|
if (invalidAncestor == null) {
|
|
109
104
|
// void expression is in valid position
|
|
110
105
|
return;
|
|
111
106
|
}
|
|
107
|
+
const type = (0, util_1.getConstrainedTypeAtLocation)(services, node);
|
|
108
|
+
if (!tsutils.isTypeFlagSet(type, ts.TypeFlags.VoidLike)) {
|
|
109
|
+
// not a void expression
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
112
|
const wrapVoidFix = (fixer) => {
|
|
113
113
|
const nodeText = context.sourceCode.getText(node);
|
|
114
114
|
const newNodeText = `void ${nodeText}`;
|
|
@@ -148,17 +148,25 @@ exports.default = (0, util_1.createRule)({
|
|
|
148
148
|
});
|
|
149
149
|
}
|
|
150
150
|
function checkDuplicateRecursively(unionOrIntersection, constituentNode, uniqueConstituents, cachedTypeMap, forEachNodeType) {
|
|
151
|
+
const reportDuplicate = (previous) => {
|
|
152
|
+
report('duplicate', constituentNode, {
|
|
153
|
+
type: unionOrIntersection,
|
|
154
|
+
previous: sourceCode.getText(previous),
|
|
155
|
+
});
|
|
156
|
+
};
|
|
157
|
+
// Check duplicates in the AST before type lookup for better performance.
|
|
158
|
+
let duplicatedPrevious = uniqueConstituents.find(ele => isSameAstNode(ele, constituentNode));
|
|
159
|
+
if (duplicatedPrevious) {
|
|
160
|
+
reportDuplicate(duplicatedPrevious);
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
151
163
|
const type = parserServices.getTypeAtLocation(constituentNode);
|
|
152
164
|
if (tsutils.isIntrinsicErrorType(type)) {
|
|
153
165
|
return;
|
|
154
166
|
}
|
|
155
|
-
|
|
156
|
-
cachedTypeMap.get(type);
|
|
167
|
+
duplicatedPrevious = cachedTypeMap.get(type);
|
|
157
168
|
if (duplicatedPrevious) {
|
|
158
|
-
|
|
159
|
-
type: unionOrIntersection,
|
|
160
|
-
previous: sourceCode.getText(duplicatedPrevious),
|
|
161
|
-
});
|
|
169
|
+
reportDuplicate(duplicatedPrevious);
|
|
162
170
|
return;
|
|
163
171
|
}
|
|
164
172
|
forEachNodeType?.(type, constituentNode);
|
|
@@ -63,13 +63,13 @@ exports.default = (0, util_1.createRule)({
|
|
|
63
63
|
const compilerOptions = services.program.getCompilerOptions();
|
|
64
64
|
const isNoImplicitThis = tsutils.isStrictCompilerOptionEnabled(compilerOptions, 'noImplicitThis');
|
|
65
65
|
function checkReturn(returnNode, reportingNode = returnNode) {
|
|
66
|
-
const tsNode = services.esTreeNodeToTSNodeMap.get(returnNode);
|
|
67
|
-
const type = checker.getTypeAtLocation(tsNode);
|
|
68
|
-
const anyType = (0, util_1.discriminateAnyType)(type, checker, services.program, tsNode);
|
|
69
66
|
const functionNode = (0, getParentFunctionNode_1.getParentFunctionNode)(returnNode);
|
|
70
67
|
/* istanbul ignore if */ if (!functionNode) {
|
|
71
68
|
return;
|
|
72
69
|
}
|
|
70
|
+
const tsNode = services.esTreeNodeToTSNodeMap.get(returnNode);
|
|
71
|
+
const type = checker.getTypeAtLocation(tsNode);
|
|
72
|
+
const anyType = (0, util_1.discriminateAnyType)(type, checker, services.program, tsNode);
|
|
73
73
|
// function has an explicit return type, so ensure it's a safe return
|
|
74
74
|
const returnNodeType = services.getTypeAtLocation(returnNode);
|
|
75
75
|
const constrainedReturnNodeType = (0, util_1.getConstrainedTypeAtLocation)(services, returnNode);
|
|
@@ -216,10 +216,6 @@ exports.default = (0, util_1.createRule)({
|
|
|
216
216
|
* @param testNode The node being tested (i.e. `a`)
|
|
217
217
|
*/
|
|
218
218
|
function isTruthinessCheckEligibleForPreferNullish({ node, testNode, }) {
|
|
219
|
-
const testType = parserServices.getTypeAtLocation(testNode);
|
|
220
|
-
if (!isTypeEligibleForPreferNullish(testType)) {
|
|
221
|
-
return false;
|
|
222
|
-
}
|
|
223
219
|
if (ignoreConditionalTests === true && isConditionalTest(node)) {
|
|
224
220
|
return false;
|
|
225
221
|
}
|
|
@@ -229,6 +225,10 @@ exports.default = (0, util_1.createRule)({
|
|
|
229
225
|
node.parent.type === utils_1.AST_NODE_TYPES.CallExpression)) {
|
|
230
226
|
return false;
|
|
231
227
|
}
|
|
228
|
+
const testType = parserServices.getTypeAtLocation(testNode);
|
|
229
|
+
if (!isTypeEligibleForPreferNullish(testType)) {
|
|
230
|
+
return false;
|
|
231
|
+
}
|
|
232
232
|
return true;
|
|
233
233
|
}
|
|
234
234
|
function checkAndFixWithPreferNullishOverOr(node, description, equals) {
|
|
@@ -153,6 +153,9 @@ exports.default = util.createRule({
|
|
|
153
153
|
* and report them too.
|
|
154
154
|
*/
|
|
155
155
|
function checkFunctionCallNode(callNode) {
|
|
156
|
+
if (callNode.arguments.length === 0) {
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
156
159
|
const callTsNode = parserServices.esTreeNodeToTSNodeMap.get(callNode);
|
|
157
160
|
const funcType = checker.getTypeAtLocation(callTsNode.expression);
|
|
158
161
|
const funcSignatures = tsutils
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@typescript-eslint/eslint-plugin",
|
|
3
|
-
"version": "8.60.1-alpha.
|
|
3
|
+
"version": "8.60.1-alpha.4",
|
|
4
4
|
"description": "TypeScript plugin for ESLint",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist",
|
|
@@ -52,10 +52,10 @@
|
|
|
52
52
|
"ignore": "^7.0.5",
|
|
53
53
|
"natural-compare": "^1.4.0",
|
|
54
54
|
"ts-api-utils": "^2.5.0",
|
|
55
|
-
"@typescript-eslint/scope-manager": "8.60.1-alpha.
|
|
56
|
-
"@typescript-eslint/type-utils": "8.60.1-alpha.
|
|
57
|
-
"@typescript-eslint/utils": "8.60.1-alpha.
|
|
58
|
-
"@typescript-eslint/visitor-keys": "8.60.1-alpha.
|
|
55
|
+
"@typescript-eslint/scope-manager": "8.60.1-alpha.4",
|
|
56
|
+
"@typescript-eslint/type-utils": "8.60.1-alpha.4",
|
|
57
|
+
"@typescript-eslint/utils": "8.60.1-alpha.4",
|
|
58
|
+
"@typescript-eslint/visitor-keys": "8.60.1-alpha.4"
|
|
59
59
|
},
|
|
60
60
|
"devDependencies": {
|
|
61
61
|
"@types/json-schema": "^7.0.15",
|
|
@@ -78,13 +78,13 @@
|
|
|
78
78
|
"typescript": ">=4.8.4 <6.1.0",
|
|
79
79
|
"unist-util-visit": "^5.0.0",
|
|
80
80
|
"vitest": "^4.0.18",
|
|
81
|
-
"@typescript-eslint/rule-schema-to-typescript-types": "8.60.1-alpha.
|
|
82
|
-
"@typescript-eslint/rule-tester": "8.60.1-alpha.
|
|
81
|
+
"@typescript-eslint/rule-schema-to-typescript-types": "8.60.1-alpha.4",
|
|
82
|
+
"@typescript-eslint/rule-tester": "8.60.1-alpha.4"
|
|
83
83
|
},
|
|
84
84
|
"peerDependencies": {
|
|
85
85
|
"eslint": "^8.57.0 || ^9.0.0 || ^10.0.0",
|
|
86
86
|
"typescript": ">=4.8.4 <6.1.0",
|
|
87
|
-
"@typescript-eslint/parser": "^8.60.1-alpha.
|
|
87
|
+
"@typescript-eslint/parser": "^8.60.1-alpha.4"
|
|
88
88
|
},
|
|
89
89
|
"funding": {
|
|
90
90
|
"type": "opencollective",
|