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
6.99k stars 333 forks source link

syntax: remove backslash-newline-semicolon when it's unnecessary #959

Open mvdan opened 1 year ago

mvdan commented 1 year ago

Take this piece of shell:

$ cat f.sh
if
    true \
    ; then
    echo yes
fi
$ bash f.sh
yes
$ shfmt f.sh
if
    true \
        ;
then
    echo yes
fi

Note how it runs, but shfmt didn't improve it that much. It could do better, instead producing:

$ cat f2.sh
if
    true
then
    echo yes
fi
$ bash f2.sh 
yes
$ shfmt f2.sh
if
    true
then
    echo yes
fi