Skip to content

Commit

Permalink
[Refactor] cleanup no-mixed-operators warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
RedTn authored and ljharb committed Sep 28, 2020
1 parent 71a0e8f commit f84dc8b
Show file tree
Hide file tree
Showing 17 changed files with 28 additions and 29 deletions.
1 change: 0 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
"function-paren-newline": 0,
"no-plusplus": 1,
"no-param-reassign": 1,
"no-mixed-operators": 1,
"no-restricted-syntax": [2, {
"selector": "ObjectPattern",
"message": "Object destructuring is not compatible with Node v4"
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/destructuring-assignment.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ module.exports = {

create: Components.detect((context, components, utils) => {
const configuration = context.options[0] || DEFAULT_OPTION;
const ignoreClassFields = context.options[1] && context.options[1].ignoreClassFields === true || false;
const ignoreClassFields = (context.options[1] && (context.options[1].ignoreClassFields === true)) || false;

/**
* @param {ASTNode} node We expect either an ArrowFunctionExpression,
Expand Down
4 changes: 2 additions & 2 deletions lib/rules/forbid-foreign-prop-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,14 @@ module.exports = {
return {
MemberExpression(node) {
if (
node.property
(node.property
&& (
!node.computed
&& node.property.type === 'Identifier'
&& node.property.name === 'propTypes'
&& !ast.isAssignmentLHS(node)
&& !isAllowedAssignment(node)
) || (
)) || (
(node.property.type === 'Literal' || node.property.type === 'JSXText')
&& node.property.value === 'propTypes'
&& !ast.isAssignmentLHS(node)
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/jsx-indent.js
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ module.exports = {
return;
}
// Use the parent in a list or an array
if (prevToken.type === 'JSXText' || prevToken.type === 'Punctuator' && prevToken.value === ',') {
if (prevToken.type === 'JSXText' || ((prevToken.type === 'Punctuator') && prevToken.value === ',')) {
prevToken = sourceCode.getNodeByRangeIndex(prevToken.range[0]);
prevToken = prevToken.type === 'Literal' || prevToken.type === 'JSXText' ? prevToken.parent : prevToken;
// Use the first non-punctuator token in a conditional expression
Expand Down
10 changes: 5 additions & 5 deletions lib/rules/jsx-max-depth.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ module.exports = {
}

function hasJSX(node) {
return jsxUtil.isJSX(node) || isExpression(node) && jsxUtil.isJSX(node.expression);
return jsxUtil.isJSX(node) || (isExpression(node) && jsxUtil.isJSX(node.expression));
}

function isLeaf(node) {
Expand Down Expand Up @@ -87,10 +87,10 @@ module.exports = {
if (has(refs[i], 'writeExpr')) {
const writeExpr = refs[i].writeExpr;

return jsxUtil.isJSX(writeExpr)
&& writeExpr
|| (writeExpr && writeExpr.type === 'Identifier')
&& findJSXElementOrFragment(variables, writeExpr.name);
return (jsxUtil.isJSX(writeExpr)
&& writeExpr)
|| ((writeExpr && writeExpr.type === 'Identifier')
&& findJSXElementOrFragment(variables, writeExpr.name));
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/rules/jsx-one-expression-per-line.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ module.exports = {
) {
if (
options.allow === 'single-child'
|| options.allow === 'literal' && (child.type === 'Literal' || child.type === 'JSXText')
|| (options.allow === 'literal' && (child.type === 'Literal' || child.type === 'JSXText'))
) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-set-state.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ module.exports = {
return;
}
const component = components.get(utils.getParentComponent());
const setStateUsages = component && component.setStateUsages || [];
const setStateUsages = (component && component.setStateUsages) || [];
setStateUsages.push(callee);
components.set(node, {
useSetState: true,
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-this-in-sfc.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ module.exports = {
MemberExpression(node) {
if (node.object.type === 'ThisExpression') {
const component = components.get(utils.getParentStatelessComponent());
if (!component || component.node && component.node.parent && component.node.parent.type === 'Property') {
if (!component || (component.node && component.node.parent && component.node.parent.type === 'Property')) {
return;
}
context.report({
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-unknown-property.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ module.exports = {

create(context) {
function getIgnoreConfig() {
return context.options[0] && context.options[0].ignore || DEFAULTS.ignore;
return (context.options[0] && context.options[0].ignore) || DEFAULTS.ignore;
}

return {
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-unused-state.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ module.exports = {
if (
parent
&& parent.type === 'MethodDefinition' && (
parent.static && parent.key.name === 'getDerivedStateFromProps'
(parent.static && parent.key.name === 'getDerivedStateFromProps')
|| classMethods.indexOf(parent.key.name) !== -1
)
&& parent.value.type === 'FunctionExpression'
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/prefer-read-only-props.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function isFlowPropertyType(node) {
}

function isCovariant(node) {
return node.variance && node.variance.kind === 'plus' || node.parent.parent.parent.id && node.parent.parent.parent.id.name === '$ReadOnly';
return (node.variance && (node.variance.kind === 'plus')) || (node.parent.parent.parent.id && (node.parent.parent.parent.id.name === '$ReadOnly'));
}

// ------------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/prefer-stateless-function.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ module.exports = {
return properties.some((property) => {
const name = astUtil.getPropertyName(property);
const isDisplayName = name === 'displayName';
const isPropTypes = name === 'propTypes' || name === 'props' && property.typeAnnotation;
const isPropTypes = name === 'propTypes' || ((name === 'props') && property.typeAnnotation);
const contextTypes = name === 'contextTypes';
const defaultProps = name === 'defaultProps';
const isUselessConstructor = property.kind === 'constructor'
Expand Down
4 changes: 2 additions & 2 deletions lib/rules/self-closing-comp.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ module.exports = {
function isShouldBeSelfClosed(node) {
const configuration = Object.assign({}, optionDefaults, context.options[0]);
return (
configuration.component && isComponent(node)
|| configuration.html && jsxUtil.isDOMComponent(node)
(configuration.component && isComponent(node))
|| (configuration.html && jsxUtil.isDOMComponent(node))
) && !node.selfClosing && (childrenIsEmpty(node) || childrenIsMultilineSpaces(node));
}

Expand Down
4 changes: 2 additions & 2 deletions lib/rules/sort-comp.js
Original file line number Diff line number Diff line change
Expand Up @@ -354,9 +354,9 @@ module.exports = {
// Comparing the same properties
refIndexA === refIndexB
// 1st property is placed before the 2nd one in reference and in current component
|| refIndexA < refIndexB && classIndexA < classIndexB
|| ((refIndexA < refIndexB) && (classIndexA < classIndexB))
// 1st property is placed after the 2nd one in reference and in current component
|| refIndexA > refIndexB && classIndexA > classIndexB
|| ((refIndexA > refIndexB) && (classIndexA > classIndexB))
) {
return {
correct: true,
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/style-prop-object.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ module.exports = {
},

create(context) {
const allowed = new Set(context.options.length > 0 && context.options[0].allow || []);
const allowed = new Set(((context.options.length > 0) && context.options[0].allow) || []);

/**
* @param {ASTNode} expression An Identifier node
Expand Down
8 changes: 4 additions & 4 deletions lib/util/propTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -749,8 +749,8 @@ module.exports = function propTypesInstructions(context, components, utils) {
componentNode = componentNode.parent;
}
const component = components.get(componentNode);
let declaredPropTypes = component && component.declaredPropTypes || {};
let ignorePropsValidation = component && component.ignorePropsValidation || false;
let declaredPropTypes = (component && component.declaredPropTypes) || {};
let ignorePropsValidation = (component && component.ignorePropsValidation) || false;
switch (propTypes && propTypes.type) {
case 'ObjectTypeAnnotation':
ignorePropsValidation = declarePropTypesForObjectTypeAnnotation(propTypes, declaredPropTypes);
Expand Down Expand Up @@ -810,8 +810,8 @@ module.exports = function propTypesInstructions(context, components, utils) {
let isUsedInPropTypes = false;
let n = propTypes;
while (n) {
if (n.type === 'AssignmentExpression' && propsUtil.isPropTypesDeclaration(n.left)
|| (n.type === 'ClassProperty' || n.type === 'Property') && propsUtil.isPropTypesDeclaration(n)) {
if (((n.type === 'AssignmentExpression') && propsUtil.isPropTypesDeclaration(n.left))
|| ((n.type === 'ClassProperty' || n.type === 'Property') && propsUtil.isPropTypesDeclaration(n))) {
// Found a propType used inside of another propType. This is not considered usage, we'll still validate
// this component.
isUsedInPropTypes = true;
Expand Down
6 changes: 3 additions & 3 deletions lib/util/usedPropTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -356,8 +356,8 @@ module.exports = function usedPropTypesInstructions(context, components, utils)
}

const component = components.get(utils.getParentComponent());
const usedPropTypes = component && component.usedPropTypes || [];
let ignoreUnusedPropTypesValidation = component && component.ignoreUnusedPropTypesValidation || false;
const usedPropTypes = (component && component.usedPropTypes) || [];
let ignoreUnusedPropTypesValidation = (component && component.ignoreUnusedPropTypesValidation) || false;

switch (type) {
case 'direct': {
Expand Down Expand Up @@ -419,7 +419,7 @@ module.exports = function usedPropTypesInstructions(context, components, utils)

const destructuring = param && (
param.type === 'ObjectPattern'
|| param.type === 'AssignmentPattern' && param.left.type === 'ObjectPattern'
|| ((param.type === 'AssignmentPattern') && (param.left.type === 'ObjectPattern'))
);

if (destructuring && (components.get(node) || components.get(node.parent))) {
Expand Down

0 comments on commit f84dc8b

Please sign in to comment.