Skip to content

Ugly formatting: long assignment to previously declared variable #687

Closed
@kaidohallik

Description

@kaidohallik

Prettier-Java 2.6.4

# Options (if any):
print-width: 140
tab-width: 2

Input:

class Example {

  void example() {
    var lineLengthInAssignmentMoreThanPrintWidth = "";
    lineLengthInAssignmentMoreThanPrintWidth = "1234567890" + "1234567890" + "1234567890" + "1234567890" + "1234567890" + "1234567890" + "1234567890";
  }
}

Output:

class Example {

  void example() {
    var lineLengthInAssignmentMoreThanPrintWidth = "";
    lineLengthInAssignmentMoreThanPrintWidth = "1234567890" +
    "1234567890" +
    "1234567890" +
    "1234567890" +
    "1234567890" +
    "1234567890" +
    "1234567890";
  }
}

Expected output:

class Example {

  void example() {
    var lineLengthInAssignmentMoreThanPrintWidth = "";
    lineLengthInAssignmentMoreThanPrintWidth =
      "1234567890" + "1234567890" + "1234567890" + "1234567890" + "1234567890" + "1234567890" + "1234567890";
  }
}

Note: long variable declarations are formatted correctly:

class Example {

  void example() {
    var lineLengthInAssignmentMoreThanPrintWidth =
      "1234567890" + "1234567890" + "1234567890" + "1234567890" + "1234567890" + "1234567890" + "1234567890";
  }
}

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