com.puppycrawl.tools.checkstyle.meta.checks.metrics.CyclomaticComplexityCheck.xml Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of checkstyle Show documentation
Show all versions of checkstyle Show documentation
Checkstyle is a development tool to help programmers write Java code
that adheres to a coding standard
<?xml version="1.0" encoding="UTF-8"?> <checkstyle-metadata> <module> <check fully-qualified-name="com.puppycrawl.tools.checkstyle.checks.metrics.CyclomaticComplexityCheck" name="CyclomaticComplexity" parent="com.puppycrawl.tools.checkstyle.TreeWalker"> <description><p> Checks cyclomatic complexity against a specified limit. It is a measure of the minimum number of possible paths through the source and therefore the number of required tests, it is not a about quality of code! It is only applied to methods, c-tors, <a href="https://docs.oracle.com/javase/tutorial/java/javaOO/initial.html"> static initializers and instance initializers</a>. </p> <p> The complexity is equal to the number of decision points {@code + 1}. Decision points: {@code if}, {@code while}, {@code do}, {@code for}, {@code ?:}, {@code catch}, {@code switch}, {@code case} statements and operators {@code &amp;&amp;} and {@code ||} in the body of target. </p> <p> By pure theory level 1-4 is considered easy to test, 5-7 OK, 8-10 consider re-factoring to ease testing, and 11+ re-factor now as testing will be painful. </p> <p> When it comes to code quality measurement by this metric level 10 is very good level as a ultimate target (that is hard to archive). Do not be ashamed to have complexity level 15 or even higher, but keep it below 20 to catch really bad designed code automatically. </p> <p> Please use Suppression to avoid violations on cases that could not be split in few methods without damaging readability of code or encapsulation. </p></description> <properties> <property default-value="10" name="max" type="int"> <description>Specify the maximum threshold allowed.</description> </property> <property default-value="false" name="switchBlockAsSingleDecisionPoint" type="boolean"> <description>Control whether to treat the whole switch block as a single decision point.</description> </property> <property default-value="LITERAL_WHILE,LITERAL_DO,LITERAL_FOR,LITERAL_IF,LITERAL_SWITCH,LITERAL_CASE,LITERAL_CATCH,QUESTION,LAND,LOR" name="tokens" type="java.lang.String[]" validation-type="tokenSet"> <description>tokens to check</description> </property> </properties> <message-keys> <message-key key="cyclomaticComplexity"/> </message-keys> </check> </module> </checkstyle-metadata>