You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
$ cat IndentationFoo.java
import java.time.DayOfWeek;
import java.time.LocalDate;
public class IndentationFoo {
public static void main(final String[] args) {
final DayOfWeek today = LocalDate.now().getDayOfWeek();
final boolean isWeekend = switch (today) {
case SATURDAY:
System.out.println("Saturday"); // Warning: expected indentation: 16
yield true; // Warning: expected indentation: 16.
case SUNDAY:
System.out.println("Sunday"); // (no warning)
yield true; // Warning: expected indentation: 12
default:
yield false; // Warning: expected indentation: 12
};
System.out.println("isWeekend = " + isWeekend);
}
}
$ java -jar checkstyle-10.20.1-all.jar -c checkstyle-foo.xml IndentationFoo.java
Starting audit...
[ERROR] /home/dan/projects/aeron/aeron-insights/insights/src/main/java/IndentationFoo.java:9:13: 'block' child has incorrect indentation level 12, expected level should be 16. [Indentation]
[ERROR] /home/dan/projects/aeron/aeron-insights/insights/src/main/java/IndentationFoo.java:10:13: 'yield' has incorrect indentation level 12, expected level should be 16. [Indentation]
[ERROR] /home/dan/projects/aeron/aeron-insights/insights/src/main/java/IndentationFoo.java:13:17: 'yield' has incorrect indentation level 16, expected level should be 12. [Indentation]
[ERROR] /home/dan/projects/aeron/aeron-insights/insights/src/main/java/IndentationFoo.java:15:1: 'yield' has incorrect indentation level 0, expected level should be 12. [Indentation]
Audit done.
Checkstyle ends with 4 errors.
The Indentation check rejects all yield statements in switch expressions when forceStrictCondition is set to true. In the example above, it rejects anything that is not 12, saying 12 is the correct level. If you set the indentation level to 12, it rejects it saying it should be 16.
This is also inconsistent with the required indentation level for other statements, which require an indentation of 16.
I would expect 16 to be accepted as the correct indentation for all of these statements.
The text was updated successfully, but these errors were encountered:
I have read check documentation: https://checkstyle.sourceforge.io/checks/misc/indentation.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
The Indentation check rejects all
yield
statements in switch expressions whenforceStrictCondition
is set to true. In the example above, it rejects anything that is not 12, saying 12 is the correct level. If you set the indentation level to 12, it rejects it saying it should be 16.This is also inconsistent with the required indentation level for other statements, which require an indentation of 16.
I would expect 16 to be accepted as the correct indentation for all of these statements.
The text was updated successfully, but these errors were encountered: