Skip to content

Commit

Permalink
refactor: Replace string comparison with pattern matching
Browse files Browse the repository at this point in the history
  • Loading branch information
d3xter666 committed Nov 14, 2024
1 parent 10cd6cc commit 5d53ccc
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/linter/linter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down

0 comments on commit 5d53ccc

Please sign in to comment.