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

[import/extensions] Doesn't error on . or .. #2777

Closed
benasher44 opened this issue May 7, 2023 · 3 comments · Fixed by #2778
Closed

[import/extensions] Doesn't error on . or .. #2777

benasher44 opened this issue May 7, 2023 · 3 comments · Fixed by #2778

Comments

@benasher44
Copy link
Contributor

benasher44 commented May 7, 2023

I have this rule configured like so:

'import/extensions': ['error', 'ignorePackages'],

With this configuration, the following is flagged as an error:

import { Something } from './LocalFolderWithIndexfile'

However, the following is not flagged as an error, but I believe it should be:

import { Something } from '.'

The only difference between the two is where in the file tree the importing file sits. As a workaround, one can supplement this rule with the general no-restricted-imports rule like this:

'no-restricted-imports': ['error',
  {
    paths: [
      {
        name: '..',
        message: 'Import from ../index.js instead.',
      },
      {
        name: '.',
        message: 'Import from ./index.js instead.',
      },
    ],
  },
],

Apologies if this has already been filed. I found it really hard to search for

@ljharb
Copy link
Member

ljharb commented May 7, 2023

. should not be, because that's not necessarily pointing to a specific file, it's potentially pointing to a package.json. . won't always be index.js, and the whole point of that feature is to not specify extensions and defer to node's algorithm for it.

@ljharb
Copy link
Member

ljharb commented May 7, 2023

Although I do see the discontinuity - when . points to an index file and there's no package.json, i think you're right, it should warn.

@benasher44
Copy link
Contributor Author

benasher44 commented May 8, 2023

Yep it's exactly that case: when it's meant to point to an index.js w/o a package.json

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

Successfully merging a pull request may close this issue.

2 participants