I have read check documentation: https://checkstyle.org/checks/coding/magicnumber.html
I have downloaded the latest cli from: https://checkstyle.org/cmdline.html#Download_and_Run
I have executed the cli and showed it below, as cli describes the problem better than 1,000 words
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
"-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
"https://checkstyle.org/dtds/configuration_1_3.dtd">
<module name="Checker">
<property name="severity" value="error"/>
<property name="fileExtensions" value="java, properties, xml"/>
<module name="TreeWalker">
<module name="MagicNumber">
<property name="ignoreNumbers" value="-2,-1,0,1,2,100"/>
<property name="ignoreHashCodeMethod" value="true"/>
<property name="ignoreFieldDeclaration" value="true"/>
<property name="severity" value="warning"/>
<property name="id" value="checkstyle:magicnumber"/>
</module>
</module>
</module>
public class Test {
public static final int BIT0 = 1;
public static final int BIT1 = 1 << 1;
public static final int BIT2 = 1 << 2;
public static final int BIT3 = 1 << 3;
public static final int BIT4 = 1 << 4;
}
$ java -jar checkstyle-10.20.1-all.jar -c config.xml Test.java
Starting audit...
[WARN] /var/tmp/Test.java:5:41: '3' is a magic number. [checkstyle:magicnumber]
[WARN] /var/tmp/Test.java:6:41: '4' is a magic number. [checkstyle:magicnumber]
Audit done.
I would have expected bit-shift operators to also be excluded from this check, just like 2 * 2 * 2 would work without checkstyle complaining...
I have read check documentation: https://checkstyle.org/checks/coding/magicnumber.html
I have downloaded the latest cli from: https://checkstyle.org/cmdline.html#Download_and_Run
I have executed the cli and showed it below, as cli describes the problem better than 1,000 words
I would have expected bit-shift operators to also be excluded from this check, just like
2 * 2 * 2would work without checkstyle complaining...