A comparison is negated with !, where the opposite operator says it directly
What it finds
!(a == b) is a != b, and !(a < b) is a >= b for integers and strings. The direct form is shorter and easier to read. Comparisons of floating-point values are left alone, since !(a < b) is also true when either is NaN.
From the rule's source, negated_comparison.rs.
class Compare{ bool Differ(int a, int b) => !(a == b);tx0 reports: !(a == b) can use != instead of negating bool NotLess(int a, int b) => !(a < b);tx0 reports: !(a < b) can use >= instead of negating bool Float(double a, double b) => !(a < b);} Turn it on, off or suppress it
The rule runs from the all tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/csharp:negated-comparison" = "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:negated-comparison] reason="..."tx0 explain tx0/csharp:negated-comparison shows the same in the terminal. Found a false positive? Report it.