Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export defaultConfig from sort-comp rule for programmatic use #1578

Merged
merged 1 commit into from
Dec 1, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
};