jhipster / prettier-java

Prettier Java Plugin
http://www.jhipster.tech/prettier-java/
Apache License 2.0
1.08k stars 103 forks source link

Formatting not stable with comment in if statement #592

Open jmattheis opened 1 year ago

jmattheis commented 1 year ago

Prettier-Java 2.2.0

The formatting is not stable with the following code structure and needs to be run twice to get to a stable state:

$ yarn add prettier prettier-plugin-java
$ cat initial.java
package main;

class Main {

  public static void main(String[] args) {
    if (true) // comment
    {
      System.out.println("Oops");
    }
  }
}
$ yarn -s prettier --plugin prettier-plugin-java initial.java | tee first.java
package main;

class Main {

  public static void main(String[] args) {
    if (
      true
    ) { // comment
      System.out.println("Oops");
    }
  }
}
$ yarn -s prettier --plugin prettier-plugin-java first.java | tee second.java
package main;

class Main {

  public static void main(String[] args) {
    if (true) { // comment
      System.out.println("Oops");
    }
  }
}

Expected behavior:

The prettier-java-plugin should only require one format execution to properly format the code.