azat-io / eslint-plugin-perfectionist

🦄 ESLint plugin for sorting various data such as objects, imports, types, enums, JSX props, etc.
https://eslint-plugin-perfectionist.azat.io
MIT License
1.62k stars 28 forks source link

Feature: sort-imports sort order by group order in line-length #142

Open matheusdsilva01 opened 2 weeks ago

matheusdsilva01 commented 2 weeks ago

What rule do you want to change?

sort-imports

Describe the problem

The possibility of sorting by group order. I believe it would be something like: "sort-order-groups": true

sort-order-groups rule with first create after get:

"perfectionist/sort-imports": [
      "warn",
      {
        "type": "line-length",
        "order": "desc",
        "groups": [
          ["create", "get"],
          ["builtin", "external"]
        ],
        "custom-groups": {
          "value": {
            "get": "../utils/get/**/*",
            "create": "../utils/create/**/*"
          }
        },
        "newlines-between": "always",
        "sort-groups": true
      }
    ]

Code example

without sort-order-groups rule, sort this:

import { createEslintRule } from '../utils/create'
import { createEslint } from '../utils/create'
import { getLinesBetween } from '../utils/get'
import { getGroupNumber } from '../utils/get'
import { createRule } from '../utils/create'
import { getNodeRange } from '../utils/get'
import { getGroup } from '../utils/get'

with "sort-order-groups": true rule:

import { createEslintRule } from '../utils/create'
import { createEslint } from '../utils/create'
import { createRule } from '../utils/create'
import { getLinesBetween } from '../utils/get'
import { getGroupNumber } from '../utils/get'
import { getNodeRange } from '../utils/get'
import { getGroup } from '../utils/get'

Additional comments

I used Google Translate for this issue, sorry if there are some grammatical errors 😄

Validations