Skip to content

Commit

Permalink
sort-comp #1858 PR amendments
Browse files Browse the repository at this point in the history
  • Loading branch information
nosilleg committed Jul 2, 2018
1 parent 0b0e462 commit 98ce807
Showing 1 changed file with 56 additions and 71 deletions.
127 changes: 56 additions & 71 deletions lib/rules/sort-comp.js
Expand Up @@ -134,86 +134,71 @@ module.exports = {
const methodGroupIndexes = [];

methodsOrder.forEach((currentGroup, groupIndex) => {
switch (currentGroup) {
case 'getters': {
if (method.getter) {
methodGroupIndexes.push(groupIndex);
}
break;
if (currentGroup === 'getters') {
if (method.getter) {
methodGroupIndexes.push(groupIndex);
}
case 'setters': {
if (method.setter) {
methodGroupIndexes.push(groupIndex);
}
break;
} else if (currentGroup === 'setters') {
if (method.setter) {
methodGroupIndexes.push(groupIndex);
}
case 'type-annotations': {
if (method.typeAnnotation) {
methodGroupIndexes.push(groupIndex);
}
break;
} else if (currentGroup === 'type-annotations') {
if (method.typeAnnotation) {
methodGroupIndexes.push(groupIndex);
}
case 'static-methods': {
if (method.static) {
methodGroupIndexes.push(groupIndex);
}
break;
} else if (currentGroup === 'static-methods') {
if (method.static) {
methodGroupIndexes.push(groupIndex);
}
case 'instance-variables': {
if (method.instanceVariable) {
methodGroupIndexes.push(groupIndex);
}
break;
} else if (currentGroup === 'instance-variables') {
if (method.instanceVariable) {
methodGroupIndexes.push(groupIndex);
}
case 'instance-methods': {
if (method.instanceMethod) {
methodGroupIndexes.push(groupIndex);
}
break;
} else if (currentGroup === 'instance-methods') {
if (method.instanceMethod) {
methodGroupIndexes.push(groupIndex);
}
case 'displayName':
case 'propTypes':
case 'contextTypes':
case 'childContextTypes':
case 'mixins':
case 'statics':
case 'defaultProps':
case 'constructor':
case 'getDefaultProps':
case 'state':
case 'getInitialState':
case 'getChildContext':
case 'getDerivedStateFromProps':
case 'componentWillMount':
case 'UNSAFE_componentWillMount':
case 'componentDidMount':
case 'componentWillReceiveProps':
case 'UNSAFE_componentWillReceiveProps':
case 'shouldComponentUpdate':
case 'componentWillUpdate':
case 'UNSAFE_componentWillUpdate':
case 'getSnapshotBeforeUpdate':
case 'componentDidUpdate':
case 'componentDidCatch':
case 'componentWillUnmount':
case 'render': {
if (currentGroup === method.name) {
methodGroupIndexes.push(groupIndex);
}
break;
} else if ([
'displayName',
'propTypes',
'contextTypes',
'childContextTypes',
'mixins',
'statics',
'defaultProps',
'constructor',
'getDefaultProps',
'state',
'getInitialState',
'getChildContext',
'getDerivedStateFromProps',
'componentWillMount',
'UNSAFE_componentWillMount',
'componentDidMount',
'componentWillReceiveProps',
'UNSAFE_componentWillReceiveProps',
'shouldComponentUpdate',
'componentWillUpdate',
'UNSAFE_componentWillUpdate',
'getSnapshotBeforeUpdate',
'componentDidUpdate',
'componentDidCatch',
'componentWillUnmount',
'render'
].includes(currentGroup)) {
if (currentGroup === method.name) {
methodGroupIndexes.push(groupIndex);
}
default: {
// Is the group a regex?
const isRegExp = currentGroup.match(regExpRegExp);
if (isRegExp) {
const isMatching = new RegExp(isRegExp[1], isRegExp[2]).test(method.name);
if (isMatching) {
methodGroupIndexes.push(groupIndex);
}
} else if (currentGroup === method.name) {
} else {
// Is the group a regex?
const isRegExp = currentGroup.match(regExpRegExp);
if (isRegExp) {
const isMatching = new RegExp(isRegExp[1], isRegExp[2]).test(method.name);
if (isMatching) {
methodGroupIndexes.push(groupIndex);
}
break;
} else if (currentGroup === method.name) {
methodGroupIndexes.push(groupIndex);
}
}
});
Expand Down

0 comments on commit 98ce807

Please sign in to comment.