From b11fc72f8858f824d7c6d7df373348142a5c0796 Mon Sep 17 00:00:00 2001 From: Merlin Beutlberger Date: Wed, 4 Sep 2024 17:32:27 +0200 Subject: [PATCH] feat: Detect deprecated function overloads --- src/linter/ui5Types/SourceFileLinter.ts | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/linter/ui5Types/SourceFileLinter.ts b/src/linter/ui5Types/SourceFileLinter.ts index ca5675965..f9762ce41 100644 --- a/src/linter/ui5Types/SourceFileLinter.ts +++ b/src/linter/ui5Types/SourceFileLinter.ts @@ -240,9 +240,9 @@ export default class SourceFileLinter { return deprecatedTag.text?.reduce((acc, text) => acc + text.text, "").split("\n\n")[0] ?? ""; } - getDeprecationInfo(symbol: ts.Symbol | undefined): DeprecationInfo | null { + getDeprecationInfo(symbol: ts.Symbol | undefined, signature?: ts.Signature): DeprecationInfo | null { if (symbol && this.isSymbolOfUi5Type(symbol)) { - const jsdocTags = symbol.getJsDocTags(this.#checker); + const jsdocTags = (signature ?? symbol).getJsDocTags(this.#checker); const deprecatedTag = jsdocTags.find((tag) => tag.name === "deprecated"); if (deprecatedTag) { const deprecationInfo: DeprecationInfo = { @@ -286,7 +286,9 @@ export default class SourceFileLinter { throw new Error(`Unhandled CallExpression expression syntax: ${ts.SyntaxKind[exprNode.kind]}`); } - const deprecationInfo = this.getDeprecationInfo(exprType.symbol); + const signature = this.#checker.getResolvedSignature(node); + const deprecationInfo = this.getDeprecationInfo(exprType.symbol, signature); + if (!deprecationInfo) { return; } @@ -454,6 +456,20 @@ export default class SourceFileLinter { return; // Already analyzed in context of call expression } + const nodeType = this.#checker.getTypeAtLocation(node); + const signatures = nodeType.getCallSignatures(); + if (signatures) { + const allSignaturesDeprecated = signatures.every((signature) => { + signature.getJsDocTags().some((tag) => { + return tag.name === "deprecated"; + }); + }); + + if (!allSignaturesDeprecated) { + return; + } + } + const deprecationInfo = this.getDeprecationInfoForAccess(node); if (deprecationInfo) { if (this.isSymbolOfJquerySapType(deprecationInfo.symbol)) {