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.14k stars 44 forks source link

Feature: sort interface properties, object keys and array values if code has annotation #400

Open sardor01 opened 4 days ago

sardor01 commented 4 days ago

Describe the rule

There is existing package that implements similar feature: https://github.com/ronparkdev/eslint-plugin-annotation

I personally think it would be great if eslint-plugin-perfectionist provided thie rule since it's also related to sorting.

Code example

| sort | sort-keys |

Additional comments

No response

Validations

azat-io commented 4 days ago

Currently, you can use ESLint comments to define plugin rule settings.

/*
  eslint perfectionist/sort-objects: [
    'error',
    {
      type: 'alphabetical',
      order: 'asc',
      partitionByNewLine: true
    }
  ]
*/

Using annotations looks beautiful and convenient. But I'm not sure it will be in demand.

I would like to hear more opinions from other users.

hugop95 commented 4 days ago

I understand the use case for sort-array-includes: it would allow users to sort arrays who do not have .include if the user wishes.

However, I'm not sure to understand the use case with other rules such as sort-objects: all objects get sorted if the rule is active, why would an annotation be needed?

azat-io commented 3 days ago

@sardor01 Perhaps the ESLint comment solves your problem?