Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Checkstyle - return count in switch statement

Is it possible to change ReturnCount check to increase value for switch statements only? In docs, I cannot see it, but I am ready for a dirty hack or something.

I have

    <module name="ReturnCount">
        <property name="max" value="3"/>
        <property name="maxForVoid" value="0"/>
        <property name="tokens" value="METHOD_DEF"/>
    </module>
    <module name="ReturnCount">
        <property name="max" value="1"/>
        <property name="maxForVoid" value="0"/>
        <property name="tokens" value="CTOR_DEF, LAMBDA"/>
    </module>

But for switch statements is it easier and cleaner for us to return multiple times (in most cases in each case statement) and this rule warns after 3.

like image 804
ByeBye Avatar asked Aug 29 '26 01:08

ByeBye


1 Answers

There is no existing option in ReturnCountCheck that will do what you want.

Since ReturnCountCheck supports xpath, you can use that to create an expression that will suppress the violations in the areas you wish to ignore. This would suppress the violation for the entire method and not limit the scope to just ignoring what is listed in the switches and violating on other parts of the same method. See http://checkstyle.sourceforge.net/config_filters.html#SuppressionXpathFilter

like image 111
rveach Avatar answered Aug 30 '26 14:08

rveach



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!