-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Closed
Labels
approvedbugfalse positiveissues where check places violations on code, but should notissues where check places violations on code, but should notgoogle styleindentation
Milestone
Description
I have read check documentation:
- https://checkstyle.org/checks/blocks/leftcurly.html
- https://checkstyle.org/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
/var/tmp $ javac mymodule/src/main/java/com/example/checkstyle/CheckstyleScope.java
/var/tmp $ cat minimal-rules.xml
<?xml version="1.0" encoding="UTF-8"?>
<!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="LeftCurly">
<property name="tokens"
value="ANNOTATION_DEF, CLASS_DEF, CTOR_DEF, ENUM_CONSTANT_DEF, ENUM_DEF,
INTERFACE_DEF, LAMBDA, LITERAL_CATCH, LITERAL_DEFAULT,
LITERAL_DO, LITERAL_ELSE, LITERAL_FINALLY, LITERAL_FOR, LITERAL_IF,
LITERAL_SWITCH, LITERAL_SYNCHRONIZED, LITERAL_TRY, LITERAL_WHILE, METHOD_DEF,
OBJBLOCK, STATIC_INIT, RECORD_DEF, COMPACT_CTOR_DEF"/>
</module>
<module name="Indentation">
<property name="basicOffset" value="2"/>
<property name="braceAdjustment" value="2"/>
<property name="caseIndent" value="2"/>
<property name="throwsIndent" value="4"/>
<property name="lineWrappingIndentation" value="4"/>
<property name="arrayInitIndent" value="2"/>
</module>
</module>
</module>
/var/tmp $ cat mymodule/src/main/java/com/example/checkstyle/CheckstyleScope.java
package com.example.checkstyle;
public class CheckstyleScope {
private static void indentationIssue(Condition condition) {
switch (condition) {
case TRUE:
{
System.out.println("True");
break;
}
case FALSE:
{
System.out.println("False");
break;
}
default:
System.out.println("Other");
}
{
System.out.println("True");
}
}
private enum Condition {
TRUE,
FALSE
}
}
/var/tmp $ RUN_LOCALE="-Duser.language=en -Duser.country=US"
/var/tmp $ java $RUN_LOCALE -jar ~/Downloads/checkstyle-10.12.7-all.jar -c ./minimal-rules.xml mymodule/src/main/java/com/example/checkstyle/CheckstyleScope.java
Starting audit...
[ERROR] /home/path/mymodule/src/main/java/com/example/checkstyle/CheckstyleScope.java:14:9: 'block lcurly' has incorrect indentation level 8, expected level should be 6. [Indentation]
[ERROR] /home/path/mymodule/src/main/java/com/example/checkstyle/CheckstyleScope.java:15:11: 'block' child has incorrect indentation level 10, expected level should be 8. [Indentation]
[ERROR] /home/path/mymodule/src/main/java/com/example/checkstyle/CheckstyleScope.java:16:11: 'block' child has incorrect indentation level 10, expected level should be 8. [Indentation]
[ERROR] /home/path/mymodule/src/main/java/com/example/checkstyle/CheckstyleScope.java:17:9: 'block rcurly' has incorrect indentation level 8, expected level should be 6. [Indentation]
[ERROR] /home/path/mymodule/src/main/java/com/example/checkstyle/CheckstyleScope.java:19:9: 'block lcurly' has incorrect indentation level 8, expected level should be 6. [Indentation]
[ERROR] /home/path/mymodule/src/main/java/com/example/checkstyle/CheckstyleScope.java:20:11: 'block' child has incorrect indentation level 10, expected level should be 8. [Indentation]
[ERROR] /home/path/mymodule/src/main/java/com/example/checkstyle/CheckstyleScope.java:21:11: 'block' child has incorrect indentation level 10, expected level should be 8. [Indentation]
[ERROR] /home/path/mymodule/src/main/java/com/example/checkstyle/CheckstyleScope.java:22:9: 'block rcurly' has incorrect indentation level 8, expected level should be 6. [Indentation]
Audit done.
Checkstyle ends with 8 errors.
If I modify the rules to change to <property name="braceAdjustment" value="0"/>
,
I manage to get ride of some errors but new ones appears:
/var/tmp $ java -jar ~/Downloads/checkstyle-10.12.7-all.jar -c ./minimal-rules.xml mymodule/src/main/java/com/example/checkstyle/CheckstyleScope.java
Starting audit...
[ERROR] /home/path/mymodule/src/main/java/com/example/checkstyle/CheckstyleScope.java:27:5: 'block lcurly' has incorrect indentation level 4, expected level should be 6. [Indentation]
[ERROR] /home/path/mymodule/src/main/java/com/example/checkstyle/CheckstyleScope.java:29:5: 'block rcurly' has incorrect indentation level 4, expected level should be 6. [Indentation]
Audit done.
Checkstyle ends with 2 errors.
The file was previously formatted with google-java-format (https://github.com/google/google-java-format/releases/tag/v1.19.2):
/var/tmp $ java -jar ~/Downloads/google-java-format-1.19.2-all-deps.jar --replace mymodule/src/main/java/com/example/checkstyle/CheckstyleScope.java
Metadata
Metadata
Assignees
Labels
approvedbugfalse positiveissues where check places violations on code, but should notissues where check places violations on code, but should notgoogle styleindentation