Skip to content

Commit

Permalink
Minor fixes in git ignores parser
Browse files Browse the repository at this point in the history
  • Loading branch information
webpro committed Mar 25, 2024
1 parent 4c3160b commit ec11f37
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/knip/src/util/globby.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function convertGitignoreToMicromatch(pattern: string) {
if (pattern.startsWith('*/**/')) pattern = pattern.slice(5);

if (pattern.startsWith('/')) pattern = pattern.slice(1);
else pattern = '**/' + pattern;
else if (!pattern.startsWith('**/')) pattern = '**/' + pattern;

if (pattern.endsWith('/*')) extPattern = pattern;
else if (pattern.endsWith('/')) extPattern = pattern + '**';
Expand All @@ -53,7 +53,7 @@ function parseGitignoreFile(filePath: string) {
return file
.split(/\r?\n/)
.filter(line => line && !line.startsWith('#'))
.map(pattern => convertGitignoreToMicromatch(pattern));
.map(pattern => convertGitignoreToMicromatch(pattern.replace(/#.*/, '').trim()));
}

async function parseFindGitignores(options: Options): Promise<Gitignores> {
Expand Down

0 comments on commit ec11f37

Please sign in to comment.