eslint-plugin-perfectionist
eslint-plugin-perfectionist copied to clipboard
`sort-classes`: Improved and extensible custom groups
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 incustomGroups
, this is one key of the object. -
selector
: Filter on theselector
of the element. -
modifiers
: Filter on themodifiers
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 incustomGroups
, this is the value associated to a key of the object. -
decoratorNamePattern
: If entered, will check that at least onedecorator
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 tovalueTypePattern
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