lydell / eslint-plugin-simple-import-sort

Easy autofixable import sorting.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to sort first all `import * as`

ChristoRibeiro opened this issue · comments

Hi,

I'm trying to sort first all imports that contain import * as like so:

  • import * as R from "remeda"
  • import * as _ from "lodash"

What is the the right config? Any idea @lydell?

Thanks.

My config for now:

"simple-import-sort/imports": ["error", {
  "groups": [[
    // type (e.g. `import type { ... } from "..."`)
    "^.*\\u0000$",
    // `react`.
    "^react",
    // `next`
    "^next\\/",
    // things that start with a letter (or digit or underscore), or `@` followed by a letter
    "^@?\\w",
    // internal
    "^@/",
    // relative parent (e.g. `import ... from ".."`)
    "^\\.\\.(?!/?$)",
    "^\\.\\./?$",
    // relative same folder (e.g. `import ... from "./"`)
    "^\\./(?=.*/)(?!/?$)",
    "^\\.(?!/?$)",
    "^\\./?$",
    // side effect (e.g. `import "./foo"`)
    "^\\u0000",
    // css
    "^.+\\.s?css$"
  ]]
}],

Hi! That is not possible. This plugin only sorts on the from part (plus being able to choose where side effect imports and type imports go).

https://github.com/lydell/eslint-plugin-simple-import-sort#why-sort-on-from

In my opinion, changing import {foo} from "lodash" to import * as _ from "lodash" should not change the sorting.

To me, side effect imports and type imports are completely different from other imports, so being able to choose where they are makes sense. But import * as is just like any other import.

Thanks for the feedback @lydell

I tried on a small project to sort manually imports and grouping all import * as make easier to read the whole imports block (in my opinion).

I see, thank you for replying!

This is not something I would like to add. I recommend either:

  • Finding another plugin that can do it.
  • Forking this plugin.
  • Living without this way of sorting.