Skip to content

Number-only array arguments print one element per line #1114

Closed

Description

@2is10

Prettier-Java 2.11.0

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

Input:

class A {
  void f() {
    assertEquals(Bytes.fromInt(0x01020304), new byte[] { 0x01, 0x02, 0x03, 0x04 });
    community = fromExtended(0x02, new byte[] { 0x00, 0x00, 0x00, 0x64, 0x19, 0x00, 0x00, 0x00, 0x00, 0x64, 0x19, 0x00, 0x00, 0x00, 0x00, 0x64 });
  }
}

Output:

class A {

  void f() {
    assertEquals(Bytes.fromInt(0x01020304), new byte[] {
      0x01,
      0x02,
      0x03,
      0x04,
    });
    community = fromExtended(0x02, new byte[] {
      0x00,
      0x00,
      0x00,
      0x64,
      0x19,
      0x00,
      0x00,
      0x00,
      0x00,
      0x64,
      0x19,
      0x00,
      0x00,
      0x00,
      0x00
      0x64,
    });
  }
}

Expected behavior:

class A {

  void f() {
    assertEquals(
      Bytes.fromInt(0x01020304),
      new byte[] { 0x01, 0x02, 0x03, 0x04 }
    );
    community = fromExtended(
      0x02,
      new byte[] {
        0x00, 0x00, 0x00, 0x64, 0x19, 0x00, 0x00, 0x00, 0x00, 0x64, 0x19, 0x00,
        0x00, 0x00, 0x00, 0x64,
      }
    );
  }
}

This matches Prettier JS, which doesn't hug a number-only array as the last argument and fills its elements across lines:

community = fromExtended(
  0x02,
  [
    0x00, 0x00, 0x00, 0x64, 0x19, 0x00, 0x00, 0x00, 0x00, 0x64, 0x19, 0x00,
    0x00, 0x00, 0x00, 0x64,
  ],
);

2.8.1 also kept short arrays like the first one on a single line:

assertEquals(Bytes.fromInt(0x01020304), new byte[] { 0x01, 0x02, 0x03, 0x04 });

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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