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

tx0/go: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. Formatted code never has it, so a finding is either a slip or code that was never formatted.

From the rule's source, swapped_assign_operator.rs.

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

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