prettier-java icon indicating copy to clipboard operation
prettier-java copied to clipboard

Missing indentation for division function

Open Friss opened this issue 5 years ago • 1 comments

Prettier-Java 0.7.1

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

Input:

public class Test {

  public static void main(String[] args) {
    if (oneLevelDeep) {
      if (twoLevelsDeep) {
        if (threeLevelsDeep) {
          int successfulCount = 0;
          int failureCount = 1;
          double availability = (double) successfulCount / (successfulCount + failureCount);
        }
      }
    }
  }
}

Output:

public class Test {

  public static void main(String[] args) {
    if (oneLevelDeep) {
      if (twoLevelsDeep) {
        if (threeLevelsDeep) {
          int successfulCount = 0;
          int failureCount = 1;
          double availability = (double) successfulCount /
          (successfulCount + failureCount);
        }
      }
    }
  }
}

Expected behavior: I'm not 100% sure on what the expected behavior should be but I feel that the current output is non ideal.

I would guess having the parens indented 1 level would be okay instead on the same level as the declaration.

Friss avatar Apr 25 '20 02:04 Friss

Hi, thanks for reporting this case ! It seems to be related to on how we handle binaryExpression. I think we need to refactor it again, althought we already did it multiple times as it is difficult to understand what it does exactly.

related issue #307

Shaolans avatar Apr 30 '20 09:04 Shaolans