Skip to content

Commit

Permalink
feat(groups): use minimatch for matchesKnownList
Browse files Browse the repository at this point in the history
We should use minimatch instead of includes for matching the known lists. This
will ensure the same behavior packages is retained with the change and extends
the functionality to support glob patterns.
  • Loading branch information
ardelato committed Jul 9, 2024
1 parent a628435 commit f5755ed
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/guards/can-add-to-group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ function matchesKnownList(values: unknown, value: string): boolean {
positive.push(name);
}
});
if (isNonEmptyArray(negative) && !negative.includes(value)) return true;
return isNonEmptyArray(positive) && positive.includes(value);
if (isNonEmptyArray(negative) && !someMinimatch(value, negative)) return true;
return isNonEmptyArray(positive) && someMinimatch(value, positive);
}

function someMinimatch(value: string, patterns: string[]): boolean {
return patterns.some((pattern) => minimatch(value, pattern))
}

0 comments on commit f5755ed

Please sign in to comment.