Skip to content

[import-order] order within import type #2172

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
alvis opened this issue Aug 1, 2021 · 7 comments · Fixed by #3104
Closed

[import-order] order within import type #2172

alvis opened this issue Aug 1, 2021 · 7 comments · Fixed by #3104

Comments

@alvis
Copy link

alvis commented Aug 1, 2021

Now, import type can be a separate group.
I also find the ability to alphabetize very useful.

However, I find it very annoying that they don't work well together.
The problem is that the order of import type statement doesn't follow the order we define for other module types.
Let's say we have the following options

"import/order": [
  "warn",
  {
    "groups": [
      "builtin",
      "external",
      "type"
    ],
    "newlines-between": "always-and-inside-groups",
    "alphabetize": { "order": "asc", "caseInsensitive": true }
  }
],

e.g. I'd like to have the following order

// buildin modules before external modules

// for ordinary import it's ok, builtin first, then external
import { createServer } from 'http'

import { graphql } from 'gatsby';

// but for `import type` it warns that the gatsby import should be put in front of the http one
// the order is right here since http is a buildin and gatsby is an external
import type { RequestOptions } from 'http'

import type { PageProps } from 'gatsby';
@ljharb
Copy link
Member

ljharb commented Aug 16, 2021

Seems like to do what you want, the schema would need some way of providing alternative config options for a specific group.

I suppose we could add groupOverrides: { [groupName]: groupConfiguration }, but that seems like a lot of complexity for such a specific use case.

@alvis
Copy link
Author

alvis commented Aug 18, 2021

or can we take the order from groups excluding type when we analyze the order within import type statements?

@ljharb
Copy link
Member

ljharb commented Aug 18, 2021

I'm not sure what you mean. Can you elaborate?

@Exelenz9
Copy link

This answer helped me to solve similar problem

@kaysonwu
Copy link

I have the same issue. @ljharb the type group should also follow the basic order, e.g. : "builtin", "external", "internal", "parent", "Sibling ","index", "object"

@danranVm
Copy link

danranVm commented Oct 9, 2021

I have the same problem.

import type { TablePagination, TableProps } from '../types'
import type { TableConfig } from '@idux/components/config'
import type { ComputedRef } from 'vue'

import { computed, ref, watchEffect } from 'vue'

import { callEmit } from '@idux/cdk/utils'
import { useGlobalConfig } from '@idux/components/config'

import { tablePagination, tableProps } from '../types'

my config :

          {
            alphabetize: { order: 'asc', caseInsensitive: false },
            'newlines-between': 'always',
            groups: ['type', 'builtin', 'external', 'internal', ['parent', 'sibling', 'index']],
            pathGroups: [
              {
                pattern: '{vue,@vue/**}',
                group: 'external',
                position: 'before',
              },
              {
                pattern: '@idux/**',
                group: 'internal',
                position: 'before',
              },
            ],
            pathGroupsExcludedImportTypes: ['type'],
          },

@danranVm
Copy link

danranVm commented Oct 9, 2021

Seems like to do what you want, the schema would need some way of providing alternative config options for a specific group.

I suppose we could add , but that seems like a lot of complexity for such a specific use case.groupOverrides: { [groupName]: groupConfiguration }

Hope to support this configuration, thank you.

@ljharb In addition, I have another idea, for 'type' grouping, according to groups' exclude 'type', do a sort again.

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