dotnet / roslyn-analyzers

MIT License
1.58k stars 464 forks source link

Do not flag `CA1508` inside `Debug.Assert()` #7327

Closed RenderMichael closed 3 months ago

RenderMichael commented 3 months ago

Analyzer

Diagnostic ID: CA1508

Describe the improvement

When writing assertions with Debug.Assert, it is expected that the result is always true. Even if the true value is "dead conditional code", ie. if the assertion results are known to be true. Debug.Assert is still useful to protect the assumptions in case of a refactoring.

Describe suggestions on how to achieve the rule

The return value of Debug.Assert does not get flagged by CA1508.

CollinAlpert commented 3 months ago

Already implemented in https://github.com/dotnet/roslyn-analyzers/pull/7014. Can you make sure you are using the newest version of the CodeAnalysis package?

RenderMichael commented 3 months ago

Chalk this up to not searching through recently-closed issues. Thanks.