Skip to content

Commit

Permalink
feat(eslint-plugin): rewrite member-ordering docs
Browse files Browse the repository at this point in the history
  • Loading branch information
timkraut committed Mar 20, 2019
1 parent 6ffaa0b commit 00571e9
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions packages/eslint-plugin/docs/rules/member-ordering.md
@@ -1,16 +1,19 @@
# Require a consistent member declaration order (member-ordering)

A consistent ordering of fields, methods and constructors can make interfaces, type literals, classes and class
expressions easier to read, navigate and edit.
A consistent ordering of fields, methods and constructors can make interfaces, type literals, classes and class expressions easier to read, navigate and edit.

## Rule Details

This rule aims to standardize the way class declarations, class expressions, interfaces and type literals are structured.
This rule aims to standardize the way class declarations, class expressions, interfaces and type literals are structured and ordered.

It allows to group members by their type (e.g. `public-static-field`, `protected-static-field`, `private-static-field`, `public-instance-field`, ...). 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.
### 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.

## Options
### 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 @@ -22,6 +25,18 @@ It allows to group members by their type (e.g. `public-static-field`, `protected
}
```

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

interfaces?: { memberTypes?: Array<MemberType>, order?: 'alphabetically' } | never
typeLiterals?: { memberTypes?: Array<MemberType>, order?: 'alphabetically' } | never
}
```

See below for the possible definitions of `MemberType`.

### Member types (granular form)
Expand Down Expand Up @@ -160,6 +175,8 @@ The default configuration looks as follows:

Note: The default configuration contains member group types which contain other member types (see above). This is intentional to provide better error messages.

Note: By default, the members are not sorted. If you want to sort them alphabetically, you have to provide a custom configuration.

## Examples

### Custom `default` configuration
Expand Down

0 comments on commit 00571e9

Please sign in to comment.