com.puppycrawl.tools.checkstyle.meta.checks.coding.MagicNumberCheck.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.coding.MagicNumberCheck" name="MagicNumber" parent="com.puppycrawl.tools.checkstyle.TreeWalker"> <description><p> Checks that there are no <a href="https://en.wikipedia.org/wiki/Magic_number_%28programming%29"> &quot;magic numbers&quot;</a> where a magic number is a numeric literal that is not defined as a constant. By default, -1, 0, 1, and 2 are not considered to be magic numbers. </p> <p>Constant definition is any variable/field that has 'final' modifier. It is fine to have one constant defining multiple numeric literals within one expression: </p> <pre> static final int SECONDS_PER_DAY = 24 * 60 * 60; static final double SPECIAL_RATIO = 4.0 / 3.0; static final double SPECIAL_SUM = 1 + Math.E; static final double SPECIAL_DIFFERENCE = 4 - Math.PI; static final Border STANDARD_BORDER = BorderFactory.createEmptyBorder(3, 3, 3, 3); static final Integer ANSWER_TO_THE_ULTIMATE_QUESTION_OF_LIFE = new Integer(42); </pre></description> <properties> <property default-value="-1, 0, 1, 2" name="ignoreNumbers" type="double[]"> <description>Specify non-magic numbers.</description> </property> <property default-value="false" name="ignoreHashCodeMethod" type="boolean"> <description>Ignore magic numbers in hashCode methods.</description> </property> <property default-value="false" name="ignoreAnnotation" type="boolean"> <description>Ignore magic numbers in annotation declarations.</description> </property> <property default-value="false" name="ignoreFieldDeclaration" type="boolean"> <description>Ignore magic numbers in field declarations.</description> </property> <property default-value="true" name="ignoreAnnotationElementDefaults" type="boolean"> <description>Ignore magic numbers in annotation elements defaults.</description> </property> <property default-value="TYPECAST,METHOD_CALL,EXPR,ARRAY_INIT,UNARY_MINUS,UNARY_PLUS,ELIST,STAR,ASSIGN,PLUS,MINUS,DIV,LITERAL_NEW" name="constantWaiverParentToken" type="java.lang.String[]" validation-type="tokenTypesSet"> <description>Specify tokens that are allowed in the AST path from the number literal to the enclosing constant definition.</description> </property> <property default-value="NUM_DOUBLE,NUM_FLOAT,NUM_INT,NUM_LONG" name="tokens" type="java.lang.String[]" validation-type="tokenSet"> <description>tokens to check</description> </property> </properties> <message-keys> <message-key key="magic.number"/> </message-keys> </check> </module> </checkstyle-metadata>