<ESLINT> How can place all "import type" lines at the bottom and force the same alignment order of non "import type" lines

122 views Asked by At

First of all, Here is my .eslintrc.js file. I have a project with aliased modules (@foo/**).

module.exports = {
  extends: ['plugin:prettier/recommended', 'plugin:@typescript-eslint/recommended'],
  parser: '@typescript-eslint/parser',
  parserOptions: { ecmaVersion: '2021', sourceType: 'module' },
  plugins: ['import', '@typescript-eslint'],
  root: true,
  rules: {
    '@typescript-eslint/no-explicit-any': 'off',
    '@typescript-eslint/no-namespace': 'off',
    '@typescript-eslint/no-empty-interface': 0,
    'import/order': [
      'error',
      {
        alphabetize: { order: 'asc' },
        pathGroups: [
          {
            pattern: '@foo/**',
            group: 'external',
            position: 'after',
          },
        ],
        distinctGroup: false,
        groups: ['builtin', 'external', 'internal', 'parent', 'sibling', 'object', 'index', 'unknown', 'type'],
        pathGroupsExcludedImportTypes: ['@foo', 'type'],
      },
    ],
  },
};

What I want from this eslint is to order my import lines to be like this below,

import { A } from 'express';
import { B } from '@foo/bar';
import { C } from '../baz';

import type { D } from 'express';
import type { E } from '@foo/bar';
import type { F } from '../baz';

But with my .eslintrc.js file, it forces import lines to be this.

import { A } from 'express';
import { B } from '@foo/bar';
import { C } from '../baz';

import type { F } from '../baz';
import type { E } from '@foo/bar';
import type { D } from 'express';

When I remove 'type' from pathGroupsExcludedImportTypes, this is how it works.

import { A } from 'express';
import { B } from '@foo/bar';
import type { E } from '@foo/bar';
import { C } from '../baz';

import type { D } from 'express';
import type { F } from '../baz';

How can I fix my eslint setting?

0

There are 0 answers