The result of CompareTo or Compare is tested for being exactly 1 or -1

tx0/csharp:compare-to-signdefaultwarningreliability/equalitydepth fastbug

What it finds

Comparison methods promise only the sign of their result: string.Compare and many CompareTo implementations return other negative and positive numbers. x.CompareTo(y) == 1 is then false for a greater x. Compare with zero instead.

From the rule's source, compare_to_sign.rs.

Example from the rule's tests
class Sort{    bool Greater(string a, string b, int x, int y)    {        if (string.Compare(a, b) == 1)tx0 reports: the result of a comparison is tested for being exactly 1        {            return true;        }        return x.CompareTo(y) == -1 || a.CompareTo(b) > 0;tx0 reports: the result of a comparison is tested for being exactly -1    }}
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/csharp:compare-to-sign" = "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:compare-to-sign] reason="..."

tx0 explain tx0/csharp:compare-to-sign shows the same in the terminal. Found a false positive? Report it.