Skip to content

Commit

Permalink
Merge pull request #1578 from Andarist/sort-comp/export-default-config
Browse files Browse the repository at this point in the history
Export defaultConfig from sort-comp rule for programmatic use
  • Loading branch information
ljharb authored Dec 1, 2017
2 parents cfd1c34 + f044bc2 commit 6f444a7
Showing 1 changed file with 37 additions and 34 deletions.
71 changes: 37 additions & 34 deletions lib/rules/sort-comp.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -438,5 +439,7 @@ module.exports = {
reportErrors();
}
};
})
}),

defaultConfig
};

0 comments on commit 6f444a7

Please sign in to comment.