Skip to content

feat: concise numeric array initializers - #1126

Merged
jtkiesel merged 1 commit into
jhipster:mainfrom
jtkiesel:feat/concise-numeric-arrays
Oct 28, 2026
Merged

jtkiesel merged 1 commit into
jhipster:mainfrom
jtkiesel:feat/concise-numeric-arrays

Conversation

@jtkiesel

@jtkiesel jtkiesel commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

What changed with this PR:

Formatting of array initializers is aligned with arrays in Prettier JS, in that numeric arrays can now be printed concisely.

Example

Input

int[] empty = {};

int[] emptyWithComments = {
  // dangling comment
};

int[] shortArray = { 1, 2, 3, 4, 5 };

int[] longArray = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25 };

int[] variousBases = { 0b1010, 0xFF, 0123, 3.14159f, 2.71828d, 100L, 0b1101, 0xABC, 0456, 1.41421f, 1.61803d, 200L, 0b1111, 0x7F, 0777, 9.80665f, 6.62607d, 300L };

int[] signedNumbers = { -1, +2, -42, +100, -3.14, -500, +600, -7000, +80, -90, +101, -202, +303, -404, +505, -606 };

int[] signedWithComment = { -1, -/* negative two */ 2, +3, -4, +5, -6, +7, -8, +9, -10 };

int[] withBlankLines = {
  1, 2, 3, 4, 5,

  6, 7, 8, 9, 10,

  11, 12, 13, 14, 15
};

int[] withTrailingComments = {
  1, // comment on one
  2, // comment on two
  3
};

int[] withLeadingComments = {
  1,
  // comment before 3
  3,
  4
};

Object[] mixedArray = { 1, "hello", true, null, 2, "world", false, 3, "foo", true, 4, "bar", false };

int[] expressionArray = { 1 + 1, 2 * 3, getValue(), 4 + 4, 5 * 5, getData(), 6 + 6, 7 * 7, compute() };

int[][] nestedSingular = { { 1 }, { 2 }, { 3 } };

int[][] nestedMultiple = { { 1, 2 }, { 3, 4 }, { 5, 6 } };

int[] arrayWithInternalNodeComment = {
  1, 2, 3
  // internal node comment
};

Output

int[] empty = {};

int[] emptyWithComments = {
  // dangling comment
};

int[] shortArray = { 1, 2, 3, 4, 5 };

int[] longArray = {
  1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22,
  23, 24, 25,
};

int[] variousBases = {
  0b1010, 0xFF, 0123, 3.14159f, 2.71828d, 100L, 0b1101, 0xABC, 0456, 1.41421f,
  1.61803d, 200L, 0b1111, 0x7F, 0777, 9.80665f, 6.62607d, 300L,
};

int[] signedNumbers = {
  -1, +2, -42, +100, -3.14, -500, +600, -7000, +80, -90, +101, -202, +303, -404,
  +505, -606,
};

int[] signedWithComment = {
  -1,
  -(/* negative two */ 2),
  +3,
  -4,
  +5,
  -6,
  +7,
  -8,
  +9,
  -10,
};

int[] withBlankLines = {
  1, 2, 3, 4, 5,

  6, 7, 8, 9, 10,

  11, 12, 13, 14, 15,
};

int[] withTrailingComments = {
  1, // comment on one
  2, // comment on two
  3,
};

int[] withLeadingComments = {
  1,
  // comment before 3
  3, 4,
};

Object[] mixedArray = {
  1,
  "hello",
  true,
  null,
  2,
  "world",
  false,
  3,
  "foo",
  true,
  4,
  "bar",
  false,
};

int[] expressionArray = {
  1 + 1,
  2 * 3,
  getValue(),
  4 + 4,
  5 * 5,
  getData(),
  6 + 6,
  7 * 7,
  compute(),
};

int[][] nestedSingular = { { 1 }, { 2 }, { 3 } };

int[][] nestedMultiple = {
  { 1, 2 },
  { 3, 4 },
  { 5, 6 },
};

int[] arrayWithInternalNodeComment = {
  1, 2, 3,
  // internal node comment
};

Relative issues or prs:

Closes #1114

@jtkiesel
jtkiesel force-pushed the feat/concise-numeric-arrays branch from e32e707 to a923202 Compare October 27, 2026 06:00
@jtkiesel
jtkiesel merged commit b352dc1 into jhipster:main Oct 28, 2026
6 checks passed
@jtkiesel
jtkiesel deleted the feat/concise-numeric-arrays branch October 28, 2026 02:07
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.

Number-only array arguments print one element per line

1 participant