Skip to content

Non-idempotent and non-convergent formatting of parentheses placement near line-level comments #914

Closed

Description

@ZachCallear

Prettier-Java 2.9.7

Example 1:

This example can be reproduced in https://www.jhipster.tech/prettier-java/playground with its default settings by repeatedly pasting the output back into the input.

Input 1:

public class Foo {

  public static void testMethod() {
    var something1 =
      something2 + // comment line 1
      // comment line 2
      (something3);
  }
}

Output 1:

public class Foo {

  public static void testMethod() {
    var something1 =
      something2 + // comment line 1
      (// comment line 2
        something3);
  }
}

Input 2 is identical to Output 1.

Output 2 is identical to Input 1.

This especially becomes noticeable when paired with googleJavaFormat().reflowLongStrings() in the Spotless Gradle plugin, which often breaks single-line comments into multiple lines.

Example 2:

This example cannot be reproduced in https://www.jhipster.tech/prettier-java/playground with its default settings, but it occurs when running prettier --plugin prettier-plugin-java --write test.java on a file directly. In the Playground, setting --arrow-parens to avoid also causes it to be reproducible, but according to prettier --plugin prettier-plugin-java --help | grep arrow -A1, the default for this setting is always, as the Playground shows as its default.

Input 1:

 public class Foo {

   public static void testMethod() {
     var something1 = Optional.ofNullable(null).map(
       (something2) -> // Allocate the jaguar to the treestump.
         (Set<String>) Sets.union(ImmutableSet.of(something), SOME_SET_OF_THINGS)
     );
   }
 }

Output 1:

 public class Foo {

   public static void testMethod() {
     var something1 = Optional.ofNullable(null).map(
       something2 -> // Allocate the jaguar to the treestump.
         (Set<String>) Sets.union(ImmutableSet.of(something), SOME_SET_OF_THINGS)
     );
   }
 }

Input 2 is identical to Output 1.

Output 2 is identical to Input 1:

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions