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.35k stars 346 forks source link

Comments in a subshell are moved every time the formatter runs #1084

Open Ashymad opened 4 months ago

Ashymad commented 4 months ago

Example file.sh:

#!/bin/sh
( # Comment
    true
)

Running shfmt -w -l 1st time produces (2 spaces in front of the comment):

#!/bin/sh
(  # Comment
    true
)

Running shfmt -w -l 2nd time produces (3 spaces in front of the comment):

#!/bin/sh
(   # Comment
    true
)

Every time you run shfmt adds another space in front of the comment, never satisfied with the amount of them.