Sort interface and string enum keys in custom order
npm install eslint-plugin-typescript-custom-sort-keysThis plugin sorts your typescript and interfaces in a custom defined order.
References:
- eslint/sort-keys
- eslint/eslint-plugin-typescript-sort-keys
``sh`
yarn add -D eslint-plugin-typescript-custom-sort-keys
`json`
{
"plugins": ["typescript-custom-sort-keys"]
}
Then configure the rules you want to use under the rules section.
displayFirst: Define array of fields that you want to show on top
showFunctionsAtEnd: keep it true if you want to show your functions in end
`json``
{
"rules": {
"typescript-custom-sort-keys/interface": [
"warn",
"asc",
{
"caseSensitive": true,
"displayFirst": ["id"],
"showFunctionsAtEnd": true,
},
],
}
}
|Before| After |
|--|--|
|
|
|