eslint-plugin-sort-decorators
v0.4.0
Published
An ESLint plugin to sort decorators
Maintainers
Readme
eslint-plugin-sort-decorators
An ESLint plugin to sort decorators
Installation
First, the peer dependencies must be installed:
npm i --save-dev typescript eslint @typescript-eslint/parserNext, install eslint-plugin-sort-decorators:
npm i --save-dev eslint-plugin-sort-decoratorsUsage - Flat Config (Eslint >= 9)
As this plugin only works with typescript, the parser must be set:
import * as tsParser from "@typescript-eslint/parser"
import eslintSortDecorators from "eslint-plugin-sort-decorators";
export default [
// other configurations
{
files: ["**/*.ts"],
plugins: { "sort-decorators": eslintSortDecorators },
languageOptions: { parser: tsParser },
rules: {
'sort-decorators/sort-on-classes': 'error',
}
},
// other configurations
]Or simply use a configuration preset:
import eslintSortDecorators from "eslint-plugin-sort-decorators";
export default [
// other configurations
eslintSortDecorators.configs["flat/recommended"],
// other configurations
]Configuration presets (Flat config)
| Name | Description |
|:-------------------------------------|:---------------------------------------------------------------|
| plugin:sort-decorators/flat/recommended | Enables all rules with a warn security level. |
| plugin:sort-decorators/flat/strict | Enables all rules with a error security level and autoFix. |
Usage - Legacy (Eslint < 9)
As this plugin only works with typescript, the parser must be set in a .eslintrc file:
{
"parser": "@typescript-eslint/parser"
}The plugin can then be activated by adding sort-decorators to the plugins property:
{
"plugins": ["sort-decorators"]
}The different rules can be defined as follows:
{
"rules": {
"sort-decorators/sort-on-classes": "error"
}
}Or simply extends a configuration preset:
{
"extends": ["plugin:sort-decorators/recommended"]
}Configuration presets
| Name | Description |
|:-------------------------------------|:---------------------------------------------------------------|
| plugin:sort-decorators/recommended | Enables all rules with a warn security level. |
| plugin:sort-decorators/strict | Enables all rules with a error security level and autoFix. |
All this configuration can be done on a
overridesection: https://eslint.org/docs/latest/use/configure/configuration-files#how-do-overrides-work
Rules
💼 Configurations enabled in.
⚠️ Configurations set to warn in.
✅ Set in the recommended configuration.
🔒 Set in the strict configuration.
🔧 Automatically fixable by the --fix CLI option.
| 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 | 🔒 | ✅ | 🔧 |
Releases
See information about breaking changes and release notes here.
