Skip to content

Commit

Permalink
Make gitignore code clearer
Browse files Browse the repository at this point in the history
  • Loading branch information
Nixinova committed Mar 8, 2024
1 parent 117af9e commit bbf8ad2
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,17 +89,17 @@ async function analyse(rawPaths?: string | string[], opts: T.Options = {}): Prom
if (!useRawContent && opts.checkIgnored) {
const nestedIgnoreFiles = files.filter(file => file.endsWith('.gitignore'));
for (const ignoresFile of nestedIgnoreFiles) {
const relFile = relPath(ignoresFile);
const relFolder = paths.dirname(relFile);
const relIgnoresFile = relPath(ignoresFile);
const relIgnoresFolder = paths.dirname(relIgnoresFile);
// Parse gitignores
const ignoresDataRaw = await readFile(ignoresFile);
const ignoresData = ignoresDataRaw.replace(/#.+|\s+$/gm, '');
const localIgnoresData = ignoresData
// '.file' -> '/root/*/.file'
.replace(/^(?=[^\s\/\\])/gm, localRoot(relFolder) + '/*/')
// '/folder' -> '/root/folder'
.replace(/^[\/\\]/gm, localRoot(relFolder) + '/')
ignored.add(localIgnoresData);
const absoluteIgnoresData = ignoresData
// '.file' -> 'root/*/.file'
.replace(/^(?=[^\s\/\\])/gm, localRoot(relIgnoresFolder) + '/*/')
// '/folder' -> 'root/folder'
.replace(/^[\/\\]/gm, localRoot(relIgnoresFolder) + '/')
ignored.add(absoluteIgnoresData);
files = filterOutIgnored(files, ignored);
}
}
Expand Down

0 comments on commit bbf8ad2

Please sign in to comment.