Checkstyle and JABA8 lambdas

I am preparing a big migration to JAVA8. Part of it configures checkstyle to work correctly with JAVA8 constructs. I am trying to keep checkstyle synchronized with the default autoformatting tool in IntelliJ. Unfortunately, it does not accept IntelliJ automatic indentation of lambda expressions.

checkstyle.xml

<module name="Indentation">
     <property name="caseIndent" value="0"/>
</module>

code:

public class Java8CheckstyleTest {
    public void java8Elements(String ala) {
        Collections.sort(names, (String a, String b) -> {
            return b.compareTo(a); // <<<25 line
        }); // <<<26 line
    }
}

Verification Report:

Java8CheckstyleTest.java:25: the block child has an incorrect indentation level 12, the expected level should be 16.

Java8CheckstyleTest.java:26: "block rcurly" has the wrong indentation level 16, the expected level should be 12.

If I break "})" with a new line and autoformat:

public class Java8CheckstyleTest {
    public void java8Elements(String ala) {
        Collections.sort(names, (String a, String b) -> {
                    return b.compareTo(a); // <<<25 line
                } // <<<26 line
        ); 
    }
}

I get:

Java8CheckstyleTest.java:25: the block child has the wrong indentation level 20, the expected level should be 16.

Java8CheckstyleTest.java:26:'block rcurly ' 16, 12.

checkstyle, ?

EDIT: checkstyle 6.11.1, , , . . :

Java8CheckstyleTest.java:32: : "block" 20, : 12, 16.

Java8CheckstyleTest.java:33: : "block rcurly" 16, : 8, 12.

, , , , ​​ IntelliJ. .

+4
1

:

  <dependency>
      <groupId>com.puppycrawl.tools</groupId>
      <artifactId>checkstyle</artifactId>
      <version>6.11.1</version>
  </dependency>

maven checkstyle . .

+3

Source: https://habr.com/ru/post/1610932/


All Articles