`CA1874` should catch cases where Regex.Count() is compared to Zero
- Dominant language
- C#
- Stars
- 3.2k
- Forks
- 1.3k
- PR merge metrics
- PR metrics pending
Description
### Is your feature request related to a problem? Please describe.
ignoring GeneratedRegex, this code should raise CA1874, to replace the `...Count(...) == 0` with `! .. .IsMatch(...)`.
Simmilarly:
- `...Count(...) > 0` => `.IsMatch(...)`
- `...Count(...) != 0` => `.IsMatch(...)`
```cs
internal class Class1
{
public void Do()
{
if (new Regex("abc").Count("abc") == 0)
throw new InvalidOperationException();
}
}
```
### Describe the solution you'd like
the Analyzer(s) should be updated to include these zero-compare cases. Perhaps even if `CA1875` is not enabled
### Additional context
in our cases these snippets are only used once in that statement. they are not using MatchCollection/Count in any other way
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.