[must-colocate-fragment-spreads] Handle importing relative index.js files which are direct siblings #104
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.
If you import a component that is a direct sibling (in the same directory) using the ./index.js shorthand (
.
,./
, etc.) the rule currently fails, as the module parsing returns an empty string.given the code:
The ImportDeclaration parsing fails to understand this relative shorthand:
Here
moduleName
becomes simply.
.My approach is to, in that case, parse the context filename to get out the parent directory. It's perhaps questionable since it means changing a util that is marked as "Copied directly from relay", but it's clear that this plugin is failing where Relay does not - namely in correctly resolving the relative import.
I'm open to better ways to fix this, but it was flagged up swiftly after we tried installing this on our large codebase as it complained in many places (we use this pattern frequently) and the error message in those cases was confusing and inscrutable - ("...but it IS imported and used!").
I've added tests to check and to help elucidate the problem.