Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Line break between instanceof and final #605

Closed
benediktsatalia opened this issue Sep 12, 2023 · 1 comment · Fixed by #611
Closed

Line break between instanceof and final #605

benediktsatalia opened this issue Sep 12, 2023 · 1 comment · Fixed by #611

Comments

@benediktsatalia
Copy link

Prettier-Java 2.3.1

# Options (if any):
--print-width 80

Input:

  public boolean test(final Object obj) {
    return obj instanceof final Integer x && (x == 5 || x == 6 || x == 7 || x == 8 || x == 9 || x == 10 || x == 11);
  }

Output:

  public boolean test(final Object obj) {
    return (
      obj instanceof
      final Integer x &&
      (x == 5 || x == 6 || x == 7 || x == 8 || x == 9 || x == 10 || x == 11)
    );
  }

Expected behavior:

  public boolean test(final Object obj) {
    return (
      obj instanceof final Integer x &&
      (x == 5 || x == 6 || x == 7 || x == 8 || x == 9 || x == 10 || x == 11)
    );
  }
@jtkiesel
Copy link
Contributor

This seems to have been caused by #594, so a temporary workaround would be to downgrade to prettier-plugin-java 2.2.0.

It appears to affect instanceof pattern matching. For example, the following example is broken properly:
Input:

class Example {

  void example() {
    a instanceof Integer && cccccccccccccccccccccccccccccccccccccccccccccccccccc;
  }
}

Output:

class Example {

  void example() {
    a instanceof Integer &&
    cccccccccccccccccccccccccccccccccccccccccccccccccccc;
  }
}

While the following example is broken improperly:
Input:

class Example {

  void example() {
    a instanceof Integer b && cccccccccccccccccccccccccccccccccccccccccccccccccc;
  }
}

Output:

class Example {

  void example() {
    a instanceof
    Integer b &&
    cccccccccccccccccccccccccccccccccccccccccccccccccc;
  }
}

I've begun looking into fixing this.

jtkiesel added a commit to jtkiesel/prettier-java that referenced this issue Sep 17, 2023
jtkiesel added a commit to jtkiesel/prettier-java that referenced this issue Sep 18, 2023
jtkiesel added a commit to jtkiesel/prettier-java that referenced this issue Sep 18, 2023
jtkiesel added a commit to jtkiesel/prettier-java that referenced this issue Sep 18, 2023
jtkiesel added a commit to jtkiesel/prettier-java that referenced this issue Sep 18, 2023
jtkiesel added a commit to jtkiesel/prettier-java that referenced this issue Oct 27, 2023
jtkiesel added a commit to jtkiesel/prettier-java that referenced this issue Oct 27, 2023
jtkiesel added a commit to jtkiesel/prettier-java that referenced this issue Oct 29, 2023
jtkiesel added a commit to jtkiesel/prettier-java that referenced this issue Oct 29, 2023
jtkiesel added a commit to jtkiesel/prettier-java that referenced this issue Oct 29, 2023
jtkiesel added a commit to jtkiesel/prettier-java that referenced this issue Oct 29, 2023
jtkiesel added a commit to jtkiesel/prettier-java that referenced this issue Oct 29, 2023
clementdessoude pushed a commit that referenced this issue Nov 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants