1 | ![Tests](https://github.com/infctr/eslint-plugin-typescript-sort-keys/workflows/Tests/badge.svg?branch=master)
|
2 |
|
3 | # eslint-plugin-typescript-sort-keys
|
4 |
|
5 | Sort interface and string enum keys
|
6 |
|
7 | Inspired by and sourced from [eslint/sort-keys]([https://github.com/eslint/eslint/blob/master/docs/rules/sort-keys.md](https://github.com/eslint/eslint/blob/main/docs/src/rules/sort-keys.md))
|
8 |
|
9 | ## Installation
|
10 |
|
11 | You'll first need to install
|
12 |
|
13 | - [eslint](http://eslint.org)
|
14 | - [typescript](http://www.typescriptlang.org/)
|
15 | - [@typescript-eslint/parser](https://github.com/typescript-eslint/typescript-eslint/tree/master/packages/parser)
|
16 |
|
17 | ```sh
|
18 | yarn add -D eslint typescript @typescript-eslint/parser
|
19 | ```
|
20 |
|
21 | Next, install `eslint-plugin-typescript-sort-keys`:
|
22 |
|
23 | ```sh
|
24 | yarn add -D eslint-plugin-typescript-sort-keys
|
25 | ```
|
26 |
|
27 | **Note:** If you installed ESLint globally then you must also install `eslint-plugin-typescript-sort-keys` globally.
|
28 |
|
29 | ## Usage
|
30 |
|
31 | Specify the parser for typescript files in your `.eslintrc` configuration file:
|
32 |
|
33 | ```json
|
34 | {
|
35 | "parser": "@typescript-eslint/parser"
|
36 | }
|
37 | ```
|
38 |
|
39 | Add `typescript-sort-keys` to the plugins section. You can omit the `eslint-plugin-` prefix:
|
40 |
|
41 | ```json
|
42 | {
|
43 | "plugins": ["typescript-sort-keys"]
|
44 | }
|
45 | ```
|
46 |
|
47 | Then configure the rules you want to use under the rules section.
|
48 |
|
49 | ```json
|
50 | {
|
51 | "rules": {
|
52 | "typescript-sort-keys/interface": "error",
|
53 | "typescript-sort-keys/string-enum": "error"
|
54 | }
|
55 | }
|
56 | ```
|
57 |
|
58 | Or enable all rules with defaults
|
59 |
|
60 | ```json
|
61 | {
|
62 | "extends": ["plugin:typescript-sort-keys/recommended"]
|
63 | }
|
64 | ```
|
65 |
|
66 | ## Supported Rules
|
67 |
|
68 |
|
69 |
|
70 | **Key**: :heavy_check_mark: = recommended, :wrench: = fixable
|
71 |
|
72 |
|
73 | | Name | Description | :heavy_check_mark: | :wrench: |
|
74 | | ---- | ----------- | ------------------ | -------- |
|
75 | | [`typescript-sort-keys/interface`](./docs/rules/interface.md) | require interface keys to be sorted | :heavy_check_mark: | :wrench: |
|
76 | | [`typescript-sort-keys/string-enum`](./docs/rules/string-enum.md) | require string enum members to be sorted | :heavy_check_mark: | :wrench: |
|
77 |
|
78 |
|