Skip to content

Commit

Permalink
[eslint] enable and auto + manually fix no-else-return
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed May 19, 2019
1 parent 0ed8e0d commit 0b49ae7
Show file tree
Hide file tree
Showing 11 changed files with 36 additions and 31 deletions.
1 change: 0 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
"function-paren-newline": 0,
"no-plusplus": 1,
"no-param-reassign": 1,
"no-else-return": 1,
"object-curly-newline": 1,
"object-property-newline": 1,
"spaced-comment": 1,
Expand Down
23 changes: 8 additions & 15 deletions lib/rules/jsx-no-bind.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,26 +87,19 @@ module.exports = {
node.callee.property.name === 'bind'
) {
return 'bindCall';
} else if (
nodeType === 'ConditionalExpression'
) {
}
if (nodeType === 'ConditionalExpression') {
return getNodeViolationType(node.test) ||
getNodeViolationType(node.consequent) ||
getNodeViolationType(node.alternate);
} else if (
!configuration.allowArrowFunctions &&
nodeType === 'ArrowFunctionExpression'
) {
}
if (!configuration.allowArrowFunctions && nodeType === 'ArrowFunctionExpression') {
return 'arrowFunc';
} else if (
!configuration.allowFunctions &&
nodeType === 'FunctionExpression'
) {
}
if (!configuration.allowFunctions && nodeType === 'FunctionExpression') {
return 'func';
} else if (
!configuration.allowBind &&
nodeType === 'BindExpression'
) {
}
if (!configuration.allowBind && nodeType === 'BindExpression') {
return 'bindExpression';
}

Expand Down
6 changes: 4 additions & 2 deletions lib/rules/jsx-sort-default-props.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,13 @@ module.exports = {
function getPropertyName(node) {
if (node.key || ['MethodDefinition', 'Property'].indexOf(node.type) !== -1) {
return node.key.name;
} else if (node.type === 'MemberExpression') {
}
if (node.type === 'MemberExpression') {
return node.property.name;
// Special case for class properties
// (babel-eslint@5 does not expose property name so we have to rely on tokens)
} else if (node.type === 'ClassProperty') {
}
if (node.type === 'ClassProperty') {
const tokens = context.getFirstTokens(node, 2);
return tokens[1] && tokens[1].type === 'Identifier' ? tokens[1].value : tokens[0].value;
}
Expand Down
12 changes: 8 additions & 4 deletions lib/rules/jsx-sort-props.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ function contextCompare(a, b, options) {
const bIsReserved = isReservedPropName(bProp, options.reservedList);
if (aIsReserved && !bIsReserved) {
return -1;
} else if (!aIsReserved && bIsReserved) {
}
if (!aIsReserved && bIsReserved) {
return 1;
}
}
Expand All @@ -47,7 +48,8 @@ function contextCompare(a, b, options) {
const bIsCallback = isCallbackPropName(bProp);
if (aIsCallback && !bIsCallback) {
return 1;
} else if (!aIsCallback && bIsCallback) {
}
if (!aIsCallback && bIsCallback) {
return -1;
}
}
Expand All @@ -56,7 +58,8 @@ function contextCompare(a, b, options) {
const shorthandSign = options.shorthandFirst ? -1 : 1;
if (!a.value && b.value) {
return shorthandSign;
} else if (a.value && !b.value) {
}
if (a.value && !b.value) {
return -shorthandSign;
}
}
Expand Down Expand Up @@ -178,7 +181,8 @@ function validateReservedFirstConfig(context, reservedFirst) {
message: 'A customized reserved first list must not be empty'
});
};
} else if (nonReservedWords.length > 0) {
}
if (nonReservedWords.length > 0) {
return function (decl) {
context.report({
node: decl,
Expand Down
3 changes: 2 additions & 1 deletion lib/rules/no-danger-with-children.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ module.exports = {
return node.properties.find(prop => {
if (prop.type === 'Property') {
return prop.key.name === propName;
} else if (prop.type === 'ExperimentalSpreadProperty' || prop.type === 'SpreadElement') {
}
if (prop.type === 'ExperimentalSpreadProperty' || prop.type === 'SpreadElement') {
const variable = findSpreadVariable(prop.argument.name);
if (variable && variable.defs.length && variable.defs[0].node.init) {
if (seenProps.indexOf(prop.argument.name) > -1) {
Expand Down
3 changes: 2 additions & 1 deletion lib/rules/no-redundant-should-component-update.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ module.exports = {
function getNodeName(node) {
if (node.id) {
return node.id.name;
} else if (node.parent && node.parent.id) {
}
if (node.parent && node.parent.id) {
return node.parent.id.name;
}
return '';
Expand Down
6 changes: 4 additions & 2 deletions lib/rules/no-unused-state.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@ function getName(node) {

if (type === 'Identifier') {
return node.name;
} else if (type === 'Literal') {
}
if (type === 'Literal') {
return String(node.value);
} else if (type === 'TemplateLiteral' && node.expressions.length === 0) {
}
if (type === 'TemplateLiteral' && node.expressions.length === 0) {
return node.quasis[0].value.raw;
}
return null;
Expand Down
4 changes: 2 additions & 2 deletions lib/rules/prefer-stateless-function.js
Original file line number Diff line number Diff line change
Expand Up @@ -306,11 +306,11 @@ module.exports = {
return;
}
markChildContextTypesAsDeclared(component.node);
return;
}
return;
// Ignore calls to `this.props` and `this.context`
} else if (
}
if (
(node.property.name || node.property.value) === 'props' ||
(node.property.name || node.property.value) === 'context'
) {
Expand Down
3 changes: 2 additions & 1 deletion lib/util/Components.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ function usedPropTypesAreEquivalent(propA, propB) {
if (propA.name === propB.name) {
if (!propA.allNames && !propB.allNames) {
return true;
} else if (Array.isArray(propA.allNames) && Array.isArray(propB.allNames) && propA.allNames.join('') === propB.allNames.join('')) {
}
if (Array.isArray(propA.allNames) && Array.isArray(propB.allNames) && propA.allNames.join('') === propB.allNames.join('')) {
return true;
}
return false;
Expand Down
3 changes: 2 additions & 1 deletion lib/util/ast.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ function findReturnStatement(node) {
function getPropertyNameNode(node) {
if (node.key || ['MethodDefinition', 'Property'].indexOf(node.type) !== -1) {
return node.key;
} else if (node.type === 'MemberExpression') {
}
if (node.type === 'MemberExpression') {
return node.property;
}
return null;
Expand Down
3 changes: 2 additions & 1 deletion lib/util/propTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,8 @@ module.exports = function propTypesInstructions(context, components, utils) {

if (!typeNode) {
return true;
} else if (typeNode.type === 'IntersectionTypeAnnotation') {
}
if (typeNode.type === 'IntersectionTypeAnnotation') {
return declarePropTypesForIntersectionTypeAnnotation(typeNode, declaredPropTypes);
}

Expand Down

0 comments on commit 0b49ae7

Please sign in to comment.