An assignment is written =+, =- or =! where a compound operator was likely meant
What it finds
x =+ 1 reads like x += 1 but assigns +1, and x =- 1 assigns -1 where x -= 1 was meant. In a condition, if (a =! b) assigns a negation where != was meant. Reported is that spacing only: the sign written against the = and apart from its operand. x = -1 and x =-1 say what they do. =! is reported only in a condition, as elsewhere, as in flag =! flag, it is a way to write a toggle, and != could not stand there. The fix for =+ and =- swaps the two characters; it changes what the code does, so it is a suggestion.
From the rule's source, reversed_assign_operator.rs.
class Counter{ int total; bool open; void Add(int n, bool closed) { total =+ n;tx0 reports: =+ assigns +n; += may have been meant total =- 1;tx0 reports: =- assigns -1; -= may have been meant if (open =! closed)tx0 reports: =! assigns !closed; != may have been meant { } total = -1; total =-1; total = +n; total += n; open = !closed; open =! closed; }} Turn it on, off or suppress it
The rule runs from the strict tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/csharp:reversed-assign-operator" = "warning"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/csharp:reversed-assign-operator] reason="..."tx0 explain tx0/csharp:reversed-assign-operator shows the same in the terminal. Found a false positive? Report it.