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: Group named import/export kinds (type/value) on sort-named-imports/exports #114

Closed renato-bohler closed 2 months ago

renato-bohler commented 2 months ago

What rule do you want to change?

sort-named-imports & sort-named-exports

Describe the problem

Hey, first of all, love this plugin!


Currently, there's no way to configure sort-named-imports and sort-named-exports to group inline type import/exports.

Code example

When using this rule to sort named imports alphabetically, we get:

import { A, type B, C, type D} from 'rurouni-kenshin'

This is fine, but IMO we should have an option to group inline type imports before/after value imports to improve readability.

Same goes for named exports.

Additional comments

I've implemented this by adding an option called group-kind with possible values mixed (default, current behavior), values-first, and types-first.

// group-kind: mixed
import { A, type B, C, type D} from 'rurouni-kenshin'

// group-kind: values-first
import { A, C, type B, type D } from 'rurouni-kenshin'

// group-kind: types-first
import { type B, type D, A, C } from 'rurouni-kenshin'

Not sure how https://github.com/azat-io/eslint-plugin-perfectionist/pull/113 will affect it, but I've opened https://github.com/azat-io/eslint-plugin-perfectionist/pull/115 anyway. If we agree that this should be doable on this plugin, I can reimplement it on v3.

Validations

azat-io commented 2 months ago

Released in v2.7.0.