eslint-plugin-perfectionist icon indicating copy to clipboard operation
eslint-plugin-perfectionist copied to clipboard

`sort-classes`: Improved and extensible custom groups

Open hugop95 opened this issue 6 months ago • 2 comments

Description

https://github.com/azat-io/eslint-plugin-perfectionist/issues/201

Typings for this rule have been moved in their own file sort-classes.types.ts.

Improves the customGroups API by allowing an array of CustomGroup to be entered rather than an object. Entering an object will still use the currently existing customGroups API.

interface CustomGroup {
  groupName: string
  selector: string
  modifiers?: string[]
  elementNamePattern?: string
  decoratorNamePattern?: string
  valueTypePattern?: string
}

This interface is easily extensible if additional features need to be added later on.

  • groupName: The group's name. Today in customGroups, this is one key of the object.
  • selector: Filter on the selector of the element.
  • modifiers: Filter on the modifiers of the element. (All the modifiers of the element must be present in that list)
  • elementNamePattern: If entered, will check that the name of the element matches the pattern entered. Today in customGroups, this is the value associated to a key of the object.
  • decoratorNamePattern: If entered, will check that at least one decorator matches the pattern entered. (solves #165)
  • valueTypePattern: If entered, will check that the value type of the element matches the pattern entered. Currently unsure about the use cases for this.

Possible improvements:

  • typeDeclarationPattern: Similar to valueTypePattern but for checking type declaration rather than value. Also unsure of the actual use cases for this.

Code example

Here is the simplified configuration that solves #165:

  {
            "groups": [
              "input",
              "output"
            ],
            "customGroups": [
              {
                "groupName": "input",
                "decoratorNamePattern": "Input"
              },
              {
                "groupName": "output",
                "decoratorNamePattern": "Output"
              }
            ]
          }

What is the purpose of this pull request?

  • [x] New Feature
  • [x] Documentation update

hugop95 avatar Aug 14 '24 21:08 hugop95