Skip to content

[import/order] "import type" always should be recognized as 'type' group #2088

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

Closed
Bardiamist opened this issue May 18, 2021 · 6 comments
Closed

Comments

@Bardiamist
Copy link

Problem

import type {
  RouteName,
} from '~/enums';

should be recognized as type.

If import type then don't need to use pathGroups. Becuase sometimes I can use RouteName as value, sometomes only as type. Then import type keywords must take precedence on group recognition.

Full rules

'import/order': ['error', {
      'newlines-between': 'always',
      'groups': [
        'type',
        'external',
        'builtin',
        'parent',
        'object',
        'sibling',
      ],
      'pathGroups': [
        {
          'pattern': '~/types/**',
          'group': 'type',
        },
        {
          'pattern': '**/types',
          'group': 'type',
        },
        {
          'pattern': '~/**',
          'group': 'builtin',
        },
      ],
    }],
@ljharb
Copy link
Member

ljharb commented May 21, 2021

Please check in the newly released v2.23.3 (#2092).

@Bardiamist
Copy link
Author

@ljharb not helped

Screenshot 2021-05-24 at 11 22 01

@geraintwhite
Copy link
Contributor

@Bardiamist using the following option would prevent type imports being handled by pathGroups:

"pathGroupsExcludedImportTypes": ["type"],

@Bardiamist
Copy link
Author

@grit96 no, that not helped

@geraintwhite
Copy link
Contributor

geraintwhite commented May 26, 2021

The following test passes successfully with the latest plugin version using the config and code you provided plus the option I mentioned above:

test(
  {
    code: `
      import type { ViewStyle, TextStyle } from 'react-native';
      import type { Color } from '~/enums';
    `,
    parser,
    options: [
      {
        'newlines-between': 'always',
        'groups': [
          'type',
          'external',
          'builtin',
          'parent',
          'object',
          'sibling',
        ],
        'pathGroups': [
          {
            'pattern': '~/types/**',
            'group': 'type',
          },
          {
            'pattern': '**/types',
            'group': 'type',
          },
          {
            'pattern': '~/**',
            'group': 'builtin',
          },
        ],
        'pathGroupsExcludedImportTypes': ['type'],
      },
    ],
  },
  parserConfig,
),

@Bardiamist
Copy link
Author

I'm not sure why that not applied at first time (tried twice). It realy working nice now. Thank you

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

No branches or pull requests

3 participants