An ESLint plugin to sort decorators
npm install @elsikora/eslint-plugin-sort-decorators

!Code coverage
An ESLint plugin to sort decorators
First, the peer dependencies must be installed:
- eslint
- typescript
- @typescript-eslint/parser
``bash`
npm i --save-dev typescript eslint @typescript-eslint/parser
Next, install eslint-plugin-sort-decorators:
`bash`
npm i --save-dev @elsikora/eslint-plugin-sort-decorators
As this plugin only works with _typescript_,
the parser must be set in a .eslintrc
file:
`json`
{
"parser": "@typescript-eslint/parser"
}
The plugin can then be activated by adding sort-decorators to the plugins property:
`json`
{
"plugins": ["@elsikora/sort-decorators"]
}
The different rules can be defined as follows:
`json`
{
"rules": {
"@elsikora/sort-decorators/sort-on-classes": "error"
}
}
Or simply extends a configuration preset:
`json`
{
"extends": ["plugin:@elsikora/sort-decorators/recommended"]
}
| Name | Description |
|:-----------------------------------------------|:---------------------------------------------------------------|
| plugin:@elsikora/sort-decorators/recommended | Enables all rules with a warn security level. |plugin:@elsikora/sort-decorators/strict
| | Enables all rules with a error security level and autoFix. |
---
> All this configuration can be done on a override section:
>
š¼ Configurations enabled in.\
ā ļø Configurations set to warn in.\
ā
Set in the recommended configuration.\strict
š Set in the configuration.\--fix` CLI option.
š§ Automatically fixable by the
| Name | Description | š¼ | ā ļø | š§ |
| :----------------------------------------------------- | :-------------------------------------- | :- | :- | :- |
| sort-on-accessors | Enforces order of accessors decorators | š | ā
| š§ |
| sort-on-classes | Enforces order of class decorators | š | ā
| š§ |
| sort-on-methods | Enforces order of methods decorators | š | ā
| š§ |
| sort-on-parameters | Enforces order of parameters decorators | š | ā
| š§ |
| sort-on-properties | Enforces order of properties decorators | š | ā
| š§ |
See information about breaking changes and release notes here.