Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support classic StringAssert in ConstActualValueUsage analyzer and code fix #453

Merged
merged 4 commits into from
May 12, 2022

Conversation

eatdrinksleepcode
Copy link

This adds support for StringAssert to ConstActualValueUsageAnalyzer and ConstActualValueUsageCodeFix.

The analyzers already support "classic" assertions in many places, but only ones that are defined on Assert. I have an existing codebase that frequently uses StringAssert and the other classic Assert classes, and I recently found a case where a StringAssert.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 and ConstActualValueUsage; 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.

Copy link
Member

@manfred-brands manfred-brands left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @eatdrinksleepcode for your contribution.
Your additions are neat and clean.
I added one remark about the use of the 'includeClassic' field.

@eatdrinksleepcode eatdrinksleepcode force-pushed the support-string-assert branch 2 times, most recently from 70f38bc to 89bec5f Compare May 7, 2022 14:45
@eatdrinksleepcode eatdrinksleepcode force-pushed the support-string-assert branch from 89bec5f to f32db4d Compare May 7, 2022 17:36
Copy link
Member

@manfred-brands manfred-brands left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, looks good to me.

Copy link
Member

@mikkelbu mikkelbu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Look good to me. Thanks for the contribution @eatdrinksleepcode and thanks for the review @manfred-brands 👍 . I'll just add one minor correction and then merge the PR

@mikkelbu mikkelbu merged commit 195337e into nunit:master May 12, 2022
@mikkelbu mikkelbu added this to the Release 3.4 / 2.4 milestone May 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants