Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix: invalid operator in operator-assignment messages (#15759)
  • Loading branch information
mdjermanovic committed Apr 6, 2022
1 parent 7a305c1 commit 97b57ae
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 77 deletions.
12 changes: 7 additions & 5 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,11 +109,13 @@ 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 },
data: { operator: replacementOperator },
fix(fixer) {
if (canBeFixed(left) && canBeFixed(expr.left)) {
const equalsToken = getOperatorToken(node);
Expand All @@ -126,7 +128,7 @@ module.exports = {
return null;
}

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

0 comments on commit 97b57ae

Please sign in to comment.