Prefer relative import instead of alias if the import is a subpath #160
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
There is an inconsistent case when dealing with relative subpath imports.
When importing
./foo/bar
, the import is kept and not replaced, which is good. When importingalias/bar
however, the import is not replaced back to./foo/bar
, leading to non-deterministic behavior because the convention depends on the current code state. It should be replaced back to./foo/bar
. Because then always holds:This has a few implications though. The current implementation is kinda 'specialized' on a single fixer, which is why the fixer is decoupled from the error detection. This will lead to a lot of duplicated code because the error detection has to be replicated in the fixer.
Actually I found this plugin recently and implemented my own one before, so I thought the best idea is to put both together. This PR includes some refactoring and the fixes I already had in my project.
babel-plugin-module-resolver
logic to resolve the aliases\
separators in the fixed import pathsWould be great to have this merged! If there are questions or open things to be done, feel free to ask.