Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update: operator-assignment should indicate which operator can be shortened #14764

Merged
merged 1 commit into from Jul 10, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 6 additions & 3 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.",
unexpected: "Unexpected operator assignment shorthand."
replaced: "Assignment (=) can be replaced with operator assignment ({{operator}}=).",
unexpected: "Unexpected operator assignment ({{operator}}=) shorthand."
}
},

Expand Down Expand Up @@ -113,6 +113,7 @@ module.exports = {
context.report({
node,
messageId: "replaced",
data: { operator },
fix(fixer) {
if (canBeFixed(left) && canBeFixed(expr.left)) {
const equalsToken = getOperatorToken(node);
Expand All @@ -139,7 +140,8 @@ module.exports = {
*/
context.report({
node,
messageId: "replaced"
messageId: "replaced",
data: { operator }
});
}
}
Expand All @@ -155,6 +157,7 @@ module.exports = {
context.report({
node,
messageId: "unexpected",
data: { operator: node.operator },
fix(fixer) {
if (canBeFixed(node.left)) {
const firstToken = sourceCode.getFirstToken(node);
Expand Down