lib/rules/operator-assignment.js
function prohibit(node) {
            if (node.operator !== "=") {
                context.report({
                    node,
                    messageId: "unexpected",
                    fix(fixer) {
                        if (canBeFixed(node.left)) {
                            const operatorToken = getOperatorToken(node);
                            const leftText = sourceCode.getText().slice(node.range[0], operatorToken.range[0]);
                            const newOperator = node.operator.slice(0, -1);
                            let rightText;

                            // If this change would modify precedence (e.g. `foo *= bar + 1` => `foo = foo * (bar + 1)`), parenthesize the right side.
                            if (
                                astUtils.getPrecedence(node.right) <= astUtils.getPrecedence({ type: "BinaryExpression", operator: newOperator }) &&
                                !astUtils.isParenthesised(sourceCode, node.right)
                            ) {
                                rightText = `${sourceCode.text.slice(operatorToken.range[1], node.right.range[0])}(${sourceCode.getText(node.right)})`;
                            } else {
                                rightText = sourceCode.text.slice(operatorToken.range[1], node.range[1]);
                            }

                            return fixer.replaceText(node, `${leftText}= ${leftText}${newOperator}${rightText}`);
                        }
                        return null;
                    }
                });
            }
        }
function prohibit(node) {
            if (node.operator !== "=") {
                context.report({
                    node,
                    messageId: "unexpected",
                    fix(fixer) {
                        if (canBeFixed(node.left)) {
                            const operatorToken = getOperatorToken(node);
                            const leftText = sourceCode.getText().slice(node.range[0], operatorToken.range[0]);
                            const newOperator = node.operator.slice(0, -1);
                            let rightText;

                            // If this change would modify precedence (e.g. `foo *= bar + 1` => `foo = foo * (bar + 1)`), parenthesize the right side.
                            if (
                                astUtils.getPrecedence(node.right) <= astUtils.getPrecedence({ type: "BinaryExpression", operator: newOperator }) &&
                                !astUtils.isParenthesised(sourceCode, node.right)
                            ) {
                                rightText = `${sourceCode.text.slice(operatorToken.range[1], node.right.range[0])}(${sourceCode.getText(node.right)})`;
                            } else {
                                rightText = sourceCode.text.slice(operatorToken.range[1], node.range[1]);
                            }

                            return fixer.replaceText(node, `${leftText}= ${leftText}${newOperator}${rightText}`);
                        }
                        return null;
                    }
                });
            }
        }
function prohibit ( node ) { if ( node . operator !== "=" ) { context . report ( { node , messageId : "unexpected" , fix ( fixer ) { if ( canBeFixed ( node . left ) ) { const operatorToken = getOperatorToken ( node ) ; const leftText = sourceCode . getText ( ) . slice ( node . range [ 0 ] , operatorToken . range [ 0 ] ) ; const newOperator = node . operator . slice ( 0 , - 1 ) ; let rightText ; // If this change would modify precedence (e.g. `foo *= bar + 1` => `foo = foo * (bar + 1)`), parenthesize the right side. if ( astUtils . getPrecedence ( node . right ) <= astUtils . getPrecedence ( { type : "BinaryExpression" , operator : newOperator } ) && ! astUtils . isParenthesised ( sourceCode , node . right ) ) { rightText = ` ${ sourceCode . text . slice ( operatorToken . range [ 1 ] , node . right . range [ 0 ] ) } ${ sourceCode . getText ( node . right ) } ` ; } else { rightText = sourceCode . text . slice ( operatorToken . range [ 1 ] , node . range [ 1 ] ) ; } return fixer . replaceText ( node , ` ${ leftText } ${ leftText } ${ newOperator } ${ rightText } ` ) ; } return null ; } } ) ; } }
Warns if an assignment expression uses operator assignment shorthand.
@param   {ASTNode} node An AssignmentExpression node.
@returns {void}
Warns if an assignment expression uses operator assignment shorthand .