mvdan / sh

A shell parser, formatter, and interpreter with bash support; includes shfmt
https://pkg.go.dev/mvdan.cc/sh/v3
BSD 3-Clause "New" or "Revised" License
7.1k stars 336 forks source link

syntax: inconsistent formatting for subshell's closing parentheses #876

Open riacataquian opened 2 years ago

riacataquian commented 2 years ago

The syntax $(( and (( are ambiguous and when printing, we space the opening parentheses as in: ( (, as documented on the Caveats which is OK but we don't space for its closing parentheses. The output then looks inconsistent:

$ cat in.sh
( (foo) )
$ shfmt in.sh
( (foo))

It's not actually wrong but we can improve the output by making the space consistent:

( (foo) )
mvdan commented 2 years ago

I think this suggestion makes sense - we don't strictly need the space between the closing parentheses for the sake of avoiding ambiguity, but adding the space makes the formatting more consistent, which is the point of the formatter.