sh
sh copied to clipboard
syntax: align array elements if the first does not follow a newline
This was a case where some users were using -kp
, particularly for PKGBUILDs. See https://github.com/mvdan/sh/issues/658#issuecomment-775143783. Copying part of the comment below. Here's an example PKGBUILD with the format: https://github.com/archlinux/svntogit-community/blob/8813db36b540577575e425ba3ce98c3894d1c768/trunk/PKGBUILD
If space indentation is used and arrays begin with an element on the same line, then the elements on following lines could be vertically aligned. This is something we already do for comments, for instance.
The canonical format, when indenting with -i=4
, could be:
# The first element is on the same line; align elements vertically.
aligned=(one
two
three)
# The first element is on a separate line and indented,
# so we don't need vertical alignment.
indented=(
one
two
three
)
It's unclear if it would be a breaking change in v3, but we could always try implementing it and see how many users it upsets. I think, overall, it should result in better style. And if anyone does not like the alignment, they can just add a newline before the first element to get the good old indentation.
This new feature would only kick in for space indentation, not tabs, because mixing tabs and spaces is deliberately not supported.
cc @maximbaz