Skip to content

Commit

Permalink
Update: ensure operator-assignment handles exponentiation operators (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
not-an-aardvark authored Jan 27, 2017
1 parent c5066ce commit fbd7c13
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/rules/operator-assignment.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function isCommutativeOperatorWithShorthand(operator) {
* a shorthand form.
*/
function isNonCommutativeOperatorWithShorthand(operator) {
return ["+", "-", "/", "%", "<<", ">>", ">>>"].indexOf(operator) >= 0;
return ["+", "-", "/", "%", "<<", ">>", ">>>", "**"].indexOf(operator) >= 0;
}

//------------------------------------------------------------------------------
Expand Down
17 changes: 16 additions & 1 deletion tests/lib/rules/operator-assignment.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const rule = require("../../../lib/rules/operator-assignment"),
// Tests
//------------------------------------------------------------------------------

const ruleTester = new RuleTester();
const ruleTester = new RuleTester({ parserOptions: { ecmaVersion: 7 } });

const EXPECTED_OPERATOR_ASSIGNMENT = [{ message: "Assignment can be replaced with operator assignment.", type: "AssignmentExpression" }];
const UNEXPECTED_OPERATOR_ASSIGNMENT = [{ message: "Unexpected operator assignment shorthand.", type: "AssignmentExpression" }];
Expand All @@ -40,6 +40,7 @@ ruleTester.run("operator-assignment", rule, {
"x >>= x >> y",
"x >>>= y",
"x &= y",
"x **= y",
"x ^= y ^ z",
"x |= x | y",
"x = x && y",
Expand All @@ -66,6 +67,11 @@ ruleTester.run("operator-assignment", rule, {
code: "x = x + y",
options: ["never"]
},
{
code: "x = x ** y",
options: ["never"]
},
"x = y ** x",
"x = x < y",
"x = x > y",
"x = x <= y",
Expand Down Expand Up @@ -184,6 +190,15 @@ ruleTester.run("operator-assignment", rule, {
output: "(foo.bar) = (foo.bar) ^ ((((((((((((((((baz))))))))))))))))",
options: ["never"],
errors: UNEXPECTED_OPERATOR_ASSIGNMENT
}, {
code: "foo = foo ** bar",
output: "foo **= bar",
errors: EXPECTED_OPERATOR_ASSIGNMENT
}, {
code: "foo **= bar",
output: "foo = foo ** bar",
options: ["never"],
errors: UNEXPECTED_OPERATOR_ASSIGNMENT
}]

});

0 comments on commit fbd7c13

Please sign in to comment.