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/order]: Typescript path incorrect groups #1379

Closed
tomaskallup opened this issue Jun 12, 2019 · 3 comments · Fixed by #1493
Closed

[import/order]: Typescript path incorrect groups #1379

tomaskallup opened this issue Jun 12, 2019 · 3 comments · Fixed by #1493

Comments

@tomaskallup
Copy link

I ran into a weird case of import/order with new lines between groups.
I'm using typescript & the typescript resolver (apologies, if this issue is on the resolver side, just tell me and I'll open it there).

I created a repo for this as that's simpler than trying to explain: https://github.com/tomaskallup/eslint-import-typescript-bug

Just clone, yarn/npm install & yarn/npm run lint. It will report lines in atomics/box/box-article/box-article.ts as wrong, because it assings different groups to imports of same type (they should be internal export according to documentation of the import/order rule) and the rule requires space between them.

Since the imports start with '@', this might be related to #1293, but I didn't really find anything helpful to my case.

@davidpelayo
Copy link

Same thing here ✋ . Aliased '@/paths' are considered external so I can't sort them correctly.

@michielmetcake
Copy link

same here. any help on this issue is much appreciated

@AamuLumi
Copy link
Contributor

AamuLumi commented Sep 3, 2019

Hi !

I have the same bug on a big Typescript project.
I checked my code and the code from @tomaskallup project.

I found that this way of writing the imports works on its project :

import {someFunc} from '@utils/some-util';

import {Button} from '@atomics';
import {Omit} from '@typings';
import {Box, BoxProps} from '..';

It seems that paths reference from tsconfig.json file which points to a file or an index in a folder (ex: "@atomics": ["atomics"]) are considered as elements of unknown group (according to the doc).
In other case, paths reference which described a shortcut (ex: "@utils/*" : ["utils/*"]) are considered as internal.

So it seems to be a problem of tsconfig paths recognition.

I tested the project with :

    'import/order': [
      'error',
      {
        groups: [
          'builtin',
          'external',
          ['internal', 'unknown'],
          'parent',
          'sibling',
          'index',
        ],
        'newlines-between': 'always',
      },
    ],

and this code works :

import {Button} from '@atomics';
import {Omit} from '@typings';
import {someFunc} from '@utils/some-util';
import {Box, BoxProps} from '..';

Hope it will help to fix the issue!

@ljharb ljharb closed this as completed in 2d3d045 Dec 6, 2019
marcusdarmstrong pushed a commit to marcusdarmstrong/eslint-plugin-import that referenced this issue Dec 9, 2019
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.

5 participants