PS D:\CS\test> cat src/Test.java
import java.util.LinkedHashMap;
import java.util.List;
record ColoredPoint(String p, String x, int c) { }
record Rectangle(ColoredPoint upperLeft, ColoredPoint lowerRight) { }
public class Test {
void test(Object obj) {
int _ = 4;
}
}
PS D:\CS\test> cat config.xml
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
"-//Puppy Crawl//DTD Check Configuration 1.3//EN"
"http://www.puppycrawl.com/dtds/configuration_1_3.dtd">
<module name="Checker">
<property name="charset" value="UTF-8"/>
<module name="TreeWalker">
<module name="MagicNumber">
</module>
</module>
</module>
PS D:\CS\test> javac src/Test.java
PS D:\CS\test> java -jar checkstyle-10.17.0-all.jar -c config.xml src/Test.java
Starting audit...
[ERROR] D:\CS\test\src\Test.java:9:16: '4' is a magic number. [MagicNumber]
Audit done.
Checkstyle ends with 1 errors.
PS D:\CS\test>
The check always detects magic numbers whether it is assigned to an unnamed variable or not.
child of #14942 :
doc :https://checkstyle.org/checks/coding/magicnumber.html
The check always detects magic numbers whether it is assigned to an unnamed variable or not.