The result of IndexOf is tested with > 0, which misses a match at the first position
What it finds
IndexOf returns -1 when nothing is found and 0 when the match is at the start, so s.IndexOf(x) > 0 treats a match at the start as no match. >= 0, or Contains, tests for any match. Code that means "found, but not at the start" is a deliberate use and can be suppressed.
From the rule's source, index_of_above_zero.rs.
class Paths{ bool HasDot(string name) => name.IndexOf('.') > 0;tx0 reports: name.IndexOf('.') > 0 treats a match at position 0 as no match bool Found(string name) => name.IndexOf('.') >= 0;} Turn it on, off or suppress it
The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/csharp:index-of-above-zero" = "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:index-of-above-zero] reason="..."tx0 explain tx0/csharp:index-of-above-zero shows the same in the terminal. Found a false positive? Report it.