For AI agents: the complete documentation index is available at https://rslint.rs/llms.txt, the full documentation bundle is available at https://rslint.rs/llms-full.txt, and this page is available as Markdown at https://rslint.rs/rules/unicorn/no-misrefactored-assignment.md.
close

no-misrefactored-assignment

Unreleased

Configuration

rslint.config.ts
import { defineConfig, unicornPlugin } from '@rslint/core';

export default defineConfig([
  unicornPlugin.configs.recommended,
  {
    rules: {
      'unicorn/no-misrefactored-assignment': 'error',
    },
  },
]);

Rule Details

Disallow arithmetic or bitwise compound assignments that repeat the target in an immediate operand of the matching operator. The assignment a += a + b uses the previous value of a twice. This can happen when rewriting a = a + b as a compound assignment.

For +, *, &, |, and ^, the target can appear on either side of the binary expression. For other operators, the rule checks only the left operand. Logical assignments (&&=, ||=, and ??=) are ignored.

The rule reports these assignments.

a += a + b;
a *= b * a;

These assignments are allowed.

a += b;
a *= b;
a += b + c;
a += a - b;
a -= b - a;

Suggestions

Removing the duplicate changes runtime behavior, so the rule offers an editor suggestion. The suggestion preserves comments in the retained operand. If the edit would discard a comment, the rule reports the assignment without a suggestion.

Options

This rule has no options.

Differences from upstream

ESLint Unicorn reports counters["1"] += counters[(1).toString()] + delta because both expressions access the same property. Rslint leaves this assignment unreported. Rslint reports the assignment when the right-hand side uses counters[1] directly.

Original Documentation