Skip to content

Commit

Permalink
feat(eslint-plugin): sort members alphabetically
Browse files Browse the repository at this point in the history
  • Loading branch information
timkraut committed Sep 13, 2019
1 parent 649cd94 commit 75788eb
Show file tree
Hide file tree
Showing 5 changed files with 3,109 additions and 396 deletions.
15 changes: 10 additions & 5 deletions packages/eslint-plugin/docs/rules/member-ordering.md
Expand Up @@ -7,13 +7,17 @@ A consistent ordering of fields, methods and constructors can make interfaces, t
This rule aims to standardize the way class declarations, class expressions, interfaces and type literals are structured and ordered.

### Grouping and sorting member groups

It allows to group members by their type (e.g. `public-static-field`, `protected-static-field`, `private-static-field`, `public-instance-field`, ...) and enforce a certain order for these groups. By default, their order is the same inside `classes`, `classExpressions`, `interfaces` and `typeLiterals` (note: not all member types apply to `interfaces` and `typeLiterals`). It is possible to define the order for any of those individually or to change the default order for all of them by setting the `default` option.

### Sorting members

Besides grouping the members and sorting their groups, this rule also allows to sort the members themselves. You have 2 options: Sort all of them while ignoring their type or sort them inside of the member types (e.g. sort all fields in an interface alphabetically).

## Options

These options allow to specify how to group the members and sort their groups.

```ts
{
default?: Array<MemberType> | never
Expand All @@ -26,14 +30,15 @@ These options allow to specify how to group the members and sort their groups.
```

If you want to enforce an alphabetic order, you have to use this form

```ts
{
default?: { memberTypes?: Array<MemberType>, order?: 'alphabetically' } | never
classes?: { memberTypes?: Array<MemberType>, order?: 'alphabetically' } | never
classExpressions?: { memberTypes?: Array<MemberType>, order?: 'alphabetically' } | never
default?: Array<MemberType> | { memberTypes?: Array<MemberType>, order?: 'alphabetically' } | never
classes?: Array<MemberType> | { memberTypes?: Array<MemberType>, order?: 'alphabetically' } | never
classExpressions?: Array<MemberType> | { memberTypes?: Array<MemberType>, order?: 'alphabetically' } | never

interfaces?: { memberTypes?: Array<MemberType>, order?: 'alphabetically' } | never
typeLiterals?: { memberTypes?: Array<MemberType>, order?: 'alphabetically' } | never
interfaces?: ['field' | 'method' | 'constructor'] | { memberTypes?: Array<MemberType>, order?: 'alphabetically' } | never
typeLiterals?: ['field' | 'method' | 'constructor'] | { memberTypes?: Array<MemberType>, order?: 'alphabetically' } | never
}
```

Expand Down

0 comments on commit 75788eb

Please sign in to comment.