diff --git a/packages/eslint-plugin/src/rules/unified-signatures.ts b/packages/eslint-plugin/src/rules/unified-signatures.ts index 809b19dd1aa6..47e148197f1b 100644 --- a/packages/eslint-plugin/src/rules/unified-signatures.ts +++ b/packages/eslint-plugin/src/rules/unified-signatures.ts @@ -241,9 +241,8 @@ export default createRule({ } if (ignoreOverloadsWithDifferentJSDoc) { - const aComment = getBlockCommentForNode(getExportingNode(a) ?? a); - const bComment = getBlockCommentForNode(getExportingNode(b) ?? b); - + const aComment = getBlockCommentForNode(getCommentTargetNode(a)); + const bComment = getBlockCommentForNode(getCommentTargetNode(b)); if (aComment?.value !== bComment?.value) { return false; } @@ -657,6 +656,14 @@ export default createRule({ }, }); +function getCommentTargetNode(node: SignatureDefinition) { + if (node.type === AST_NODE_TYPES.TSEmptyBodyFunctionExpression) { + return node.parent; + } + + return getExportingNode(node) ?? node; +} + function getExportingNode( node: SignatureDefinition, ): diff --git a/packages/eslint-plugin/tests/rules/unified-signatures.test.ts b/packages/eslint-plugin/tests/rules/unified-signatures.test.ts index 30952ddebb0f..871507e24ad2 100644 --- a/packages/eslint-plugin/tests/rules/unified-signatures.test.ts +++ b/packages/eslint-plugin/tests/rules/unified-signatures.test.ts @@ -378,6 +378,19 @@ declare function f(x: boolean): unknown; declare function f(x: number): unknown; declare function f(x: boolean): unknown; `, + + options: [{ ignoreOverloadsWithDifferentJSDoc: true }], + }, + { + code: ` +class C { + a(b: string): void; + /** + * @deprecate + */ + a(b: number): void; +} + `, options: [{ ignoreOverloadsWithDifferentJSDoc: true }], }, ` @@ -833,6 +846,30 @@ abstract class Foo { }, ], }, + { + code: ` +abstract class C { + a(b: string): void; + /** + * @deprecate + */ + a(b: number): void; +} + `, + errors: [ + { + column: 5, + data: { + failureStringStart: + 'These overloads can be combined into one signature', + type1: 'string', + type2: 'number', + }, + line: 7, + messageId: 'singleParameterDifference', + }, + ], + }, { // Works with literals code: ` pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy