Ignore constructor
- List<
String> patterns, { - bool ignoreCase = false,
- void onInvalidPattern(
- String pattern,
- FormatException exception
Create an Ignore instance with a set of .gitignore
compatible
patterns.
Each value in patterns
will be interpreted as one or more lines from
a .gitignore
file, in compliance with the .gitignore
manual page.
The keys of 'pattern' are the directories to intpret the rules relative to. The root should be the empty string, and sub-directories are separated by '/' (but no final '/').
If ignoreCase
is true
, patterns will be case-insensitive. By default
git
is case-sensitive. But case insensitivity can be enabled when a
repository is created, or by configuration option, see
core.ignoreCase
documentation for details.
If onInvalidPattern
is passed, it will be called with a
FormatException describing the problem. The exception will have source
as source.
Example:
import 'package:ignore/ignore.dart';
void main() {
final ignore = Ignore({'': [
// You can pass an entire .gitignore file as a single string.
// You can also pass it as a list of lines, or both.
'''
# Comment in a .gitignore file
obj/
*.o
!main.o
'''
}]);
print(ignore.ignores('obj/README.md')); // true
print(ignore.ignores('lib.o')); // false
print(ignore.ignores('main.o')); // false
}
Implementation
Ignore(
List<String> patterns, {
bool ignoreCase = false,
void Function(String pattern, FormatException exception)? onInvalidPattern,
}) : _rules = _parseIgnorePatterns(
patterns,
ignoreCase,
onInvalidPattern: onInvalidPattern,
).toList(growable: false);