=+, =- or =! is written where +=, -= or != was likely meant

tx0/java:swapped-assign-operatordefaultwarningbug

What it finds

x =+ 1: an assignment whose sign is written against the = and apart from its operand reads like x += 1, but assigns +1. The same holds for =- and -=, and for =!, which assigns a negation where != was meant.

Only that spacing is reported: x = -1 and x =-1 say what they do.

From the rule's source, swapped_assign_operator.rs.

Example from the rule's tests
class Signs {  int f(int n, boolean ok) {    n =+ 1;tx0 reports: =+ assigns +1; += may have been meant    n =- 2;tx0 reports: =- assigns -2; -= may have been meant    ok =! ok;tx0 reports: =! assigns !ok; != may have been meant    n = -1;    n = +1;    n =-1;    n += 1;    ok = !ok;    int m =- 1;    return n + m;  }}
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/java:swapped-assign-operator" = "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/java:swapped-assign-operator] reason="..."

tx0 explain tx0/java:swapped-assign-operator shows the same in the terminal. Found a false positive? Report it.