From f044bc2a269967a86f31dfe887c4efb92f734306 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Burzy=C5=84ski?= Date: Fri, 1 Dec 2017 14:02:11 +0100 Subject: [PATCH] Export defaultConfig from sort-comp rule for programmatic use --- lib/rules/sort-comp.js | 71 ++++++++++++++++++++++-------------------- 1 file changed, 37 insertions(+), 34 deletions(-) diff --git a/lib/rules/sort-comp.js b/lib/rules/sort-comp.js index 1afd10695b..171fb25010 100644 --- a/lib/rules/sort-comp.js +++ b/lib/rules/sort-comp.js @@ -10,13 +10,44 @@ const util = require('util'); const Components = require('../util/Components'); const astUtil = require('../util/ast'); +const defaultConfig = { + order: [ + 'static-methods', + 'lifecycle', + 'everything-else', + 'render' + ], + groups: { + lifecycle: [ + 'displayName', + 'propTypes', + 'contextTypes', + 'childContextTypes', + 'mixins', + 'statics', + 'defaultProps', + 'constructor', + 'getDefaultProps', + 'state', + 'getInitialState', + 'getChildContext', + 'componentWillMount', + 'componentDidMount', + 'componentWillReceiveProps', + 'shouldComponentUpdate', + 'componentWillUpdate', + 'componentDidUpdate', + 'componentWillUnmount' + ] + } +}; + /** * Get the methods order from the default config and the user config - * @param {Object} defaultConfig The default configuration. * @param {Object} userConfig The user configuration. * @returns {Array} Methods order */ -function getMethodsOrder(defaultConfig, userConfig) { +function getMethodsOrder(userConfig) { userConfig = userConfig || {}; const groups = util._extend(defaultConfig.groups, userConfig.groups); @@ -78,37 +109,7 @@ module.exports = { const MISPOSITION_MESSAGE = '{{propA}} should be placed {{position}} {{propB}}'; - const methodsOrder = getMethodsOrder({ - order: [ - 'static-methods', - 'lifecycle', - 'everything-else', - 'render' - ], - groups: { - lifecycle: [ - 'displayName', - 'propTypes', - 'contextTypes', - 'childContextTypes', - 'mixins', - 'statics', - 'defaultProps', - 'constructor', - 'getDefaultProps', - 'state', - 'getInitialState', - 'getChildContext', - 'componentWillMount', - 'componentDidMount', - 'componentWillReceiveProps', - 'shouldComponentUpdate', - 'componentWillUpdate', - 'componentDidUpdate', - 'componentWillUnmount' - ] - } - }, context.options[0]); + const methodsOrder = getMethodsOrder(context.options[0]); // -------------------------------------------------------------------------- // Public @@ -438,5 +439,7 @@ module.exports = { reportErrors(); } }; - }) + }), + + defaultConfig };