From 5d53cccad1e588e20a8eb67cb2ee6f77ba95556a Mon Sep 17 00:00:00 2001 From: Yavor Ivanov Date: Thu, 14 Nov 2024 16:07:28 +0100 Subject: [PATCH] refactor: Replace string comparison with pattern matching --- src/linter/linter.ts | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/linter/linter.ts b/src/linter/linter.ts index 88db2c93e..4b0cb5b94 100644 --- a/src/linter/linter.ts +++ b/src/linter/linter.ts @@ -378,16 +378,22 @@ async function checkUnmatchedPatterns(patterns: FilePattern[], patternsMatch: Se const rootFileReader = createReader({ fsBasePath: options.rootDir, virBasePath: "/", - excludes: [""] + excludes: [ + "/node_modules/**/*", + "/.*", + "/.*/**/*", + ], }); - // TODO: Define a better way to get all files. Exclude node_modules, .git, etc. - const allFiles = await rootFileReader.byGlob("/**/*"); - const filePaths = allFiles.map((file) => file.getPath()); - for (const pattern of unmatchedPatterns) { - if (filePaths.some((filePath) => filePath.includes(pattern))) { - notProcessedFiles.add(pattern); - unmatchedPatterns.splice(unmatchedPatterns.indexOf(pattern), 1); + const allFiles = await rootFileReader.byGlob("/**/*"); + const filePaths = allFiles.map((file) => file.getPath().substring(1)); + const patterns = buildPatterns(unmatchedPatterns); + + for (const pattern of patterns) { + const matchedFilePaths = filePaths.filter((filePath) => pattern.match(filePath)); + if (matchedFilePaths.length) { + matchedFilePaths.forEach((filePath) => notProcessedFiles.add(filePath)); + unmatchedPatterns.splice(unmatchedPatterns.indexOf(pattern.pattern), 1); } }