Skip to content

Commit f2ebd33

Browse files
committed
Move the 'constructor' method to the lifecycle group
1 parent b1e1f40 commit f2ebd33

File tree

2 files changed

+5
-9
lines changed

2 files changed

+5
-9
lines changed

docs/rules/sort-comp.md

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@ 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. `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
9+
1. lifecycle methods: `displayName`, `propTypes`, `contextTypes`, `childContextTypes`, `mixins`, `statics`,`defaultProps`, `constructor`, `getDefaultProps`, `getInitialState`, `getChildContext`, `componentWillMount`, `componentDidMount`, `componentWillReceiveProps`, `shouldComponentUpdate`, `componentWillUpdate`, `componentDidUpdate`, `componentWillUnmount` (in this order).
10+
2. custom methods
11+
3. `render` method
1312

1413
The following patterns are considered warnings:
1514

@@ -52,7 +51,6 @@ The default configuration is:
5251
```js
5352
{
5453
order: [
55-
'constructor',
5654
'lifecycle',
5755
'everything-else',
5856
'render'
@@ -66,6 +64,7 @@ The default configuration is:
6664
'mixins',
6765
'statics',
6866
'defaultProps',
67+
'constructor',
6968
'getDefaultProps',
7069
'getInitialState',
7170
'getChildContext',
@@ -81,7 +80,6 @@ The default configuration is:
8180
}
8281
```
8382

84-
* `constructor` is refering to the `constructor` method.
8583
* `lifecycle` is refering to the `lifecycle` group defined in `groups`.
8684
* `everything-else` is a special group that match all the methods that do not match any of the other groups.
8785
* `render` is refering to the `render` method.
@@ -93,7 +91,6 @@ For example, if you want to place your event handlers (`onClick`, `onSubmit`, et
9391
```js
9492
"react/sort-comp": [1, {
9593
order: [
96-
'constructor',
9794
'lifecycle',
9895
'/^on.+$/',
9996
'render',
@@ -129,7 +126,6 @@ If you want to split your `render` method into smaller ones and keep them just b
129126
```js
130127
"react/sort-comp": [1, {
131128
order: [
132-
'constructor',
133129
'lifecycle',
134130
'everything-else',
135131
'rendering',

lib/rules/sort-comp.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ module.exports = function(context) {
4848

4949
var methodsOrder = getMethodsOrder({
5050
order: [
51-
'constructor',
5251
'lifecycle',
5352
'everything-else',
5453
'render'
@@ -62,6 +61,7 @@ module.exports = function(context) {
6261
'mixins',
6362
'statics',
6463
'defaultProps',
64+
'constructor',
6565
'getDefaultProps',
6666
'getInitialState',
6767
'getChildContext',

0 commit comments

Comments
 (0)