From 746ee888cdb8af326f4eefabfbb0419f1440df36 Mon Sep 17 00:00:00 2001 From: Tianning Li Date: Mon, 12 Feb 2024 16:14:37 -0800 Subject: [PATCH] feat: update function name --- lib/plugin/utils/ast-utils.ts | 11 ++++++----- lib/plugin/visitors/controller-class.visitor.ts | 4 ++-- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/plugin/utils/ast-utils.ts b/lib/plugin/utils/ast-utils.ts index 9387df043..e0e6a64a8 100644 --- a/lib/plugin/utils/ast-utils.ts +++ b/lib/plugin/utils/ast-utils.ts @@ -228,7 +228,7 @@ export function getTsDocTagsOfNode(node: Node, typeChecker: TypeChecker) { return tagResults; } -export function getTsDocReturnsOrErrorOfNode(node: Node) { +export function getTsDocErrorsOfNode(node: Node) { const tsdocParser: TSDocParser = new TSDocParser(); const parserContext: ParserContext = tsdocParser.parseString( node.getFullText() @@ -236,16 +236,17 @@ export function getTsDocReturnsOrErrorOfNode(node: Node) { const docComment: DocComment = parserContext.docComment; const tagResults = []; + const errorParsingRegex = /{(\d+)} (.*)/; + const introspectTsDocTags = (docComment: DocComment) => { - const blocks = docComment.customBlocks.filter((block) => - ['@throws', '@returns'].includes(block.blockTag.tagName) + const blocks = docComment.customBlocks.filter( + (block) => block.blockTag.tagName === '@throws' ); blocks.forEach((block) => { try { const docValue = renderDocNode(block.content).split('\n')[0].trim(); - const regex = /{(\d+)} (.*)/; - const match = docValue.match(regex); + const match = docValue.match(errorParsingRegex); tagResults.push({ status: match[1], description: `"${match[2]}"` diff --git a/lib/plugin/visitors/controller-class.visitor.ts b/lib/plugin/visitors/controller-class.visitor.ts index 794707e7b..75b9742d2 100644 --- a/lib/plugin/visitors/controller-class.visitor.ts +++ b/lib/plugin/visitors/controller-class.visitor.ts @@ -9,7 +9,7 @@ import { getDecoratorArguments, getDecoratorName, getMainCommentOfNode, - getTsDocReturnsOrErrorOfNode, + getTsDocErrorsOfNode, getTsDocTagsOfNode } from '../utils/ast-utils'; import { @@ -353,7 +353,7 @@ export class ControllerClassVisitor extends AbstractFileVisitor { } } - const tags = getTsDocReturnsOrErrorOfNode(node); + const tags = getTsDocErrorsOfNode(node); if (!tags.length) { return []; }