Skip to content

Commit

Permalink
Move the 'constructor' method to the lifecycle group
Browse files Browse the repository at this point in the history
  • Loading branch information
yannickcr committed Jun 26, 2015
1 parent b1e1f40 commit f2ebd33
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
12 changes: 4 additions & 8 deletions docs/rules/sort-comp.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ When creating React components it is more convenient to always follow the same o

With default configuration the following organisation must be followed:

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

The following patterns are considered warnings:

Expand Down Expand Up @@ -52,7 +51,6 @@ The default configuration is:
```js
{
order: [
'constructor',
'lifecycle',
'everything-else',
'render'
Expand All @@ -66,6 +64,7 @@ The default configuration is:
'mixins',
'statics',
'defaultProps',
'constructor',
'getDefaultProps',
'getInitialState',
'getChildContext',
Expand All @@ -81,7 +80,6 @@ The default configuration is:
}
```

* `constructor` is refering to the `constructor` method.
* `lifecycle` is refering to the `lifecycle` group defined in `groups`.
* `everything-else` is a special group that match all the methods that do not match any of the other groups.
* `render` is refering to the `render` method.
Expand All @@ -93,7 +91,6 @@ For example, if you want to place your event handlers (`onClick`, `onSubmit`, et
```js
"react/sort-comp": [1, {
order: [
'constructor',
'lifecycle',
'/^on.+$/',
'render',
Expand Down Expand Up @@ -129,7 +126,6 @@ If you want to split your `render` method into smaller ones and keep them just b
```js
"react/sort-comp": [1, {
order: [
'constructor',
'lifecycle',
'everything-else',
'rendering',
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/sort-comp.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ module.exports = function(context) {

var methodsOrder = getMethodsOrder({
order: [
'constructor',
'lifecycle',
'everything-else',
'render'
Expand All @@ -62,6 +61,7 @@ module.exports = function(context) {
'mixins',
'statics',
'defaultProps',
'constructor',
'getDefaultProps',
'getInitialState',
'getChildContext',
Expand Down

0 comments on commit f2ebd33

Please sign in to comment.