Skip to content

Commit e1b310c

Browse files
authored
fix(eslint-plugin): [unified-signatures] fix false positives for ignoreOverloadsWithDifferentJSDoc option (#11381)
* fix: improve comment comparison logic for overload unification * test: add cases for overloads with different comments and class methods
1 parent bef907b commit e1b310c

File tree

2 files changed

+47
-3
lines changed

2 files changed

+47
-3
lines changed

packages/eslint-plugin/src/rules/unified-signatures.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -241,9 +241,8 @@ export default createRule<Options, MessageIds>({
241241
}
242242

243243
if (ignoreOverloadsWithDifferentJSDoc) {
244-
const aComment = getBlockCommentForNode(getExportingNode(a) ?? a);
245-
const bComment = getBlockCommentForNode(getExportingNode(b) ?? b);
246-
244+
const aComment = getBlockCommentForNode(getCommentTargetNode(a));
245+
const bComment = getBlockCommentForNode(getCommentTargetNode(b));
247246
if (aComment?.value !== bComment?.value) {
248247
return false;
249248
}
@@ -657,6 +656,14 @@ export default createRule<Options, MessageIds>({
657656
},
658657
});
659658

659+
function getCommentTargetNode(node: SignatureDefinition) {
660+
if (node.type === AST_NODE_TYPES.TSEmptyBodyFunctionExpression) {
661+
return node.parent;
662+
}
663+
664+
return getExportingNode(node) ?? node;
665+
}
666+
660667
function getExportingNode(
661668
node: SignatureDefinition,
662669
):

packages/eslint-plugin/tests/rules/unified-signatures.test.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,19 @@ declare function f(x: boolean): unknown;
378378
declare function f(x: number): unknown;
379379
declare function f(x: boolean): unknown;
380380
`,
381+
382+
options: [{ ignoreOverloadsWithDifferentJSDoc: true }],
383+
},
384+
{
385+
code: `
386+
class C {
387+
a(b: string): void;
388+
/**
389+
* @deprecate
390+
*/
391+
a(b: number): void;
392+
}
393+
`,
381394
options: [{ ignoreOverloadsWithDifferentJSDoc: true }],
382395
},
383396
`
@@ -833,6 +846,30 @@ abstract class Foo {
833846
},
834847
],
835848
},
849+
{
850+
code: `
851+
abstract class C {
852+
a(b: string): void;
853+
/**
854+
* @deprecate
855+
*/
856+
a(b: number): void;
857+
}
858+
`,
859+
errors: [
860+
{
861+
column: 5,
862+
data: {
863+
failureStringStart:
864+
'These overloads can be combined into one signature',
865+
type1: 'string',
866+
type2: 'number',
867+
},
868+
line: 7,
869+
messageId: 'singleParameterDifference',
870+
},
871+
],
872+
},
836873
{
837874
// Works with literals
838875
code: `

0 commit comments

Comments
 (0)