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.14k stars 338 forks source link

Support for Comments Using Command Substitution in Multiline Commands #845

Closed TheFrozenDuck closed 2 years ago

TheFrozenDuck commented 2 years ago

To comment a multiline command I used following bash's command substitution [1] that allows to place a comment in a multiline command like this:

dosomething `# exclude all unnecessary files` \
                      -f                                                \
                      -b                                                \
                      `# more important things`           \
                      -c                                                \
                      -d

Trying to format this (allegedly) correct snippet leads to this:

dosomething $(# exclude all unnecessary files` \
        -f \
                -b
) \
        -c \
        -d # more important things`           \

I know it is somewhat of a special case but it changes the logic in the worst case.

[1] https://stackoverflow.com/questions/9522631/how-to-put-a-line-comment-for-a-multi-line-command#answer-12797512

mvdan commented 2 years ago

I'm fairly sure that master already supports these "inline comments" using backticks; see https://github.com/mvdan/sh/issues/636#issuecomment-1097851426. Please say if I got that wrong and I'm happy to reopen.