Skip to content

Indentation check doesn't give violation when google formatter does #8965

@rdiachenko

Description

@rdiachenko

Checkstyle 8.37, google-java-format 1.9
config (taken from google_checks.xml - https://github.com/checkstyle/checkstyle/blob/checkstyle-8.37/src/main/resources/google_checks.xml#L243):

<?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">
  <module name="TreeWalker">
    <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>

code:

class Test {
  public Object foo() {
    return Optional.empty()
        .orElseThrow(
          () ->
new IllegalArgumentException(
"Something wrong 1, something wrong 2, something wrong 3"));
  }
}

none violations given by Checkstyle:

$ java -jar checkstyle-8.37-all.jar -c config.xml Test.java 
Starting audit...
Audit done.

but there is a non-empty diff when applying google-java-format (which leads to errors when using https://github.com/coveooss/fmt-maven-plugin):

$ java -jar google-java-format-1.9-all-deps.jar Test.java > /tmp/FormattedTest.java && diff -Naru Test.java /tmp/FormattedTest.java
--- Test.java	2020-11-05 06:46:28.027335639 +0000
+++ /tmp/FormattedTest.java	2020-11-05 07:13:01.536163532 +0000
@@ -2,8 +2,8 @@
   public Object foo() {
     return Optional.empty()
         .orElseThrow(
-          () ->
-new IllegalArgumentException(
-"Something wrong 1, something wrong 2, something wrong 3"));
+            () ->
+                new IllegalArgumentException(
+                    "Something wrong 1, something wrong 2, something wrong 3"));
   }
 }

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    Done

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions