Skip to content

Commit

Permalink
Revert "fix: invalid operator in operator-assignment messages (eslint…
Browse files Browse the repository at this point in the history
…#15759)"

This reverts commit 1c9970a.
  • Loading branch information
srijan-deepsource committed May 30, 2022
1 parent f7e7880 commit 00e5858
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 76 deletions.
12 changes: 5 additions & 7 deletions lib/rules/operator-assignment.js
Expand Up @@ -76,8 +76,8 @@ module.exports = {

fixable: "code",
messages: {
replaced: "Assignment (=) can be replaced with operator assignment ({{operator}}).",
unexpected: "Unexpected operator assignment ({{operator}}) shorthand."
replaced: "Assignment (=) can be replaced with operator assignment ({{operator}}=).",
unexpected: "Unexpected operator assignment ({{operator}}=) shorthand."
}
},

Expand Down Expand Up @@ -109,13 +109,11 @@ module.exports = {
const operator = expr.operator;

if (isCommutativeOperatorWithShorthand(operator) || isNonCommutativeOperatorWithShorthand(operator)) {
const replacementOperator = `${operator}=`;

if (astUtils.isSameReference(left, expr.left, true)) {
context.report({
node,
messageId: "replaced",
data: { operator: replacementOperator },
data: { operator },
fix(fixer) {
if (canBeFixed(left) && canBeFixed(expr.left)) {
const equalsToken = getOperatorToken(node);
Expand All @@ -128,7 +126,7 @@ module.exports = {
return null;
}

return fixer.replaceText(node, `${leftText}${replacementOperator}${rightText}`);
return fixer.replaceText(node, `${leftText}${expr.operator}=${rightText}`);
}
return null;
}
Expand All @@ -143,7 +141,7 @@ module.exports = {
context.report({
node,
messageId: "replaced",
data: { operator: replacementOperator }
data: { operator }
});
}
}
Expand Down

0 comments on commit 00e5858

Please sign in to comment.