swille
swille

Reputation: 841

Sorting Typescript imports using `type` keyword with ESLint

I just can't find anything on how to configure this, if it's possible. In this example, I want the type imports grouped together. The docs indicate it's possible but I get errors about no more config options allowed. Ideally it would sort both:

import type {a,b,c}` and `import {type a, type b, type c}

docs https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/order.md#named-truefalse-enabled-truefalse-import-truefalse-export-truefalse-require-truefalse-cjsexports-truefalse-types-mixedtypes-firsttypes-last-

After lint --fix

import {
  type QueryKey,
  queryOptions,
  useQueries,
  useQuery,
  type UseQueryOptions,
} from '@tanstack/react-query';

expected sorting

import {
  queryOptions,
  useQueries,
  useQuery,
  type QueryKey,
  type UseQueryOptions,
} from '@tanstack/react-query';

eslintrc file

      'error',
      {
        ignoreCase: true,
        ignoreDeclarationSort: false,
        allowSeparatedGroups: true,
      },
    ],
    'import/order': [
      'error',
      {
        alphabetize: {
          order: 'asc',
        },
        'newlines-between': 'always',
        pathGroups: [{ pattern: '~/**', group: 'internal', position: 'after' }],
        groups: [
          'builtin',
          'external',
          'internal',
          'parent',
          'sibling',
          'index',
          'object',
          'type',
        ],
      },
    ],

Upvotes: 0

Views: 49

Answers (0)

Related Questions