Skip to content

Commit d657ea5

Browse files
committed
Add ES6 methods to sort-comp default configuration (fixes #97, fixes #122)
1 parent f6292bb commit d657ea5

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

docs/rules/sort-comp.md

+9-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ When creating React components it is more convenient to always follow the same o
66

77
With default configuration the following organisation must be followed:
88

9-
1. lifecycle methods: `displayName`, `propTypes`, `contextTypes`, `childContextTypes`, `mixins`, `statics`, `getDefaultProps`, `getInitialState`, `getChildContext`, `componentWillMount`, `componentDidMount`, `componentWillReceiveProps`, `shouldComponentUpdate`, `componentWillUpdate`, `componentDidUpdate`, `componentWillUnmount` (in this order).
10-
2. custom methods
11-
3. `render` method
9+
1. `constructor` method
10+
2. lifecycle methods: `displayName`, `propTypes`, `contextTypes`, `childContextTypes`, `mixins`, `statics`,`defaultProps`, `getDefaultProps`, `getInitialState`, `getChildContext`, `componentWillMount`, `componentDidMount`, `componentWillReceiveProps`, `shouldComponentUpdate`, `componentWillUpdate`, `componentDidUpdate`, `componentWillUnmount` (in this order).
11+
3. custom methods
12+
4. `render` method
1213

1314
The following patterns are considered warnings:
1415

@@ -51,6 +52,7 @@ The default configuration is:
5152
```js
5253
{
5354
order: [
55+
'constructor',
5456
'lifecycle',
5557
'everything-else',
5658
'render'
@@ -63,6 +65,7 @@ The default configuration is:
6365
'childContextTypes',
6466
'mixins',
6567
'statics',
68+
'defaultProps',
6669
'getDefaultProps',
6770
'getInitialState',
6871
'getChildContext',
@@ -78,6 +81,7 @@ The default configuration is:
7881
}
7982
```
8083

84+
* `constructor` is refering to the `constructor` method.
8185
* `lifecycle` is refering to the `lifecycle` group defined in `groups`.
8286
* `everything-else` is a special group that match all the methods that do not match any of the other groups.
8387
* `render` is refering to the `render` method.
@@ -89,6 +93,7 @@ For example, if you want to place your event handlers (`onClick`, `onSubmit`, et
8993
```js
9094
"react/sort-comp": [1, {
9195
order: [
96+
'constructor',
9297
'lifecycle',
9398
'/^on.+$/',
9499
'render',
@@ -124,6 +129,7 @@ If you want to split your `render` method into smaller ones and keep them just b
124129
```js
125130
"react/sort-comp": [1, {
126131
order: [
132+
'constructor',
127133
'lifecycle',
128134
'everything-else',
129135
'rendering',

lib/rules/sort-comp.js

+2
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ module.exports = function(context) {
4848

4949
var methodsOrder = getMethodsOrder({
5050
order: [
51+
'constructor',
5152
'lifecycle',
5253
'everything-else',
5354
'render'
@@ -60,6 +61,7 @@ module.exports = function(context) {
6061
'childContextTypes',
6162
'mixins',
6263
'statics',
64+
'defaultProps',
6365
'getDefaultProps',
6466
'getInitialState',
6567
'getChildContext',

0 commit comments

Comments
 (0)