Skip to content

Commit

Permalink
Fix gitignore data being parsed root-relative
Browse files Browse the repository at this point in the history
  • Loading branch information
Nixinova committed Mar 8, 2024
1 parent f68f376 commit 117af9e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 2 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# Changelog

## Next
*From pre-release:*
- Fixed gitattributes comments being parsed as attributes data.
- Fixed gitignores data being parsed root-relative instead of relative to the folder the file is in.

### 2.7.0-pre
- Added CLI option `--listFiles` to list each matching file under each language result.
Expand Down
9 changes: 7 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,13 @@ async function analyse(rawPaths?: string | string[], opts: T.Options = {}): Prom
const relFile = relPath(ignoresFile);
const relFolder = paths.dirname(relFile);
// Parse gitignores
const ignoresData = await readFile(ignoresFile);
const localIgnoresData = ignoresData.replace(/^[\/\\]/g, localRoot(relFolder) + '/');
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);
files = filterOutIgnored(files, ignored);
}
Expand Down

0 comments on commit 117af9e

Please sign in to comment.