jhipster / prettier-java

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

fix: no break in single-block switch case #636

Closed jtkiesel closed 4 months ago

jtkiesel commented 5 months ago

What changed with this PR:

Switch cases whose block statements consists of a single block no longer have that block broken and indented. This aligns such switch cases with the way Prettier JavaScript formats them, and no longer violates the Checkstyle that Prettier Java provides.

Example

Input

class Example {

  void example() {
    switch (a) {
      case 1:
        {}
      case 2:
        {
          b();
        }
      case 3:
        {
          c();
        }
        {
          d();
        }
      case 4:
        e();
        {
          f();
        }
      case 5:
        {
          g();
        }
        h();
    }
  }
}

Output

class Example {

  void example() {
    switch (a) {
      case 1: {}
      case 2: {
        b();
      }
      case 3:
        {
          c();
        }
        {
          d();
        }
      case 4:
        e();
        {
          f();
        }
      case 5:
        {
          g();
        }
        h();
    }
  }
}

Relative issues or prs:

Closes #635