@typescript-eslint/eslint-plugin 8.60.1-alpha.1 → 8.60.1-alpha.10
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/ban-ts-comment.js +1 -1
- package/dist/rules/naming-convention.js +1 -0
- 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-shadow.js +46 -16
- package/dist/rules/no-unsafe-return.js +3 -3
- package/dist/rules/prefer-nullish-coalescing.js +4 -4
- package/dist/rules/prefer-ts-expect-error.js +1 -1
- package/dist/rules/strict-void-return.js +3 -0
- package/package.json +13 -10
|
@@ -121,7 +121,7 @@ exports.default = (0, util_1.createRule)({
|
|
|
121
121
|
}
|
|
122
122
|
return execDirectiveRegEx(commentDirectiveRegExSingleLine, comment.value);
|
|
123
123
|
}
|
|
124
|
-
const commentLines = comment.value.split(
|
|
124
|
+
const commentLines = comment.value.split(utils_1.ASTUtils.LINEBREAK_MATCHER);
|
|
125
125
|
return execDirectiveRegEx(commentDirectiveRegExMultiLine, commentLines[commentLines.length - 1]);
|
|
126
126
|
}
|
|
127
127
|
return {
|
|
@@ -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);
|
package/dist/rules/no-shadow.js
CHANGED
|
@@ -322,29 +322,59 @@ exports.default = (0, util_1.createRule)({
|
|
|
322
322
|
return false;
|
|
323
323
|
}
|
|
324
324
|
/**
|
|
325
|
-
*
|
|
325
|
+
* Finds the uppermost expression node that can evaluate to the given one,
|
|
326
|
+
* unwrapping through LogicalExpression and non-test ConditionalExpression branches.
|
|
327
|
+
* @param node The node to unwrap.
|
|
328
|
+
* @returns The topmost unwrapped node.
|
|
329
|
+
*/
|
|
330
|
+
function unwrapExpression(node) {
|
|
331
|
+
const { parent } = node;
|
|
332
|
+
if (parent?.type === utils_1.AST_NODE_TYPES.LogicalExpression ||
|
|
333
|
+
(parent?.type === utils_1.AST_NODE_TYPES.ConditionalExpression &&
|
|
334
|
+
parent.test !== node)) {
|
|
335
|
+
return unwrapExpression(parent);
|
|
336
|
+
}
|
|
337
|
+
return node;
|
|
338
|
+
}
|
|
339
|
+
/**
|
|
340
|
+
* Checks if a variable is the name of a function or class expression that is
|
|
341
|
+
* directly assigned (or transparently through `||`/`?:`) as the initializer
|
|
342
|
+
* of scopeVar.
|
|
326
343
|
*
|
|
327
|
-
*
|
|
328
|
-
* But it should report `var a = function(a) {};` or `var a = function() { function a() {} };`.
|
|
344
|
+
* Allows `var a = function a() {}` but reports `var a = wrap(function a() {})`.
|
|
329
345
|
* @param variable The variable to check.
|
|
330
346
|
* @param scopeVar The scope variable to look for.
|
|
331
|
-
* @returns Whether or not the variable is
|
|
347
|
+
* @returns Whether or not the variable is the direct initializer name of scopeVar.
|
|
332
348
|
*/
|
|
333
349
|
function isOnInitializer(variable, scopeVar) {
|
|
334
|
-
const outerScope = scopeVar.scope;
|
|
335
350
|
const outerDef = scopeVar.defs.at(0);
|
|
336
|
-
const outer = outerDef?.parent?.range;
|
|
337
|
-
const innerScope = variable.scope;
|
|
338
351
|
const innerDef = variable.defs.at(0);
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
(
|
|
345
|
-
innerDef.node.type === utils_1.AST_NODE_TYPES.
|
|
346
|
-
|
|
347
|
-
|
|
352
|
+
if (!outerDef || !innerDef) {
|
|
353
|
+
return false;
|
|
354
|
+
}
|
|
355
|
+
if (!((innerDef.type === scope_manager_1.DefinitionType.FunctionName &&
|
|
356
|
+
innerDef.node.type === utils_1.AST_NODE_TYPES.FunctionExpression) ||
|
|
357
|
+
(innerDef.type === scope_manager_1.DefinitionType.ClassName &&
|
|
358
|
+
innerDef.node.type === utils_1.AST_NODE_TYPES.ClassExpression))) {
|
|
359
|
+
return false;
|
|
360
|
+
}
|
|
361
|
+
const outerIdentifier = outerDef.name;
|
|
362
|
+
let initializerNode;
|
|
363
|
+
if (outerIdentifier.parent.type === utils_1.AST_NODE_TYPES.VariableDeclarator) {
|
|
364
|
+
initializerNode = outerIdentifier.parent.init;
|
|
365
|
+
}
|
|
366
|
+
else if (outerIdentifier.parent.type === utils_1.AST_NODE_TYPES.AssignmentPattern) {
|
|
367
|
+
initializerNode = outerIdentifier.parent.right;
|
|
368
|
+
}
|
|
369
|
+
if (!initializerNode) {
|
|
370
|
+
return false;
|
|
371
|
+
}
|
|
372
|
+
const nodeToCheck = innerDef.node;
|
|
373
|
+
if (!(initializerNode.range[0] <= nodeToCheck.range[0] &&
|
|
374
|
+
nodeToCheck.range[1] <= initializerNode.range[1])) {
|
|
375
|
+
return false;
|
|
376
|
+
}
|
|
377
|
+
return initializerNode === unwrapExpression(nodeToCheck);
|
|
348
378
|
}
|
|
349
379
|
/**
|
|
350
380
|
* Get a range of a variable's identifier node.
|
|
@@ -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) {
|
|
@@ -40,7 +40,7 @@ exports.default = (0, util_1.createRule)({
|
|
|
40
40
|
return comment.value;
|
|
41
41
|
}
|
|
42
42
|
// For multiline comments - we look at only the last line.
|
|
43
|
-
const commentlines = comment.value.split(
|
|
43
|
+
const commentlines = comment.value.split(utils_1.ASTUtils.LINEBREAK_MATCHER);
|
|
44
44
|
return commentlines[commentlines.length - 1];
|
|
45
45
|
}
|
|
46
46
|
function isValidTsIgnorePresent(comment) {
|
|
@@ -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.10",
|
|
4
4
|
"description": "TypeScript plugin for ESLint",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist",
|
|
@@ -52,16 +52,17 @@
|
|
|
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/
|
|
58
|
-
"@typescript-eslint/
|
|
55
|
+
"@typescript-eslint/scope-manager": "8.60.1-alpha.10",
|
|
56
|
+
"@typescript-eslint/type-utils": "8.60.1-alpha.10",
|
|
57
|
+
"@typescript-eslint/visitor-keys": "8.60.1-alpha.10",
|
|
58
|
+
"@typescript-eslint/utils": "8.60.1-alpha.10"
|
|
59
59
|
},
|
|
60
60
|
"devDependencies": {
|
|
61
61
|
"@types/json-schema": "^7.0.15",
|
|
62
62
|
"@types/mdast": "^4.0.4",
|
|
63
63
|
"@types/natural-compare": "^1.4.3",
|
|
64
64
|
"@types/react": "^18.3.21",
|
|
65
|
+
"@typescript/native-preview": "7.0.0-dev.20260518.1",
|
|
65
66
|
"@vitest/coverage-v8": "^4.0.18",
|
|
66
67
|
"ajv": "^6.12.6",
|
|
67
68
|
"eslint": "^10.0.0",
|
|
@@ -78,13 +79,13 @@
|
|
|
78
79
|
"typescript": ">=4.8.4 <6.1.0",
|
|
79
80
|
"unist-util-visit": "^5.0.0",
|
|
80
81
|
"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.
|
|
82
|
+
"@typescript-eslint/rule-schema-to-typescript-types": "8.60.1-alpha.10",
|
|
83
|
+
"@typescript-eslint/rule-tester": "8.60.1-alpha.10"
|
|
83
84
|
},
|
|
84
85
|
"peerDependencies": {
|
|
85
86
|
"eslint": "^8.57.0 || ^9.0.0 || ^10.0.0",
|
|
86
87
|
"typescript": ">=4.8.4 <6.1.0",
|
|
87
|
-
"@typescript-eslint/parser": "^8.60.1-alpha.
|
|
88
|
+
"@typescript-eslint/parser": "^8.60.1-alpha.10"
|
|
88
89
|
},
|
|
89
90
|
"funding": {
|
|
90
91
|
"type": "opencollective",
|
|
@@ -107,7 +108,8 @@
|
|
|
107
108
|
},
|
|
108
109
|
"lint": {
|
|
109
110
|
"command": "eslint"
|
|
110
|
-
}
|
|
111
|
+
},
|
|
112
|
+
"typecheck:tsgo": {}
|
|
111
113
|
}
|
|
112
114
|
},
|
|
113
115
|
"scripts": {
|
|
@@ -118,6 +120,7 @@
|
|
|
118
120
|
"generate-configs": "pnpm -w run generate-configs",
|
|
119
121
|
"lint": "pnpm -w exec nx lint",
|
|
120
122
|
"test": "pnpm -w exec nx test",
|
|
121
|
-
"typecheck": "pnpm -w exec nx typecheck"
|
|
123
|
+
"typecheck": "pnpm -w exec nx typecheck",
|
|
124
|
+
"typecheck:tsgo": "pnpm -w exec nx typecheck:tsgo"
|
|
122
125
|
}
|
|
123
126
|
}
|