Skip to content

Commit 0b49ae7

Browse files
committed
[eslint] enable and auto + manually fix no-else-return
1 parent 0ed8e0d commit 0b49ae7

11 files changed

+36
-31
lines changed

.eslintrc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
"function-paren-newline": 0,
3434
"no-plusplus": 1,
3535
"no-param-reassign": 1,
36-
"no-else-return": 1,
3736
"object-curly-newline": 1,
3837
"object-property-newline": 1,
3938
"spaced-comment": 1,

lib/rules/jsx-no-bind.js

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -87,26 +87,19 @@ module.exports = {
8787
node.callee.property.name === 'bind'
8888
) {
8989
return 'bindCall';
90-
} else if (
91-
nodeType === 'ConditionalExpression'
92-
) {
90+
}
91+
if (nodeType === 'ConditionalExpression') {
9392
return getNodeViolationType(node.test) ||
9493
getNodeViolationType(node.consequent) ||
9594
getNodeViolationType(node.alternate);
96-
} else if (
97-
!configuration.allowArrowFunctions &&
98-
nodeType === 'ArrowFunctionExpression'
99-
) {
95+
}
96+
if (!configuration.allowArrowFunctions && nodeType === 'ArrowFunctionExpression') {
10097
return 'arrowFunc';
101-
} else if (
102-
!configuration.allowFunctions &&
103-
nodeType === 'FunctionExpression'
104-
) {
98+
}
99+
if (!configuration.allowFunctions && nodeType === 'FunctionExpression') {
105100
return 'func';
106-
} else if (
107-
!configuration.allowBind &&
108-
nodeType === 'BindExpression'
109-
) {
101+
}
102+
if (!configuration.allowBind && nodeType === 'BindExpression') {
110103
return 'bindExpression';
111104
}
112105

lib/rules/jsx-sort-default-props.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,13 @@ module.exports = {
4646
function getPropertyName(node) {
4747
if (node.key || ['MethodDefinition', 'Property'].indexOf(node.type) !== -1) {
4848
return node.key.name;
49-
} else if (node.type === 'MemberExpression') {
49+
}
50+
if (node.type === 'MemberExpression') {
5051
return node.property.name;
5152
// Special case for class properties
5253
// (babel-eslint@5 does not expose property name so we have to rely on tokens)
53-
} else if (node.type === 'ClassProperty') {
54+
}
55+
if (node.type === 'ClassProperty') {
5456
const tokens = context.getFirstTokens(node, 2);
5557
return tokens[1] && tokens[1].type === 'Identifier' ? tokens[1].value : tokens[0].value;
5658
}

lib/rules/jsx-sort-props.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ function contextCompare(a, b, options) {
3737
const bIsReserved = isReservedPropName(bProp, options.reservedList);
3838
if (aIsReserved && !bIsReserved) {
3939
return -1;
40-
} else if (!aIsReserved && bIsReserved) {
40+
}
41+
if (!aIsReserved && bIsReserved) {
4142
return 1;
4243
}
4344
}
@@ -47,7 +48,8 @@ function contextCompare(a, b, options) {
4748
const bIsCallback = isCallbackPropName(bProp);
4849
if (aIsCallback && !bIsCallback) {
4950
return 1;
50-
} else if (!aIsCallback && bIsCallback) {
51+
}
52+
if (!aIsCallback && bIsCallback) {
5153
return -1;
5254
}
5355
}
@@ -56,7 +58,8 @@ function contextCompare(a, b, options) {
5658
const shorthandSign = options.shorthandFirst ? -1 : 1;
5759
if (!a.value && b.value) {
5860
return shorthandSign;
59-
} else if (a.value && !b.value) {
61+
}
62+
if (a.value && !b.value) {
6063
return -shorthandSign;
6164
}
6265
}
@@ -178,7 +181,8 @@ function validateReservedFirstConfig(context, reservedFirst) {
178181
message: 'A customized reserved first list must not be empty'
179182
});
180183
};
181-
} else if (nonReservedWords.length > 0) {
184+
}
185+
if (nonReservedWords.length > 0) {
182186
return function (decl) {
183187
context.report({
184188
node: decl,

lib/rules/no-danger-with-children.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ module.exports = {
3838
return node.properties.find(prop => {
3939
if (prop.type === 'Property') {
4040
return prop.key.name === propName;
41-
} else if (prop.type === 'ExperimentalSpreadProperty' || prop.type === 'SpreadElement') {
41+
}
42+
if (prop.type === 'ExperimentalSpreadProperty' || prop.type === 'SpreadElement') {
4243
const variable = findSpreadVariable(prop.argument.name);
4344
if (variable && variable.defs.length && variable.defs[0].node.init) {
4445
if (seenProps.indexOf(prop.argument.name) > -1) {

lib/rules/no-redundant-should-component-update.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ module.exports = {
4949
function getNodeName(node) {
5050
if (node.id) {
5151
return node.id.name;
52-
} else if (node.parent && node.parent.id) {
52+
}
53+
if (node.parent && node.parent.id) {
5354
return node.parent.id.name;
5455
}
5556
return '';

lib/rules/no-unused-state.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,11 @@ function getName(node) {
3030

3131
if (type === 'Identifier') {
3232
return node.name;
33-
} else if (type === 'Literal') {
33+
}
34+
if (type === 'Literal') {
3435
return String(node.value);
35-
} else if (type === 'TemplateLiteral' && node.expressions.length === 0) {
36+
}
37+
if (type === 'TemplateLiteral' && node.expressions.length === 0) {
3638
return node.quasis[0].value.raw;
3739
}
3840
return null;

lib/rules/prefer-stateless-function.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,11 +306,11 @@ module.exports = {
306306
return;
307307
}
308308
markChildContextTypesAsDeclared(component.node);
309-
return;
310309
}
311310
return;
312311
// Ignore calls to `this.props` and `this.context`
313-
} else if (
312+
}
313+
if (
314314
(node.property.name || node.property.value) === 'props' ||
315315
(node.property.name || node.property.value) === 'context'
316316
) {

lib/util/Components.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ function usedPropTypesAreEquivalent(propA, propB) {
2424
if (propA.name === propB.name) {
2525
if (!propA.allNames && !propB.allNames) {
2626
return true;
27-
} else if (Array.isArray(propA.allNames) && Array.isArray(propB.allNames) && propA.allNames.join('') === propB.allNames.join('')) {
27+
}
28+
if (Array.isArray(propA.allNames) && Array.isArray(propB.allNames) && propA.allNames.join('') === propB.allNames.join('')) {
2829
return true;
2930
}
3031
return false;

lib/util/ast.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ function findReturnStatement(node) {
4444
function getPropertyNameNode(node) {
4545
if (node.key || ['MethodDefinition', 'Property'].indexOf(node.type) !== -1) {
4646
return node.key;
47-
} else if (node.type === 'MemberExpression') {
47+
}
48+
if (node.type === 'MemberExpression') {
4849
return node.property;
4950
}
5051
return null;

0 commit comments

Comments
 (0)