From 3ddd8dcaea106de3b1a5bfe3532f8cdeb8c7e317 Mon Sep 17 00:00:00 2001 From: Nixinova Date: Sat, 9 Mar 2024 00:00:57 +1300 Subject: [PATCH] Ignore gitattributes comments --- changelog.md | 3 +++ src/helpers/parse-gitattributes.ts | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/changelog.md b/changelog.md index 544df28..30b9f94 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,8 @@ # Changelog +## Next +- Fixed gitattributes comments being parsed as attributes data. + ### 2.7.0-pre - Added CLI option `--listFiles` to list each matching file under each language result. - Fixed files that are by default marked vendored being removed even when marked as not vendored in gitattributes ([#26](https://github.com/Nixinova/LinguistJS/issues/26)). diff --git a/src/helpers/parse-gitattributes.ts b/src/helpers/parse-gitattributes.ts index e42db2c..3c914a4 100644 --- a/src/helpers/parse-gitattributes.ts +++ b/src/helpers/parse-gitattributes.ts @@ -21,7 +21,8 @@ export type ParsedGitattributes = Array<{ export default function parseAttributes(content: string, folderRoot: string = '.'): ParsedGitattributes { const output: ParsedGitattributes = []; - for (const line of content.split('\n')) { + for (const rawLine of content.split('\n')) { + const line = rawLine.replace(/#.*$/, '').trim(); if (!line) continue; const parts = line.split(/\s+/g);