Support classic StringAssert in ConstActualValueUsage analyzer and code fix #453
+298
−13
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This adds support for
StringAssert
toConstActualValueUsageAnalyzer
andConstActualValueUsageCodeFix
.The analyzers already support "classic" assertions in many places, but only ones that are defined on
Assert
. I have an existing codebase that frequently usesStringAssert
and the other classic Assert classes, and I recently found a case where aStringAssert.Contains
call started failing incorrectly after a refactoring because the arguments were reversed. I have tested that this change correctly flags that case.This change is narrowly focused on
StringAssert
andConstActualValueUsage
; but if the general approach is acceptable, I can add more classic Asserts to more analyzers. I am probably going to do it anyway to use on my own code.Also, I noticed that the existing code fix only supports the classic assertions specifically related to equality; but I saw no reason not to support all of the asserts on
StringAssert
, as they all follow the same format.