From 7fc6355208a46b826deb18b765423bb87240d431 Mon Sep 17 00:00:00 2001 From: Michael Cousins Date: Thu, 3 Oct 2024 01:33:44 -0400 Subject: [PATCH] Do not treat trailing `#` in gitignore as comment (#797) --- packages/knip/src/util/glob-core.ts | 2 +- .../util/parse-and-convert-gitignore-patterns.test.ts | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/knip/src/util/glob-core.ts b/packages/knip/src/util/glob-core.ts index a13db7c23..babce2ad1 100644 --- a/packages/knip/src/util/glob-core.ts +++ b/packages/knip/src/util/glob-core.ts @@ -54,7 +54,7 @@ export const parseAndConvertGitignorePatterns = (patterns: string, ancestor?: st .split(/\r?\n/) .filter(line => line.trim() && !line.startsWith('#')) .flatMap(line => { - const pattern = line.replace(/(? { { negated: false, patterns: ['c', 'c/**'] }, ]); }); + +test('parseAndConvertGitignorePatterns (hashes)', async () => { + const gitignorePatterns = ['#comment', 'ends-with-hash#', String.raw`\#starts-with-hash`]; + const globPatterns = parse(gitignorePatterns.join(EOL)); + assert.deepEqual(globPatterns, [ + { negated: false, patterns: ['**/ends-with-hash#', '**/ends-with-hash#/**'] }, + { negated: false, patterns: ['**/#starts-with-hash', '**/#starts-with-hash/**'] }, + ]); +});