Skip to content

Formatting not stable with comment in if statement #592

Closed
@jmattheis

Description

@jmattheis

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.

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