matchesIgnorePatterns function
Returns whether relativePath is excluded by patterns.
relativePath must be relative to the scan root (reference or target).
patterns use gitignore-compatible syntax, including ! negation.
Implementation
bool matchesIgnorePatterns({
required String relativePath,
required List<String> patterns,
}) {
if (patterns.isEmpty) {
return false;
}
final normalizedPath = normalizeIgnoreRelativePath(relativePath);
var ignored = false;
for (final pattern in patterns) {
if (pattern.startsWith('!')) {
if (matchesIgnorePattern(
relativePath: normalizedPath,
pattern: pattern.substring(1),
)) {
ignored = false;
}
} else if (matchesIgnorePattern(
relativePath: normalizedPath,
pattern: pattern,
)) {
ignored = true;
}
}
return ignored;
}