Skip to content

Commit

Permalink
Rewrite gitignore check code
Browse files Browse the repository at this point in the history
Use already retrieved file contents instead of traversing file tree twice.
  • Loading branch information
Nixinova committed Mar 8, 2024
1 parent 229d324 commit 1592108
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,17 +86,16 @@ async function analyse(rawInput?: string | string[], opts: T.Options = {}): Prom
}

// Load gitignore data and apply ignores rules
if (!useRawContent) {
// TODO switch to be like the gitattributes code
for (const folder of folders) {
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);
// Parse gitignores
const ignoresFile = paths.join(folder, '.gitignore');
if (opts.checkIgnored && fs.existsSync(ignoresFile)) {
const ignoresData = await readFile(ignoresFile);
const localIgnoresData = ignoresData.replace(/^[\/\\]/g, localRoot(folder) + '/');
ignored.add(localIgnoresData);
files = filterOutIgnored(files, ignored);
}
const ignoresData = await readFile(ignoresFile);
const localIgnoresData = ignoresData.replace(/^[\/\\]/g, localRoot(relFolder) + '/');
ignored.add(localIgnoresData);
files = filterOutIgnored(files, ignored);
}
}

Expand Down

0 comments on commit 1592108

Please sign in to comment.