@typescript-eslint/eslint-plugin 8.25.1-alpha.9 → 8.26.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/configs/eslint-recommended-raw.d.ts.map +1 -1
- package/dist/rules/explicit-module-boundary-types.d.ts +1 -0
- package/dist/rules/explicit-module-boundary-types.d.ts.map +1 -1
- package/dist/rules/explicit-module-boundary-types.js +14 -0
- package/dist/rules/no-invalid-void-type.d.ts.map +1 -1
- package/dist/rules/no-invalid-void-type.js +1 -0
- package/dist/rules/no-unnecessary-type-assertion.d.ts.map +1 -1
- package/dist/rules/no-unnecessary-type-assertion.js +4 -0
- package/dist/rules/no-unnecessary-type-parameters.js +26 -9
- package/dist/rules/no-unused-vars.d.ts.map +1 -1
- package/dist/rules/no-unused-vars.js +52 -18
- package/dist/rules/unified-signatures.d.ts +1 -0
- package/dist/rules/unified-signatures.d.ts.map +1 -1
- package/dist/rules/unified-signatures.js +32 -2
- package/dist/util/getESLintCoreRule.d.ts.map +1 -1
- package/dist/util/getValueOfLiteralType.d.ts.map +1 -1
- package/dist/util/misc.d.ts.map +1 -1
- package/dist/util/truthinessAndNullishUtils.d.ts.map +1 -1
- package/docs/rules/consistent-return.mdx +1 -1
- package/docs/rules/explicit-module-boundary-types.mdx +14 -0
- package/docs/rules/no-unnecessary-type-parameters.mdx +22 -2
- package/docs/rules/unified-signatures.mdx +44 -0
- package/package.json +8 -8
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"eslint-recommended-raw.d.ts","sourceRoot":"","sources":["../../src/configs/eslint-recommended-raw.ts"],"names":[],"mappings":"AAIA;;;;GAIG;AACH,QAAA,MAAM,MAAM,
|
1
|
+
{"version":3,"file":"eslint-recommended-raw.d.ts","sourceRoot":"","sources":["../../src/configs/eslint-recommended-raw.ts"],"names":[],"mappings":"AAIA;;;;GAIG;AACH,QAAA,MAAM,MAAM,GACV,OAAO,MAAM,GAAG,WAAW,KAC1B;IACD,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,GAAG,MAAM,GAAG,OAAO,CAAC,CAAC;CAiChD,CAAC;AAEH,SAAS,MAAM,CAAC"}
|
@@ -5,6 +5,7 @@ export type Options = [
|
|
5
5
|
allowedNames?: string[];
|
6
6
|
allowHigherOrderFunctions?: boolean;
|
7
7
|
allowTypedFunctionExpressions?: boolean;
|
8
|
+
allowOverloadFunctions?: boolean;
|
8
9
|
}
|
9
10
|
];
|
10
11
|
export type MessageIds = 'anyTypedArg' | 'anyTypedArgUnnamed' | 'missingArgType' | 'missingArgTypeUnnamed' | 'missingReturnType';
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"explicit-module-boundary-types.d.ts","sourceRoot":"","sources":["../../src/rules/explicit-module-boundary-types.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"explicit-module-boundary-types.d.ts","sourceRoot":"","sources":["../../src/rules/explicit-module-boundary-types.ts"],"names":[],"mappings":"AAyBA,MAAM,MAAM,OAAO,GAAG;IACpB;QACE,kCAAkC,CAAC,EAAE,OAAO,CAAC;QAC7C,yCAAyC,CAAC,EAAE,OAAO,CAAC;QACpD,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;QACxB,yBAAyB,CAAC,EAAE,OAAO,CAAC;QACpC,6BAA6B,CAAC,EAAE,OAAO,CAAC;QACxC,sBAAsB,CAAC,EAAE,OAAO,CAAC;KAClC;CACF,CAAC;AACF,MAAM,MAAM,UAAU,GAClB,aAAa,GACb,oBAAoB,GACpB,gBAAgB,GAChB,uBAAuB,GACvB,mBAAmB,CAAC;;AAExB,wBAweG"}
|
@@ -48,6 +48,10 @@ exports.default = (0, util_1.createRule)({
|
|
48
48
|
'You must still type the parameters of the function.',
|
49
49
|
].join('\n'),
|
50
50
|
},
|
51
|
+
allowOverloadFunctions: {
|
52
|
+
type: 'boolean',
|
53
|
+
description: 'Whether to ignore return type annotations on functions with overload signatures.',
|
54
|
+
},
|
51
55
|
allowTypedFunctionExpressions: {
|
52
56
|
type: 'boolean',
|
53
57
|
description: 'Whether to ignore type annotations on the variable of a function expression.',
|
@@ -62,6 +66,7 @@ exports.default = (0, util_1.createRule)({
|
|
62
66
|
allowDirectConstAssertionInArrowFunctions: true,
|
63
67
|
allowedNames: [],
|
64
68
|
allowHigherOrderFunctions: true,
|
69
|
+
allowOverloadFunctions: false,
|
65
70
|
allowTypedFunctionExpressions: true,
|
66
71
|
},
|
67
72
|
],
|
@@ -342,6 +347,11 @@ exports.default = (0, util_1.createRule)({
|
|
342
347
|
(0, explicitReturnTypeUtils_1.ancestorHasReturnType)(node)) {
|
343
348
|
return;
|
344
349
|
}
|
350
|
+
if (options.allowOverloadFunctions &&
|
351
|
+
node.parent.type === utils_1.AST_NODE_TYPES.MethodDefinition &&
|
352
|
+
(0, util_1.hasOverloadSignatures)(node.parent, context)) {
|
353
|
+
return;
|
354
|
+
}
|
345
355
|
(0, explicitReturnTypeUtils_1.checkFunctionExpressionReturnType)({ node, returns }, options, context.sourceCode, loc => {
|
346
356
|
context.report({
|
347
357
|
loc,
|
@@ -359,6 +369,10 @@ exports.default = (0, util_1.createRule)({
|
|
359
369
|
if (isAllowedName(node) || (0, explicitReturnTypeUtils_1.ancestorHasReturnType)(node)) {
|
360
370
|
return;
|
361
371
|
}
|
372
|
+
if (options.allowOverloadFunctions &&
|
373
|
+
(0, util_1.hasOverloadSignatures)(node, context)) {
|
374
|
+
return;
|
375
|
+
}
|
362
376
|
(0, explicitReturnTypeUtils_1.checkFunctionReturnType)({ node, returns }, options, context.sourceCode, loc => {
|
363
377
|
context.report({
|
364
378
|
loc,
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"no-invalid-void-type.d.ts","sourceRoot":"","sources":["../../src/rules/no-invalid-void-type.ts"],"names":[],"mappings":"AAMA,MAAM,WAAW,OAAO;IACtB,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,2BAA2B,CAAC,EAAE,OAAO,GAAG,CAAC,MAAM,EAAE,GAAG,MAAM,EAAE,CAAC,CAAC;CAC/D;AAED,MAAM,MAAM,UAAU,GAClB,uBAAuB,GACvB,sBAAsB,GACtB,+BAA+B,GAC/B,iCAAiC,GACjC,0CAA0C,GAC1C,6BAA6B,CAAC;;AAElC,
|
1
|
+
{"version":3,"file":"no-invalid-void-type.d.ts","sourceRoot":"","sources":["../../src/rules/no-invalid-void-type.ts"],"names":[],"mappings":"AAMA,MAAM,WAAW,OAAO;IACtB,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,2BAA2B,CAAC,EAAE,OAAO,GAAG,CAAC,MAAM,EAAE,GAAG,MAAM,EAAE,CAAC,CAAC;CAC/D;AAED,MAAM,MAAM,UAAU,GAClB,uBAAuB,GACvB,sBAAsB,GACtB,+BAA+B,GAC/B,iCAAiC,GACjC,0CAA0C,GAC1C,6BAA6B,CAAC;;AAElC,wBA2OG"}
|
@@ -57,6 +57,7 @@ exports.default = (0, util_1.createRule)({
|
|
57
57
|
utils_1.AST_NODE_TYPES.TSPropertySignature,
|
58
58
|
utils_1.AST_NODE_TYPES.CallExpression,
|
59
59
|
utils_1.AST_NODE_TYPES.PropertyDefinition,
|
60
|
+
utils_1.AST_NODE_TYPES.AccessorProperty,
|
60
61
|
utils_1.AST_NODE_TYPES.Identifier,
|
61
62
|
];
|
62
63
|
const validUnionMembers = [
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"no-unnecessary-type-assertion.d.ts","sourceRoot":"","sources":["../../src/rules/no-unnecessary-type-assertion.ts"],"names":[],"mappings":"AAqBA,MAAM,MAAM,OAAO,GAAG;IACpB;QACE,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;KAC1B;CACF,CAAC;AACF,MAAM,MAAM,UAAU,GAAG,yBAAyB,GAAG,sBAAsB,CAAC;;AAE5E,
|
1
|
+
{"version":3,"file":"no-unnecessary-type-assertion.d.ts","sourceRoot":"","sources":["../../src/rules/no-unnecessary-type-assertion.ts"],"names":[],"mappings":"AAqBA,MAAM,MAAM,OAAO,GAAG;IACpB;QACE,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;KAC1B;CACF,CAAC;AACF,MAAM,MAAM,UAAU,GAAG,yBAAyB,GAAG,sBAAsB,CAAC;;AAE5E,wBAwXG"}
|
@@ -260,6 +260,10 @@ exports.default = (0, util_1.createRule)({
|
|
260
260
|
// so figure out if the variable is used in a place that accepts nullable types
|
261
261
|
const contextualType = (0, util_1.getContextualType)(checker, originalNode);
|
262
262
|
if (contextualType) {
|
263
|
+
if ((0, util_1.isTypeFlagSet)(type, ts.TypeFlags.Unknown) &&
|
264
|
+
!(0, util_1.isTypeFlagSet)(contextualType, ts.TypeFlags.Unknown)) {
|
265
|
+
return;
|
266
|
+
}
|
263
267
|
// in strict mode you can't assign null to undefined, so we have to make sure that
|
264
268
|
// the two types share a nullable type
|
265
269
|
const typeIncludesUndefined = (0, util_1.isTypeFlagSet)(type, ts.TypeFlags.Undefined);
|
@@ -185,7 +185,12 @@ function isTypeParameterRepeatedInAST(node, references, startOfBody = Infinity)
|
|
185
185
|
if (reference.identifier.parent.type === utils_1.AST_NODE_TYPES.TSTypeReference) {
|
186
186
|
const grandparent = skipConstituentsUpward(reference.identifier.parent.parent);
|
187
187
|
if (grandparent.type === utils_1.AST_NODE_TYPES.TSTypeParameterInstantiation &&
|
188
|
-
grandparent.params.includes(reference.identifier.parent)
|
188
|
+
grandparent.params.includes(reference.identifier.parent) &&
|
189
|
+
// Array and ReadonlyArray must be handled carefully
|
190
|
+
// let's defer the check to the type-aware phase
|
191
|
+
!(grandparent.parent.type === utils_1.AST_NODE_TYPES.TSTypeReference &&
|
192
|
+
grandparent.parent.typeName.type === utils_1.AST_NODE_TYPES.Identifier &&
|
193
|
+
['Array', 'ReadonlyArray'].includes(grandparent.parent.typeName.name))) {
|
189
194
|
return true;
|
190
195
|
}
|
191
196
|
}
|
@@ -215,14 +220,14 @@ function countTypeParameterUsage(checker, node) {
|
|
215
220
|
const counts = new Map();
|
216
221
|
if (ts.isClassLike(node)) {
|
217
222
|
for (const typeParameter of node.typeParameters) {
|
218
|
-
collectTypeParameterUsageCounts(checker, typeParameter, counts);
|
223
|
+
collectTypeParameterUsageCounts(checker, typeParameter, counts, true);
|
219
224
|
}
|
220
225
|
for (const member of node.members) {
|
221
|
-
collectTypeParameterUsageCounts(checker, member, counts);
|
226
|
+
collectTypeParameterUsageCounts(checker, member, counts, true);
|
222
227
|
}
|
223
228
|
}
|
224
229
|
else {
|
225
|
-
collectTypeParameterUsageCounts(checker, node, counts);
|
230
|
+
collectTypeParameterUsageCounts(checker, node, counts, false);
|
226
231
|
}
|
227
232
|
return counts;
|
228
233
|
}
|
@@ -231,7 +236,7 @@ function countTypeParameterUsage(checker, node) {
|
|
231
236
|
* appears in the given type by checking its uses through its type references.
|
232
237
|
* This is essentially a limited subset of the scope manager, but for types.
|
233
238
|
*/
|
234
|
-
function collectTypeParameterUsageCounts(checker, node, foundIdentifierUsages) {
|
239
|
+
function collectTypeParameterUsageCounts(checker, node, foundIdentifierUsages, fromClass) {
|
235
240
|
const visitedSymbolLists = new Set();
|
236
241
|
const type = checker.getTypeAtLocation(node);
|
237
242
|
const typeUsages = new Map();
|
@@ -246,7 +251,7 @@ function collectTypeParameterUsageCounts(checker, node, foundIdentifierUsages) {
|
|
246
251
|
if (!functionLikeType) {
|
247
252
|
visitType(type, false);
|
248
253
|
}
|
249
|
-
function visitType(type, assumeMultipleUses) {
|
254
|
+
function visitType(type, assumeMultipleUses, isReturnType = false) {
|
250
255
|
// Seeing the same type > (threshold=3 ** 2) times indicates a likely
|
251
256
|
// recursive type, like `type T = { [P in keyof T]: T }`.
|
252
257
|
// If it's not recursive, then heck, we've seen it enough times that any
|
@@ -288,9 +293,21 @@ function collectTypeParameterUsageCounts(checker, node, foundIdentifierUsages) {
|
|
288
293
|
}
|
289
294
|
// Tuple types like `[K, V]`
|
290
295
|
// Generic type references like `Map<K, V>`
|
291
|
-
else if (tsutils.
|
296
|
+
else if (tsutils.isTypeReference(type)) {
|
292
297
|
for (const typeArgument of type.typeArguments ?? []) {
|
293
|
-
|
298
|
+
// currently, if we are in a "class context", everything is accepted
|
299
|
+
let thisAssumeMultipleUses = fromClass || assumeMultipleUses;
|
300
|
+
// special cases - readonly arrays/tuples are considered only to use the
|
301
|
+
// type parameter once. Mutable arrays/tuples are considered to use the
|
302
|
+
// type parameter multiple times if and only if they are returned.
|
303
|
+
// other kind of type references always count as multiple uses
|
304
|
+
thisAssumeMultipleUses ||= tsutils.isTupleType(type.target)
|
305
|
+
? isReturnType && !type.target.readonly
|
306
|
+
: checker.isArrayType(type.target)
|
307
|
+
? isReturnType &&
|
308
|
+
type.symbol?.getName() === 'Array'
|
309
|
+
: true;
|
310
|
+
visitType(typeArgument, thisAssumeMultipleUses, isReturnType);
|
294
311
|
}
|
295
312
|
}
|
296
313
|
// Template literals like `a${T}b`
|
@@ -359,7 +376,7 @@ function collectTypeParameterUsageCounts(checker, node, foundIdentifierUsages) {
|
|
359
376
|
visitType(typeParameter, false);
|
360
377
|
}
|
361
378
|
visitType(checker.getTypePredicateOfSignature(signature)?.type ??
|
362
|
-
signature.getReturnType(), false);
|
379
|
+
signature.getReturnType(), false, true);
|
363
380
|
}
|
364
381
|
function visitSymbolsListOnce(symbols, assumeMultipleUses) {
|
365
382
|
if (visitedSymbolLists.has(symbols)) {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"no-unused-vars.d.ts","sourceRoot":"","sources":["../../src/rules/no-unused-vars.ts"],"names":[],"mappings":"AAUA,OAAO,EAAkB,QAAQ,EAAE,MAAM,0BAA0B,CAAC;
|
1
|
+
{"version":3,"file":"no-unused-vars.d.ts","sourceRoot":"","sources":["../../src/rules/no-unused-vars.ts"],"names":[],"mappings":"AAUA,OAAO,EAAkB,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAepE,MAAM,MAAM,UAAU,GAAG,WAAW,GAAG,gBAAgB,GAAG,gBAAgB,CAAC;AAC3E,MAAM,MAAM,OAAO,GAAG;IAClB,KAAK,GACL,OAAO,GACP;QACE,IAAI,CAAC,EAAE,YAAY,GAAG,KAAK,GAAG,MAAM,CAAC;QACrC,iBAAiB,CAAC,EAAE,MAAM,CAAC;QAC3B,YAAY,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC;QAC9B,yBAAyB,CAAC,EAAE,MAAM,CAAC;QACnC,8BAA8B,CAAC,EAAE,MAAM,CAAC;QACxC,8BAA8B,CAAC,EAAE,OAAO,CAAC;QACzC,kBAAkB,CAAC,EAAE,OAAO,CAAC;QAC7B,uBAAuB,CAAC,EAAE,OAAO,CAAC;QAClC,IAAI,CAAC,EAAE,KAAK,GAAG,OAAO,CAAC;QACvB,iBAAiB,CAAC,EAAE,MAAM,CAAC;KAC5B;CACJ,CAAC;;AA0BF,wBAuuBG"}
|
@@ -396,24 +396,40 @@ exports.default = (0, util_1.createRule)({
|
|
396
396
|
return unusedVariablesReturn;
|
397
397
|
}
|
398
398
|
return {
|
399
|
-
// declaration file handling
|
400
|
-
[ambientDeclarationSelector(utils_1.AST_NODE_TYPES.Program
|
399
|
+
// top-level declaration file handling
|
400
|
+
[ambientDeclarationSelector(utils_1.AST_NODE_TYPES.Program)](node) {
|
401
401
|
if (!(0, util_1.isDefinitionFile)(context.filename)) {
|
402
402
|
return;
|
403
403
|
}
|
404
|
+
const moduleDecl = (0, util_1.nullThrows)(node.parent, util_1.NullThrowsReasons.MissingParent);
|
405
|
+
if (checkForOverridingExportStatements(moduleDecl)) {
|
406
|
+
return;
|
407
|
+
}
|
404
408
|
markDeclarationChildAsUsed(node);
|
405
409
|
},
|
406
410
|
// children of a namespace that is a child of a declared namespace are auto-exported
|
407
|
-
[ambientDeclarationSelector('TSModuleDeclaration[declare = true] > TSModuleBlock TSModuleDeclaration > TSModuleBlock'
|
411
|
+
[ambientDeclarationSelector('TSModuleDeclaration[declare = true] > TSModuleBlock TSModuleDeclaration > TSModuleBlock')](node) {
|
412
|
+
const moduleDecl = (0, util_1.nullThrows)(node.parent.parent, util_1.NullThrowsReasons.MissingParent);
|
413
|
+
if (checkForOverridingExportStatements(moduleDecl)) {
|
414
|
+
return;
|
415
|
+
}
|
408
416
|
markDeclarationChildAsUsed(node);
|
409
417
|
},
|
410
418
|
// declared namespace handling
|
411
|
-
[ambientDeclarationSelector('TSModuleDeclaration[declare = true] > TSModuleBlock'
|
419
|
+
[ambientDeclarationSelector('TSModuleDeclaration[declare = true] > TSModuleBlock')](node) {
|
420
|
+
const moduleDecl = (0, util_1.nullThrows)(node.parent.parent, util_1.NullThrowsReasons.MissingParent);
|
421
|
+
if (checkForOverridingExportStatements(moduleDecl)) {
|
422
|
+
return;
|
423
|
+
}
|
424
|
+
markDeclarationChildAsUsed(node);
|
425
|
+
},
|
426
|
+
// namespace handling in definition files
|
427
|
+
[ambientDeclarationSelector('TSModuleDeclaration > TSModuleBlock')](node) {
|
428
|
+
if (!(0, util_1.isDefinitionFile)(context.filename)) {
|
429
|
+
return;
|
430
|
+
}
|
412
431
|
const moduleDecl = (0, util_1.nullThrows)(node.parent.parent, util_1.NullThrowsReasons.MissingParent);
|
413
|
-
|
414
|
-
// all other statements are not automatically exported in this case
|
415
|
-
if (moduleDecl.id.type === utils_1.AST_NODE_TYPES.Literal &&
|
416
|
-
checkModuleDeclForExportEquals(moduleDecl)) {
|
432
|
+
if (checkForOverridingExportStatements(moduleDecl)) {
|
417
433
|
return;
|
418
434
|
}
|
419
435
|
markDeclarationChildAsUsed(node);
|
@@ -467,23 +483,20 @@ exports.default = (0, util_1.createRule)({
|
|
467
483
|
}
|
468
484
|
},
|
469
485
|
};
|
470
|
-
function
|
486
|
+
function checkForOverridingExportStatements(node) {
|
471
487
|
const cached = MODULE_DECL_CACHE.get(node);
|
472
488
|
if (cached != null) {
|
473
489
|
return cached;
|
474
490
|
}
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
return true;
|
480
|
-
}
|
481
|
-
}
|
491
|
+
const body = getStatementsOfNode(node);
|
492
|
+
if (hasOverridingExportStatement(body)) {
|
493
|
+
MODULE_DECL_CACHE.set(node, true);
|
494
|
+
return true;
|
482
495
|
}
|
483
496
|
MODULE_DECL_CACHE.set(node, false);
|
484
497
|
return false;
|
485
498
|
}
|
486
|
-
function ambientDeclarationSelector(parent
|
499
|
+
function ambientDeclarationSelector(parent) {
|
487
500
|
return [
|
488
501
|
// Types are ambiently exported
|
489
502
|
`${parent} > :matches(${[
|
@@ -497,7 +510,7 @@ exports.default = (0, util_1.createRule)({
|
|
497
510
|
utils_1.AST_NODE_TYPES.TSEnumDeclaration,
|
498
511
|
utils_1.AST_NODE_TYPES.TSModuleDeclaration,
|
499
512
|
utils_1.AST_NODE_TYPES.VariableDeclaration,
|
500
|
-
].join(', ')})
|
513
|
+
].join(', ')})`,
|
501
514
|
].join(', ');
|
502
515
|
}
|
503
516
|
function markDeclarationChildAsUsed(node) {
|
@@ -546,6 +559,27 @@ exports.default = (0, util_1.createRule)({
|
|
546
559
|
}
|
547
560
|
},
|
548
561
|
});
|
562
|
+
function hasOverridingExportStatement(body) {
|
563
|
+
for (const statement of body) {
|
564
|
+
if ((statement.type === utils_1.AST_NODE_TYPES.ExportNamedDeclaration &&
|
565
|
+
statement.declaration == null) ||
|
566
|
+
statement.type === utils_1.AST_NODE_TYPES.ExportAllDeclaration ||
|
567
|
+
statement.type === utils_1.AST_NODE_TYPES.TSExportAssignment) {
|
568
|
+
return true;
|
569
|
+
}
|
570
|
+
if (statement.type === utils_1.AST_NODE_TYPES.ExportDefaultDeclaration &&
|
571
|
+
statement.declaration.type === utils_1.AST_NODE_TYPES.Identifier) {
|
572
|
+
return true;
|
573
|
+
}
|
574
|
+
}
|
575
|
+
return false;
|
576
|
+
}
|
577
|
+
function getStatementsOfNode(block) {
|
578
|
+
if (block.type === utils_1.AST_NODE_TYPES.Program) {
|
579
|
+
return block.body;
|
580
|
+
}
|
581
|
+
return block.body.body;
|
582
|
+
}
|
549
583
|
/*
|
550
584
|
|
551
585
|
###### TODO ######
|
@@ -2,6 +2,7 @@ export type MessageIds = 'omittingRestParameter' | 'omittingSingleParameter' | '
|
|
2
2
|
export type Options = [
|
3
3
|
{
|
4
4
|
ignoreDifferentlyNamedParameters?: boolean;
|
5
|
+
ignoreOverloadsWithDifferentJSDoc?: boolean;
|
5
6
|
}
|
6
7
|
];
|
7
8
|
declare const _default: import("@typescript-eslint/utils/ts-eslint").RuleModule<MessageIds, Options, import("../../rules").ESLintPluginDocs, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"unified-signatures.d.ts","sourceRoot":"","sources":["../../src/rules/unified-signatures.ts"],"names":[],"mappings":"AAuDA,MAAM,MAAM,UAAU,GAClB,uBAAuB,GACvB,yBAAyB,GACzB,2BAA2B,CAAC;AAEhC,MAAM,MAAM,OAAO,GAAG;IACpB;QACE,gCAAgC,CAAC,EAAE,OAAO,CAAC;
|
1
|
+
{"version":3,"file":"unified-signatures.d.ts","sourceRoot":"","sources":["../../src/rules/unified-signatures.ts"],"names":[],"mappings":"AAuDA,MAAM,MAAM,UAAU,GAClB,uBAAuB,GACvB,yBAAyB,GACzB,2BAA2B,CAAC;AAEhC,MAAM,MAAM,OAAO,GAAG;IACpB;QACE,gCAAgC,CAAC,EAAE,OAAO,CAAC;QAC3C,iCAAiC,CAAC,EAAE,OAAO,CAAC;KAC7C;CACF,CAAC;;AAEF,wBAyiBG"}
|
@@ -25,6 +25,10 @@ exports.default = (0, util_1.createRule)({
|
|
25
25
|
type: 'boolean',
|
26
26
|
description: 'Whether two parameters with different names at the same index should be considered different even if their types are the same.',
|
27
27
|
},
|
28
|
+
ignoreOverloadsWithDifferentJSDoc: {
|
29
|
+
type: 'boolean',
|
30
|
+
description: 'Whether two overloads with different JSDoc comments should be considered different even if their parameter and return types are the same.',
|
31
|
+
},
|
28
32
|
},
|
29
33
|
},
|
30
34
|
],
|
@@ -32,9 +36,10 @@ exports.default = (0, util_1.createRule)({
|
|
32
36
|
defaultOptions: [
|
33
37
|
{
|
34
38
|
ignoreDifferentlyNamedParameters: false,
|
39
|
+
ignoreOverloadsWithDifferentJSDoc: false,
|
35
40
|
},
|
36
41
|
],
|
37
|
-
create(context, [{ ignoreDifferentlyNamedParameters }]) {
|
42
|
+
create(context, [{ ignoreDifferentlyNamedParameters, ignoreOverloadsWithDifferentJSDoc }]) {
|
38
43
|
//----------------------------------------------------------------------
|
39
44
|
// Helpers
|
40
45
|
//----------------------------------------------------------------------
|
@@ -126,6 +131,13 @@ exports.default = (0, util_1.createRule)({
|
|
126
131
|
}
|
127
132
|
}
|
128
133
|
}
|
134
|
+
if (ignoreOverloadsWithDifferentJSDoc) {
|
135
|
+
const aComment = getBlockCommentForNode(getExportingNode(a) ?? a);
|
136
|
+
const bComment = getBlockCommentForNode(getExportingNode(b) ?? b);
|
137
|
+
if (aComment?.value !== bComment?.value) {
|
138
|
+
return false;
|
139
|
+
}
|
140
|
+
}
|
129
141
|
return (typesAreEqual(a.returnType, b.returnType) &&
|
130
142
|
// Must take the same type parameters.
|
131
143
|
// If one uses a type parameter (from outside) and the other doesn't, they shouldn't be joined.
|
@@ -306,6 +318,15 @@ exports.default = (0, util_1.createRule)({
|
|
306
318
|
addFailures(failures);
|
307
319
|
currentScope = scopes.pop();
|
308
320
|
}
|
321
|
+
/**
|
322
|
+
* @returns the first valid JSDoc comment annotating `node`
|
323
|
+
*/
|
324
|
+
function getBlockCommentForNode(node) {
|
325
|
+
return context.sourceCode
|
326
|
+
.getCommentsBefore(node)
|
327
|
+
.reverse()
|
328
|
+
.find(comment => comment.type === utils_1.AST_TOKEN_TYPES.Block);
|
329
|
+
}
|
309
330
|
function addOverload(signature, key, containingNode) {
|
310
331
|
key ??= getOverloadKey(signature);
|
311
332
|
if (currentScope &&
|
@@ -383,7 +404,13 @@ function getOverloadInfo(node) {
|
|
383
404
|
return '()';
|
384
405
|
default: {
|
385
406
|
const { key } = node;
|
386
|
-
|
407
|
+
if (isPrivateIdentifier(key)) {
|
408
|
+
return `private_identifier_${key.name}`;
|
409
|
+
}
|
410
|
+
if (isIdentifier(key)) {
|
411
|
+
return `identifier_${key.name}`;
|
412
|
+
}
|
413
|
+
return key.raw;
|
387
414
|
}
|
388
415
|
}
|
389
416
|
}
|
@@ -400,6 +427,9 @@ function getStaticParameterName(param) {
|
|
400
427
|
function isIdentifier(node) {
|
401
428
|
return node.type === utils_1.AST_NODE_TYPES.Identifier;
|
402
429
|
}
|
430
|
+
function isPrivateIdentifier(node) {
|
431
|
+
return node.type === utils_1.AST_NODE_TYPES.PrivateIdentifier;
|
432
|
+
}
|
403
433
|
function isGetterOrSetter(node) {
|
404
434
|
return node.kind === 'get' || node.kind === 'set';
|
405
435
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"getESLintCoreRule.d.ts","sourceRoot":"","sources":["../../src/util/getESLintCoreRule.ts"],"names":[],"mappings":"AAGA,UAAU,OAAO;IAEf,cAAc,EAAE,cAAc,+BAA+B,CAAC,CAAC;IAC/D,mBAAmB,EAAE,cAAc,oCAAoC,CAAC,CAAC;IACzE,cAAc,EAAE,cAAc,+BAA+B,CAAC,CAAC;IAC/D,mBAAmB,EAAE,cAAc,oCAAoC,CAAC,CAAC;IACzE,YAAY,EAAE,cAAc,6BAA6B,CAAC,CAAC;IAC3D,cAAc,EAAE,cAAc,+BAA+B,CAAC,CAAC;IAC/D,uBAAuB,EAAE,cAAc,wCAAwC,CAAC,CAAC;IACjF,mBAAmB,EAAE,cAAc,oCAAoC,CAAC,CAAC;IACzE,qBAAqB,EAAE,cAAc,sCAAsC,CAAC,CAAC;IAC7E,iBAAiB,EAAE,cAAc,kCAAkC,CAAC,CAAC;IACrE,cAAc,EAAE,cAAc,+BAA+B,CAAC,CAAC;IAC/D,sBAAsB,EAAE,cAAc,uCAAuC,CAAC,CAAC;IAC/E,kBAAkB,EAAE,cAAc,mCAAmC,CAAC,CAAC;IACvE,uBAAu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AuB,EAAE,cAAc,wCAAwC,CAAC,CAAC;IACjF,UAAU,EAAE,cAAc,2BAA2B,CAAC,CAAC;IACvD,uBAAuB,EAAE,cAAc,wCAAwC,CAAC,CAAC;IACjF,wBAAwB,EAAE,cAAc,yCAAyC,CAAC,CAAC;IACnF,cAAc,EAAE,cAAc,+BAA+B,CAAC,CAAC;IAC/D,sBAAsB,EAAE,cAAc,uCAAuC,CAAC,CAAC;IAC/E,MAAM,EAAE,cAAc,yBAAyB,CAAC,CAAC;CAElD;AAED,KAAK,MAAM,GAAG,MAAM,OAAO,CAAC;AAE5B,eAAO,MAAM,iBAAiB,GAAI,CAAC,SAAS,MAAM,EAAE,QAAQ,CAAC,KAAG,OAAO,CAAC,CAAC,CAItE,CAAC;AAEJ,wBAAgB,sBAAsB,CAAC,CAAC,SAAS,MAAM,EACrD,MAAM,EAAE,CAAC,GACR,OAAO,CAAC,CAAC,CAAC,GAAG,IAAI,CAMnB"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"getValueOfLiteralType.d.ts","sourceRoot":"","sources":["../../src/util/getValueOfLiteralType.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,EAAE,MAAM,YAAY,CAAC;AAYtC,eAAO,MAAM,qBAAqB,
|
1
|
+
{"version":3,"file":"getValueOfLiteralType.d.ts","sourceRoot":"","sources":["../../src/util/getValueOfLiteralType.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,EAAE,MAAM,YAAY,CAAC;AAYtC,eAAO,MAAM,qBAAqB,GAChC,MAAM,EAAE,CAAC,WAAW,KACnB,MAAM,GAAG,MAAM,GAAG,MAKpB,CAAC"}
|
package/dist/util/misc.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"misc.d.ts","sourceRoot":"","sources":["../../src/util/misc.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAA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QAAQ,CAAC,gBAAgB,GACzB,QAAQ,CAAC,gBAAgB,GACzB,QAAQ,CAAC,gBAAgB,GACzB,QAAQ,CAAC,QAAQ,GACjB,QAAQ,CAAC,kBAAkB,GAC3B,QAAQ,CAAC,0BAA0B,GACnC,QAAQ,CAAC,4BAA4B,CAAC;AAE1C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AACH,wBAAgB,0BAA0B,CACxC,IAAI,EAAE,WAAW,EACjB,EAAE,UAAU,EAAE,EAAE,WAAW,CAAC,MAAM,EAAE,OAAO,EAAE,CAAC,GAC7C,MAAM,GAAG,MAAM,GAAG,SAAS,CAiB7B;AAED;;;;GAIG;AACH,eAAO,MAAM,2BAA2B,GACtC,kBAAkB,WAAW,EAC7B,SAAS,WAAW,CAAC,MAAM,EAAE,OAAO,EAAE,CAAC,EACvC,GAAG,QAAQ,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,KAC7B,OAGA,CAAC"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"truthinessAndNullishUtils.d.ts","sourceRoot":"","sources":["../../src/util/truthinessAndNullishUtils.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,YAAY,CAAC;AASjC,eAAO,MAAM,eAAe,
|
1
|
+
{"version":3,"file":"truthinessAndNullishUtils.d.ts","sourceRoot":"","sources":["../../src/util/truthinessAndNullishUtils.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,YAAY,CAAC;AASjC,eAAO,MAAM,eAAe,GAAI,MAAM,EAAE,CAAC,IAAI,KAAG,OAS0B,CAAC;AAE3E,eAAO,MAAM,gBAAgB,GAAI,MAAM,EAAE,CAAC,IAAI,KAAG,OAQ5C,CAAC;AAON,eAAO,MAAM,iBAAiB,GAAI,MAAM,EAAE,CAAC,IAAI,KAAG,OACA,CAAC;AAEnD,eAAO,MAAM,eAAe,GAAI,MAAM,EAAE,CAAC,IAAI,KAAG,OACG,CAAC"}
|
@@ -12,7 +12,7 @@ import TabItem from '@theme/TabItem';
|
|
12
12
|
It adds support for functions that return `void` or `Promise<void>`.
|
13
13
|
|
14
14
|
:::danger warning
|
15
|
-
If possible, it is recommended to use tsconfig's `noImplicitReturns` option rather than this rule. `noImplicitReturns` is powered by TS's type information and control-flow analysis so it has better coverage than this rule.
|
15
|
+
If possible, it is recommended to use tsconfig's [`noImplicitReturns`](https://www.typescriptlang.org/tsconfig/#noImplicitReturns) option rather than this rule. `noImplicitReturns` is powered by TS's type information and control-flow analysis so it has better coverage than this rule.
|
16
16
|
:::
|
17
17
|
|
18
18
|
<Tabs>
|
@@ -260,6 +260,20 @@ export const foo: FooType = bar => {};
|
|
260
260
|
</TabItem>
|
261
261
|
</Tabs>
|
262
262
|
|
263
|
+
### `allowOverloadFunctions`
|
264
|
+
|
265
|
+
{/* insert option description */}
|
266
|
+
|
267
|
+
Examples of correct code when `allowOverloadFunctions` is set to `true`:
|
268
|
+
|
269
|
+
```ts option='{ "allowOverloadFunctions": true }' showPlaygroundButton
|
270
|
+
export function test(a: string): string;
|
271
|
+
export function test(a: number): number;
|
272
|
+
export function test(a: unknown) {
|
273
|
+
return a;
|
274
|
+
}
|
275
|
+
```
|
276
|
+
|
263
277
|
## When Not To Use It
|
264
278
|
|
265
279
|
If your project is not used by downstream consumers that are sensitive to API types, you can disable this rule.
|
@@ -82,10 +82,30 @@ For example, the following `T` is used multiple times by virtue of being in an `
|
|
82
82
|
declare function createStateHistory<T>(): T[];
|
83
83
|
```
|
84
84
|
|
85
|
-
This is because the type parameter `T` relates multiple methods in
|
85
|
+
This is because the type parameter `T` relates multiple methods in `T[]` (`Array<T>`) together, making it used more than once.
|
86
86
|
|
87
87
|
Therefore, this rule won't report on type parameters used as a type argument.
|
88
|
-
|
88
|
+
This includes type arguments provided to global types such as `Array`, `Map`, and `Set` that have multiple methods and properties that can change values based on the type parameter.
|
89
|
+
|
90
|
+
On the other hand, readonly and fixed array-likes such as `readonly T[]`, `ReadonlyArray`, and tuples such as `[T]` are special cases that are specifically reported on when used as input types, or as `readonly` output types.
|
91
|
+
The following example will be reported because `T` is used only once as type argument for the `ReadonlyArray` global type:
|
92
|
+
|
93
|
+
<Tabs>
|
94
|
+
<TabItem value="❌ Incorrect">
|
95
|
+
|
96
|
+
```ts
|
97
|
+
declare function length<T>(array: ReadonlyArray<T>): number;
|
98
|
+
```
|
99
|
+
|
100
|
+
</TabItem>
|
101
|
+
<TabItem value="✅ Correct">
|
102
|
+
|
103
|
+
```ts
|
104
|
+
declare function length(array: ReadonlyArray<unknown>): number;
|
105
|
+
```
|
106
|
+
|
107
|
+
</TabItem>
|
108
|
+
</Tabs>
|
89
109
|
|
90
110
|
## FAQ
|
91
111
|
|
@@ -78,6 +78,50 @@ function f(b: string): void;
|
|
78
78
|
</TabItem>
|
79
79
|
</Tabs>
|
80
80
|
|
81
|
+
### `ignoreOverloadsWithDifferentJSDoc`
|
82
|
+
|
83
|
+
{/* insert option description */}
|
84
|
+
|
85
|
+
Examples of code for this rule with `ignoreOverloadsWithDifferentJSDoc`:
|
86
|
+
|
87
|
+
<Tabs>
|
88
|
+
<TabItem value="❌ Incorrect">
|
89
|
+
|
90
|
+
```ts option='{ "ignoreOverloadsWithDifferentJSDoc": true }'
|
91
|
+
declare function f(x: string): void;
|
92
|
+
declare function f(x: boolean): void;
|
93
|
+
/**
|
94
|
+
* @deprecate
|
95
|
+
*/
|
96
|
+
declare function f(x: number): void;
|
97
|
+
/**
|
98
|
+
* @deprecate
|
99
|
+
*/
|
100
|
+
declare function f(x: null): void;
|
101
|
+
```
|
102
|
+
|
103
|
+
</TabItem>
|
104
|
+
<TabItem value="✅ Correct">
|
105
|
+
|
106
|
+
```ts option='{ "ignoreOverloadsWithDifferentJSDoc": true }'
|
107
|
+
declare function f(x: string): void;
|
108
|
+
/**
|
109
|
+
* This signature does something else.
|
110
|
+
*/
|
111
|
+
declare function f(x: boolean): void;
|
112
|
+
/**
|
113
|
+
* @async
|
114
|
+
*/
|
115
|
+
declare function f(x: number): void;
|
116
|
+
/**
|
117
|
+
* @deprecate
|
118
|
+
*/
|
119
|
+
declare function f(x: null): void;
|
120
|
+
```
|
121
|
+
|
122
|
+
</TabItem>
|
123
|
+
</Tabs>
|
124
|
+
|
81
125
|
## When Not To Use It
|
82
126
|
|
83
127
|
This is purely a stylistic rule to help with readability of function signature overloads.
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@typescript-eslint/eslint-plugin",
|
3
|
-
"version": "8.
|
3
|
+
"version": "8.26.0",
|
4
4
|
"description": "TypeScript plugin for ESLint",
|
5
5
|
"files": [
|
6
6
|
"dist",
|
@@ -62,10 +62,10 @@
|
|
62
62
|
},
|
63
63
|
"dependencies": {
|
64
64
|
"@eslint-community/regexpp": "^4.10.0",
|
65
|
-
"@typescript-eslint/scope-manager": "8.
|
66
|
-
"@typescript-eslint/type-utils": "8.
|
67
|
-
"@typescript-eslint/utils": "8.
|
68
|
-
"@typescript-eslint/visitor-keys": "8.
|
65
|
+
"@typescript-eslint/scope-manager": "8.26.0",
|
66
|
+
"@typescript-eslint/type-utils": "8.26.0",
|
67
|
+
"@typescript-eslint/utils": "8.26.0",
|
68
|
+
"@typescript-eslint/visitor-keys": "8.26.0",
|
69
69
|
"graphemer": "^1.4.0",
|
70
70
|
"ignore": "^5.3.1",
|
71
71
|
"natural-compare": "^1.4.0",
|
@@ -76,8 +76,8 @@
|
|
76
76
|
"@types/marked": "^5.0.2",
|
77
77
|
"@types/mdast": "^4.0.3",
|
78
78
|
"@types/natural-compare": "*",
|
79
|
-
"@typescript-eslint/rule-schema-to-typescript-types": "8.
|
80
|
-
"@typescript-eslint/rule-tester": "8.
|
79
|
+
"@typescript-eslint/rule-schema-to-typescript-types": "8.26.0",
|
80
|
+
"@typescript-eslint/rule-tester": "8.26.0",
|
81
81
|
"ajv": "^6.12.6",
|
82
82
|
"cross-env": "^7.0.3",
|
83
83
|
"cross-fetch": "*",
|
@@ -100,7 +100,7 @@
|
|
100
100
|
"peerDependencies": {
|
101
101
|
"@typescript-eslint/parser": "^8.0.0 || ^8.0.0-alpha.0",
|
102
102
|
"eslint": "^8.57.0 || ^9.0.0",
|
103
|
-
"typescript": ">=4.8.4 <5.
|
103
|
+
"typescript": ">=4.8.4 <5.9.0"
|
104
104
|
},
|
105
105
|
"funding": {
|
106
106
|
"type": "opencollective",
|