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

fix: break and indent assignments like declarations #690

Merged
merged 1 commit into from
Oct 14, 2024

Conversation

jtkiesel
Copy link
Contributor

What changed with this PR:

Assignment expressions with boolean expression righthand sides no longer break/indent poorly, and assignment expressions in general are now printed the same way as variable declarations.

Example

Input

class Example {

  void example() {
    double availability12 =
      (double) successfulCount / (successfulCount + failureCount);
    availability12 = (double) successfulCount /
    (successfulCount + failureCount);

    var lineLengthInAssignmentMoreThanPrintWidth =
      "1234567890" +
      "1234567890" +
      "1234567890" +
      "1234567890" +
      "1234567890" +
      "1234567890";
    lineLengthInAssignmentMoreThanPrintWidth = "1234567890" +
    "1234567890" +
    "1234567890" +
    "1234567890" +
    "1234567890" +
    "1234567890";

    aaaaaaaaaa +=
    bbbbbbbbbbb +
    ccccccccccc +
    ddddddddddd +
    eeeeeeeeee +
    ffffffffff +
    gggggggggg;
    aaaaaaaaaa %=
    bbbbbbbbbbb +
    ccccccccccc +
    ddddddddddd +
    eeeeeeeeee +
    ffffffffff +
    gggggggggg;
    aaaaaaaaaa <<=
    bbbbbbbbbbb +
    ccccccccccc +
    ddddddddddd +
    eeeeeeeeee +
    ffffffffff +
    gggggggggg;
    aaaaaaaaaa &=
    bbbbbbbbbbb +
    ccccccccccc +
    ddddddddddd +
    eeeeeeeeee +
    ffffffffff +
    gggggggggg;

    var something =
      MyClass.staticFunction(
        aaaaaaaaaa,
        bbbbbbbbbbb,
        ccccccccccc,
        ddddddddddd
      ) +
      0;
    something = MyClass.staticFunction(
      aaaaaaaaaa,
      bbbbbbbbbbb,
      ccccccccccc,
      ddddddddddd
    ) +
    0;
  }
}

Output

class Example {

  void example() {
    double availability12 =
      (double) successfulCount / (successfulCount + failureCount);
    availability12 =
      (double) successfulCount / (successfulCount + failureCount);

    var lineLengthInAssignmentMoreThanPrintWidth =
      "1234567890" +
      "1234567890" +
      "1234567890" +
      "1234567890" +
      "1234567890" +
      "1234567890";
    lineLengthInAssignmentMoreThanPrintWidth =
      "1234567890" +
      "1234567890" +
      "1234567890" +
      "1234567890" +
      "1234567890" +
      "1234567890";

    aaaaaaaaaa +=
      bbbbbbbbbbb +
      ccccccccccc +
      ddddddddddd +
      eeeeeeeeee +
      ffffffffff +
      gggggggggg;
    aaaaaaaaaa %=
      bbbbbbbbbbb +
      ccccccccccc +
      ddddddddddd +
      eeeeeeeeee +
      ffffffffff +
      gggggggggg;
    aaaaaaaaaa <<=
      bbbbbbbbbbb +
      ccccccccccc +
      ddddddddddd +
      eeeeeeeeee +
      ffffffffff +
      gggggggggg;
    aaaaaaaaaa &=
      bbbbbbbbbbb +
      ccccccccccc +
      ddddddddddd +
      eeeeeeeeee +
      ffffffffff +
      gggggggggg;

    var something =
      MyClass.staticFunction(
        aaaaaaaaaa,
        bbbbbbbbbbb,
        ccccccccccc,
        ddddddddddd
      ) +
      0;
    something =
      MyClass.staticFunction(
        aaaaaaaaaa,
        bbbbbbbbbbb,
        ccccccccccc,
        ddddddddddd
      ) +
      0;
  }
}

Relative issues or prs:

Closes #687

@jtkiesel jtkiesel merged commit e2035ae into main Oct 14, 2024
11 checks passed
@jtkiesel jtkiesel deleted the fix/assignments-break-and-indent branch October 14, 2024 01:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ugly formatting: long assignment to previously declared variable
1 participant