A variable is assigned its own postfix increment or decrement, as in i = i++
What it finds
i = i++ reads i, increments it and then assigns the old value back, so i does not change. i++ alone, or i += 1, was meant. The same holds for return x++ on a local, whose increment is lost when the method returns.
From the rule's source, overwritten_increment.rs.
class Counter{ private int total; int Next(int i) { i = i++;tx0 reports: i = i++ assigns the old value back, so the variable does not change var local = i; total = total--;tx0 reports: total = total-- assigns the old value back, so the variable does not change return local++;tx0 reports: the increment in return local++ is lost } int Field() => total++;} 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:
[rules]
"tx0/csharp:overwritten-increment" = "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/csharp:overwritten-increment] reason="..."tx0 explain tx0/csharp:overwritten-increment shows the same in the terminal. Found a false positive? Report it.