Allow isIgnored
to un-ignore results by returning token
#137
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Making the case for negated ignore patterns.
Glob libraries like fast-glob, node-glob and tinyglobby use the
ignore
option to exclude matches from the results. Yet there's also a case to be made to un-ignore such results. For instance, when.gitignore
files should be taken into account.Let's say we have the following
Or just
Projects may have files like
.gitignore
(or other ignore files) like so:The semantics of
.gitignore
items differ from glob patterns, but let's ignore that here, not picomatch's problem.What downstream packages might want to do is take such patterns into account like this:
There's currently just no feasible way to make the negated items from
.gitignore
slip through.So that's where this PR comes in. We can filter out the negated patterns and:
By returning the token, the item is un-ignored and slips through. The implementation of
onUnignore
should be optimized, this is just an example to illustrate the idea.A solution like this with a token is guaranteed to be a non-breaking change. An alternative I thought of first would be to simply return
true
which would probably also not be a breaking change, but it's not guaranteed.Relevant issues:
ignore
option mrmlnc/fast-glob#86Part of why globby got so popular is because of it's support for
.gitignore
files, but the implementation is rather tedious and slow. Solving this in picomatch directly would be a major advantage in terms of both simplicity and performance.I think the implementation is relatively clean and low-impact while non-breaking. Needless to say I'm open to suggestion to improve if you have any!