azat-io / eslint-plugin-perfectionist

☂️ ESLint plugin for sorting various data such as objects, imports, types, enums, JSX props, etc.
https://perfectionist.dev
MIT License
2.13k stars 44 forks source link

Feature: Ignore index signature while sorting types #395

Open ntnyq opened 5 days ago

ntnyq commented 5 days ago

What rule do you want to change?

sort-object-types, sort-interfaces

Describe the problem

I prefer the order like this:

but the plugin treats index signatures as a required property.

Maybe we can add an options to ignore index signature.

Or is there any options can already make this happen?

Code example

export type Foobar = {
  foo: string
  bar?: string
  [key: string]: any
}

Config is rule perfectionist/sort-object-types with groupKind: 'required-first'.

Additional comments

No response

Validations

hugop95 commented 5 days ago

@azat-io @OlivierZal I personally think that the groupKind option can be deprecated for a system similar to what exists in sort-classes and sort-modules, with

This would allow users to:

The disadvantage is that it potentially does make the config a bit more verbose: it's easier to write groupKind: 'required-first' than a groups configuration, but this limits possibilities.

Let me know what you think!

OlivierZal commented 5 days ago

@hugop95, I would be in favor to migrate to the sort-classes / sort-modules system whenever it's possible: if you remember, at the beginning I proposed to use groupKind: optional-first/required-first for classes, but the system which has been chosen is both flexible and transparent. It might be overkill for some, given the small number of options for types/interfaces, but the resulted config shouldn't be more verbose though.