From d657ea5bbe6313867b218e7ffe7685fb7ed27327 Mon Sep 17 00:00:00 2001 From: Yannick Croissant Date: Mon, 22 Jun 2015 23:04:00 +0000 Subject: [PATCH] Add ES6 methods to sort-comp default configuration (fixes #97, fixes #122) --- docs/rules/sort-comp.md | 12 +++++++++--- lib/rules/sort-comp.js | 2 ++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/docs/rules/sort-comp.md b/docs/rules/sort-comp.md index efceb80c99..69c54bc5ea 100644 --- a/docs/rules/sort-comp.md +++ b/docs/rules/sort-comp.md @@ -6,9 +6,10 @@ When creating React components it is more convenient to always follow the same o With default configuration the following organisation must be followed: - 1. lifecycle methods: `displayName`, `propTypes`, `contextTypes`, `childContextTypes`, `mixins`, `statics`, `getDefaultProps`, `getInitialState`, `getChildContext`, `componentWillMount`, `componentDidMount`, `componentWillReceiveProps`, `shouldComponentUpdate`, `componentWillUpdate`, `componentDidUpdate`, `componentWillUnmount` (in this order). - 2. custom methods - 3. `render` method + 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 The following patterns are considered warnings: @@ -51,6 +52,7 @@ The default configuration is: ```js { order: [ + 'constructor', 'lifecycle', 'everything-else', 'render' @@ -63,6 +65,7 @@ The default configuration is: 'childContextTypes', 'mixins', 'statics', + 'defaultProps', 'getDefaultProps', 'getInitialState', 'getChildContext', @@ -78,6 +81,7 @@ 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. @@ -89,6 +93,7 @@ For example, if you want to place your event handlers (`onClick`, `onSubmit`, et ```js "react/sort-comp": [1, { order: [ + 'constructor', 'lifecycle', '/^on.+$/', 'render', @@ -124,6 +129,7 @@ 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', diff --git a/lib/rules/sort-comp.js b/lib/rules/sort-comp.js index 111eeb0728..cfc520e4f1 100644 --- a/lib/rules/sort-comp.js +++ b/lib/rules/sort-comp.js @@ -48,6 +48,7 @@ module.exports = function(context) { var methodsOrder = getMethodsOrder({ order: [ + 'constructor', 'lifecycle', 'everything-else', 'render' @@ -60,6 +61,7 @@ module.exports = function(context) { 'childContextTypes', 'mixins', 'statics', + 'defaultProps', 'getDefaultProps', 'getInitialState', 'getChildContext',