Skip to content

Commit

Permalink
Fix bug with patterns already in globally ignored patterns
Browse files Browse the repository at this point in the history
  • Loading branch information
webpro committed Sep 7, 2024
1 parent 7035dee commit 4c6c1ed
Showing 1 changed file with 17 additions and 21 deletions.
38 changes: 17 additions & 21 deletions packages/knip/src/util/glob-core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,40 +111,36 @@ export const findAndParseGitignores = async (cwd: string) => {
const patterns = readFileSync(filePath, 'utf8');

for (const rule of parseAndConvertGitignorePatterns(patterns, ancestor)) {
const [pattern, extraPattern] = rule.patterns;
const [pattern1, pattern2] = rule.patterns;
if (rule.negated) {
if (base === '' || base.startsWith('..')) {
if (!unignores.includes(extraPattern)) {
if (!unignores.includes(pattern2)) {
unignores.push(...rule.patterns);
dirUnignores.add(pattern);
dirUnignores.add(extraPattern);
dirUnignores.add(pattern1);
dirUnignores.add(pattern2);
}
} else {
if (!unignores.includes(extraPattern.startsWith('**/') ? extraPattern : `**/${extraPattern}`)) {
const unignore = join(base, pattern);
const extraUnignore = join(base, extraPattern);
if (!unignores.includes(pattern2.startsWith('**/') ? pattern2 : `**/${pattern2}`)) {
const unignore = join(base, pattern1);
const extraUnignore = join(base, pattern2);
unignores.push(unignore, extraUnignore);
dirUnignores.add(unignore);
dirUnignores.add(extraUnignore);
}
}
} else {
if (base === '' || base.startsWith('..')) {
if (!ignores.has(extraPattern)) {
ignores.add(pattern);
ignores.add(extraPattern);
dirIgnores.add(pattern);
dirIgnores.add(extraPattern);
}
ignores.add(pattern1);
ignores.add(pattern2);
dirIgnores.add(pattern1);
dirIgnores.add(pattern2);
} else {
if (!ignores.has(extraPattern.startsWith('**/') ? extraPattern : `**/${extraPattern}`)) {
const ignore = join(base, pattern);
const extraIgnore = join(base, extraPattern);
ignores.add(ignore);
ignores.add(extraIgnore);
dirIgnores.add(ignore);
dirIgnores.add(extraIgnore);
}
const ignore = join(base, pattern1);
const extraIgnore = join(base, pattern2);
ignores.add(ignore);
ignores.add(extraIgnore);
dirIgnores.add(ignore);
dirIgnores.add(extraIgnore);
}
}
}
Expand Down

0 comments on commit 4c6c1ed

Please sign in to comment.