feat(restricted_glob): negated globs #4377
Merged
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.
Summary
In the import revamping RFC, I proposed that each group be represented by a special identifier or a glob.
For example in the following list we have two groups:
This will place all imports starting with
@myCompany/
before all other scoped imports.Unfortunately, as noted by a comment in the RFC, this doesn't allow doing the reverse, i.e. placing first all coped imports (except the ones starting with
@myCompany/
).At the time, I thought about a recursive approach to solve this limitation.
However, this looks complicated and might even produce unwanted or confusing results for users.
I think we should keep a simple approach where we stop as soon as a group matches.
So to solve the previous limitation, I think we could allow a group to be defined by a list of globs.
We could allow the inclusion of negated globs in this list, which would act as an exception (similar to what
.gitignore
does).Then we could write:
This PR adds negated globs to restricted globs and a method
matches_with_exceptions
to match against a list of globs where negated globs are treated as exceptions (.gitignore
-like negated globs).Test Plan
I added some unit tests.