-
Notifications
You must be signed in to change notification settings - Fork 231
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
Rule S2699: Detect custom method with specific attribute as assertion #3634
Comments
Hi @egil, Thank you for taking the time to report this. We had a short discussion and we'll introduce some kind of attribute to enable marking methods as assertions. |
Great, thanks. @andrei-epure-sonarsource / @pavel-mikula-sonarsource : |
@egil The proposal only checks the attribute name. It can be in any namespace of any assembly. |
The update was merged to master and will be released with next Analyzer for C# 8.14 to SonarCloud and to the next release of SonarQube 8.6 @egil You can get your codebase ready according to new S2699 specification. |
Thanks, ill add that to my todo list :) |
Hi @pavel-mikula-sonarsource, can I get you to give this PR a very quick look and see if I am doing it right: bUnit-dev/bUnit#229 |
Description
Rule 2699 should recognize domain specific assertion methods as assertion methods as well.
In my particular case, my Blazor testing library bUnit has a semantic HTML comparer exposed as the as the assertion method
MarkupMatches(...)
which is not recognized as a assertion method by SonarLint.A simple suggestion would be to add the word
MATCHES
to the assertion method list. But that is a quick-fix for this particular case, and will likely exclude other domain specific assertion methods in the future, so perhaps an attribute is a safer approach, for those that want to be compatible with SonarLint?Repro steps
Simple example from the documentation link above:
Expected behavior
MarkupMatches
to be recognized as an assertion methodActual behavior
MarkupMatches
is not recognized as an assertion method.Known workarounds
Create another extension method that uses one of the keywords that is recognized as assertion statements.
Related information
Discussed here: https://community.sonarsource.com/t/how-to-mark-custom-methods-as-assertion-methods-in-c/31437
Not sure about these, maybe @domn1995 can help out, since he reported the problem originally: bUnit-dev/bUnit#216
The text was updated successfully, but these errors were encountered: