ReSharper custom patterns: check for nonexistence

I'm pretty new to ReSharper in general, especially the custom patterns. While the functionality looks fairly robust, I'm not quite sure how I would write a custom pattern to match against certain missing things, such as an ELSE or DEFAULT, ie. I want a hint to appear when a switch has no default or an if/else if/else block has no else.

1 comment
Comment actions Permalink

What I ended up doing for the else case is having a $statement$ of max mulitplicity 0 right after the if, which implies a standalone if block. This works for both if and elseif, and does not collide with the case where you have two if blocks together (this could be a false negative for our match).

I still need help with the missing default, however. The problem with the switch is we can have any number of cases, any number of which may or may not contain a break (except for the last case). I can have a $statement$ at the end of the switch similar to the previous example where the max mulitiplicity is 0 which catches a missing default, but how do I do multiplicity for the cases?

0

Please sign in to leave a comment.