Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[must-colocate-fragment-spreads] Handle importing relative index.js files which are direct siblings #104

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

JonathanUsername
Copy link

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:

import MyComponent from './'

graphql`
  ...MyComponent_foo
`

The ImportDeclaration parsing fails to understand this relative shorthand:

  let moduleName =
    filename === 'index' ? path.basename(path.dirname(filePath)) : filename;

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants