Skip to content

Commit

Permalink
Fix: operator-assignment with parenthesized expression (fixes #8190) (
Browse files Browse the repository at this point in the history
  • Loading branch information
alberto authored and not-an-aardvark committed Mar 6, 2017
1 parent 5e3bca7 commit 41e3d9c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rules/operator-assignment.js
Expand Up @@ -135,7 +135,7 @@ module.exports = {
const equalsToken = getOperatorToken(node);
const operatorToken = getOperatorToken(expr);
const leftText = sourceCode.getText().slice(node.range[0], equalsToken.range[0]);
const rightText = sourceCode.getText().slice(operatorToken.range[1], node.range[1]);
const rightText = sourceCode.getText().slice(operatorToken.range[1], expr.right.range[1]);

return fixer.replaceText(node, `${leftText}${expr.operator}=${rightText}`);
}
Expand Down
5 changes: 5 additions & 0 deletions tests/lib/rules/operator-assignment.js
Expand Up @@ -149,6 +149,11 @@ ruleTester.run("operator-assignment", rule, {
output: "x += y",
options: ["always"],
errors: EXPECTED_OPERATOR_ASSIGNMENT
}, {
code: "x = (x + y)",
output: "x += y",
options: ["always"],
errors: EXPECTED_OPERATOR_ASSIGNMENT
}, {
code: "x += y",
output: "x = x + y",
Expand Down

0 comments on commit 41e3d9c

Please sign in to comment.