Sort interface and string enum keys
npm install eslint-plugin-typescript-sort-keysSort interface and string enum keys
Inspired by and sourced from eslint/sort-keys)
You'll first need to install
- eslint
- typescript
- @typescript-eslint/parser
``sh`
yarn add -D eslint typescript @typescript-eslint/parser
Next, install eslint-plugin-typescript-sort-keys:
`sh`
yarn add -D eslint-plugin-typescript-sort-keys
Note: If you installed ESLint globally then you must also install eslint-plugin-typescript-sort-keys globally.
Specify the parser for typescript files in your .eslintrc configuration file:
`json`
{
"parser": "@typescript-eslint/parser"
}
Add typescript-sort-keys to the plugins section. You can omit the eslint-plugin- prefix:
`json`
{
"plugins": ["typescript-sort-keys"]
}
Then configure the rules you want to use under the rules section.
`json`
{
"rules": {
"typescript-sort-keys/interface": "error",
"typescript-sort-keys/string-enum": "error"
}
}
Or enable all rules with defaults
`json`
{
"extends": ["plugin:typescript-sort-keys/recommended"]
}
Key: :heavy_check_mark: = recommended, :wrench: = fixable
| Name | Description | :heavy_check_mark: | :wrench: |
| ---- | ----------- | ------------------ | -------- |
| typescript-sort-keys/interface | require interface keys to be sorted | :heavy_check_mark: | :wrench: |
| typescript-sort-keys/string-enum` | require string enum members to be sorted | :heavy_check_mark: | :wrench: |