A variable is assigned to itself

tx0/ts:self-assignmentdefaultwarningbug

What it finds

x = x, and [a, b] = [a, b]: assigning a variable to itself does nothing, and usually stands for an assignment to something else, such as a property of the same name.

Only variables are checked. el.textContent = el.textContent can run a setter, which is sometimes the point, as in location.href = location.href. The logical assignments x ||= x, x &&= x and x ??= x are reported too, since they assign nothing new either. Names inside a with statement may be properties, and are left alone. An assignment that makes up a whole branch of an if statement, as in else x = x, says on purpose that the value stays.

From the rule's source, self_assignment.rs.

Example from the rule's tests
function update(value: number, items: number[], options: { size: number }) {  value = value;tx0 reports: value is assigned to itself  let [first, second] = items;  [first, second] = [first, items[1]];tx0 reports: first is assigned to itself  [first, second] = [second, first];  options.size = options.size;  value ||= value;tx0 reports: value is assigned to itself  value += value;  if (first > 0) {    value = value;  } else value = value;  return value + first + second;}
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

Turn it on, off or suppress it

The rule runs in every tier. To turn it off for a project, set its level in tx0.toml:

tx0.toml
[rules]
"tx0/ts:self-assignment" = "off"

To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:

// tx0: ignore[tx0/ts:self-assignment] reason="..."

tx0 explain tx0/ts:self-assignment shows the same in the terminal. Found a false positive? Report it.