A condition assigns a boolean with = where a comparison with == was likely meant
What it finds
if (done = true) compiles in C# because the assignment yields a bool: the condition stores true and is always true. The rule reports an if, while, do or for condition, or the condition of a conditional expression, that is an assignment of a boolean literal.
From the rule's source, bool_assigned_in_condition.rs.
class Flags{ bool done; void Run(bool ready, bool other) { if (done = true)tx0 reports: done = true assigns in a condition { } while (ready = false)tx0 reports: ready = false assigns in a condition { } if (ready = other) { } if (done == true) { } }} 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:bool-assigned-in-condition" = "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:bool-assigned-in-condition] reason="..."tx0 explain tx0/csharp:bool-assigned-in-condition shows the same in the terminal. Found a false positive? Report it.