From 8681776a1b681c4f6a2df758a1b3c24f53649255 Mon Sep 17 00:00:00 2001 From: Prakash-Verma Date: Wed, 21 Apr 2021 18:20:25 +0530 Subject: [PATCH] Improved the filename search regex --- builder/strictify/helper.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/builder/strictify/helper.ts b/builder/strictify/helper.ts index 28f5cb36..d188880c 100644 --- a/builder/strictify/helper.ts +++ b/builder/strictify/helper.ts @@ -50,7 +50,7 @@ export function getAllErrors(errMessage: string, projectRoot: string) { function findAllIndices(errMessage: string, projectRoot: string) { const stopIndex = errMessage.length - 1; - const regexStr = projectRoot ? `${projectRoot}/src` : 'src'; + const regexStr = getErrorMatchingRegex(projectRoot); const regex = new RegExp(regexStr, 'g'); const it = errMessage.matchAll(regex); @@ -66,8 +66,16 @@ function findAllIndices(errMessage: string, projectRoot: string) { return allIndices; } +function getErrorMatchingRegex(projectRoot: string) { + if (projectRoot) { + projectRoot = projectRoot.replace(/\/$/, ''); + return `${projectRoot}/src`; + } + return 'src'; +} + export function getListOfFilesWithError(errorMessage: string) { - const allErrors = errorMessage.match(/src.*\.(ts|html)/g); + const allErrors = errorMessage.match(/src\/.*\.(ts|html)/g); if (allErrors) { allErrors.sort(); }