-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Description
/var/tmp $ javac Test.java
/var/tmp $ cat Test.java
package com.github.aruberto;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;
public class Test {
public static void someFunction(SomeUtilClass util) {
// This fails indentation rule
util.myLambdaUtil("FIRST_ARG",
(string) -> System.out.println(string.trim()), //line 13
"SECOND_ARG",
() -> "WHAT WHAT!"); //line 15
// This passes indentation rule
util.myLambdaUtil("FIRST_ARG",
(string) -> System.out.println(string.trim()),
"SECOND_ARG",
() -> "WHAT WHAT!");
// This fails indentation rule
Function<String, String> someFunction1 =
(string) -> { // line 25
if (string.contains("abc")) {
return "SWEET!";
} else if (string.contains("123")) {
return "COOL!";
} else {
return "BOO!";
}
}; // line 33
// This passes indentation rule
Function<String, String> someFunction2 =
(string) -> {
if (string.contains("abc")) {
return "SWEET!";
} else if (string.contains("123")) {
return "COOL!";
} else {
return "BOO!";
}
};
}
interface SomeUtilClass {
void myLambdaUtil(String firstArg,
Consumer<String> firstLambda,
String secondArg,
Supplier<String> secondLambda);
}
}
/var/tmp $ 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"/>
<property name="severity" value="warning"/>
<property name="fileExtensions" value="java, properties, xml"/>
<module name="FileTabCharacter">
<property name="eachLine" value="true"/>
</module>
<module name="TreeWalker">
<module name="Indentation">
<property name="basicOffset" value="4"/>
<property name="braceAdjustment" value="0"/>
<property name="caseIndent" value="4"/>
<property name="throwsIndent" value="8"/>
<property name="arrayInitIndent" value="4"/>
<property name="lineWrappingIndentation" value="0"/>
<property name="forceStrictCondition" value="false"/>
</module>
</module>
</module>
/var/tmp $ java -jar checkstyle-7.0-all.jar -c config.xml Test.java
Starting audit...
[WARN] Test.java:13: 'lambda arguments' have incorrect indentation level 26, expected level should be one of the following: 8, 12. [Indentation]
[WARN] Test.java:15: 'lambda arguments' have incorrect indentation level 26, expected level should be one of the following: 8, 12. [Indentation]
[WARN] Test.java:25: 'lambda arguments' have incorrect indentation level 16, expected level should be 8. [Indentation]
[WARN] Test.java:26: 'if' have incorrect indentation level 20, expected level should be 12. [Indentation]
[WARN] Test.java:27: 'if' child have incorrect indentation level 24, expected level should be 16. [Indentation]
[WARN] Test.java:28: 'if rcurly' have incorrect indentation level 20, expected level should be 12. [Indentation]
[WARN] Test.java:29: 'if' child have incorrect indentation level 24, expected level should be 16. [Indentation]
[WARN] Test.java:30: 'if rcurly' have incorrect indentation level 20, expected level should be 12. [Indentation]
[WARN] Test.java:31: 'else' child have incorrect indentation level 24, expected level should be 16. [Indentation]
[WARN] Test.java:32: 'else rcurly' have incorrect indentation level 20, expected level should be 12. [Indentation]
[WARN] Test.java:33: 'block rcurly' have incorrect indentation level 16, expected level should be 8. [Indentation]
Audit done.
Describe what you expect in details.
Given that forceStrictCondition is false and lineWrappingIndentation = 0, I should be able to indent lambda expressions on wrapping lines at any indent level > 0.
In First example, the String arg on line 14 is aligned and passes indentation rule (indention of 26) but the Consumer and Supplier args on line 13 and 15 are forced to indent at 8 or 12.
In second example, I define my Function on a new line after assignment operator (lines 25-33). This is indented by Intellij to 16 as it respects current line wrapping settings. But checkstyle want an indentation of 8 for wrapping line and all subsequent lines of lambda expression.