feat(organize_import): move legacy code to a deidicated module an dintroduce restricted globs #4357
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
Part of #3177
This PR moves the current code to a legacy module and introduce restricted globs.
I am using the
gloset
crate for proper support of globs.I choose this library because we already use the regex crate (
globset
is based on theregex
crate).Restricted globs abstracts over
gloset
in order to have a consistent behavior and make easy a change of glob library if we want to.Restricted globs support only stars
*
and globstars**
matchers.*
can be escaped with\
on any platforms (matching against\
on Windows is disabled). Also, we configure globset to ensure that*
doesn't match/
. Characters such as?
,[
, and{
must be escaped.I plan to lift some restrictions in the future (before release).
For the time being I think it is enough.
We will certainly need to add a superset to restricted glob in order to match against import sources.
Indeed, import sources can include protocols such as
node:fs
or,npm:@scope/package/subpath
.We could introduce a special glob that allow matching against it. For example
**:**
could match against any import source,**
could match only against protocol-less imports,*:**
could match only against imports with protocols, ... I am not 100% sure about that and left it for a future PR.Test Plan
I added some tests.