Formatting wrapped and nested array (and tuple)

I tried to format following program with crystal tool format:

foo([1, [2, 3,
         4, 5, [6,
                7]],
     8, 9],
     10, 11)

I got the following result:

foo([1, [2, 3,
         4, 5, [6,
                7]],
8, 9],
  10, 11)

I think it should be the following with the current rule as far as I know.

foo([1, [2, 3,
         4, 5, [6,
                7]],
     8, 9],
  10, 11)

This also happens for a simple assignment:

x = [1, [2, 3,
         4, 5, [6, 7]],
     8, 9]

yields:

x = [1, [2, 3,
         4, 5, [6, 7]],
8, 9]

Fine cases:

So, it seems fine if it does not end with ]],:

x = [1, [2],
     8, 9, [3, 4, 5],
  6, 7]

yields

x = [1, [2],
     8, 9, [3, 4, 5],
     6, 7]

And,

x = [1, [2, 3,
         4, 5, [6, 7]], 11,
8, 9]

yields:

x = [1, [2, 3,
         4, 5, [6, 7]], 11,
     8, 9]

With Tuple

This also happens for nesting arrays and tuples:

checker = A.new([{'a', [{'b', [{'c'..'e'}]},
                        {'e', [NodeRef[0, 2],
                               {'x'}]}]},
                 {'z', [NodeRef[1, 1]]}],
                1, 2)

yields:

checker = A.new([{'a', [{'b', [{'c'..'e'}]},
                        {'e', [NodeRef[0, 2],
                               {'x'}]}]},
{'z', [NodeRef[1, 1]]}],
  1, 2)

Can this be a bug?

crystal version

Crystal 1.0.0 ()

LLVM: 12.0.1
Default target: x86_64-unknown-linux-gnu

with Add support for LLVM 12 by Blacksmoke16 · Pull Request #10873 · crystal-lang/crystal · GitHub.

I’ll try some newer versions if there are differences.

I’ve had issues with auto-formatting nested and/or large structures too. My work-around was to add extra line-breaks to stretch things out a bit and then re-run the format command. But, a ‘real fix’ would be nice for such nested and/or large structures.

Can you please report this as a bug at Issues · crystal-lang/crystal · GitHub ?

I reported this here: Formatting wrapped and nested array (and tuple) · Issue #11079 · crystal-lang/crystal · GitHub.

Thanks.