From 98ce8071f64985633e6bbda35a3e756383ad1a42 Mon Sep 17 00:00:00 2001 From: Jason Ellison Date: Mon, 2 Jul 2018 08:59:21 +0100 Subject: [PATCH] sort-comp #1858 PR amendments --- lib/rules/sort-comp.js | 127 ++++++++++++++++++----------------------- 1 file changed, 56 insertions(+), 71 deletions(-) diff --git a/lib/rules/sort-comp.js b/lib/rules/sort-comp.js index 9d54749af2..8d98f4b476 100644 --- a/lib/rules/sort-comp.js +++ b/lib/rules/sort-comp.js @@ -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); } } });