-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Open
Labels
Description
I have read check documentation: https://checkstyle.sourceforge.io/checks/misc/indentation.html
I have downloaded the latest checkstyle 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
PS D:\CS\test> javac src/Test.java
PS D:\CS\test> cat config.xml
<?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">
<module name="TreeWalker">
<module name="Indentation">
<property name="forceStrictCondition" value="true"/>
</module>
</module>
</module>
PS D:\CS\test> cat src/Test.java
public class Test {
void t1(Object o) {
if (o instanceof
Point(_, _
)) { } // violation
// + 'if' child has incorrect indentation level 8, expected level should be 12. This is the record pattern paren
if (o instanceof
Point(_, _
)) { } // violation
// + ')' has incorrect indentation level 12, expected level should be 8. This is the `if` paren
}
record Point(int x, int y) { }
}
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:6:9: 'if' child has incorrect indentation level 8, expected level should be 12. [Indentation]
[ERROR] D:\CS\test\src\Test.java:11:13: ')' has incorrect indentation level 12, expected level should be 8. [Indentation]
Audit done.
Checkstyle ends with 2 errors.
PS D:\CS\test>
Describe what you expect in detail.
Current Behavior :
- For the first
if
statement, Checkstyle expects an indentation level of 12 for the record pattern parenthesis - In the second
if
statement, For the closing parenthesis of the if statement, Checkstyle expects an indentation level of 8, but it should be 12.
This can't be satisfied. We can't remove violations for both when the parentheses are on the same line. We can't move the if parenthesis to be on 8 and the record pattern parenthesis to be on 12.
Temporary Workaround:
To avoid conflict we can put the 2 parentheses on different lines.
EDIT: even if it is alone in the line. seems like there is a bug also
public class Test {
void t1(Object o) {
if (o instanceof
Point(_, _
) // violation, ')' has incorrect indentation level 12, expected level should be 8.
) { }
if (o instanceof
Point(_, _
) // violation, 'if' child has incorrect indentation level 8, expected level should be 12.
) { }
}
record Point(int x, int y) { }
}
Starting audit...
[ERROR] D:\CS\test\src\Test.java:6:13: ')' has incorrect indentation level 12, expected level should be 8. [Indentation]
[ERROR] D:\CS\test\src\Test.java:11:9: 'if' child has incorrect indentation level 8, expected level should be 12. [Indentation]
Audit done.
Checkstyle ends with 2 errors.