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.97k stars 332 forks source link

shfmt: places ";then" on wrong line when using heredoc as stdin for a command #1047

Open dionysius opened 7 months ago

dionysius commented 7 months ago

shfmt v3.6.0

Before:

#!/bin/bash

if ! lxc launch --vm "$image" "$name" <<EOF
${instance_config}
EOF
then
        lxc delete -f "$name"
fi

After:

#!/bin/bash

if ! lxc launch --vm "$image" "$name" <<EOF; then
${instance_config}
EOF
        lxc delete -f "$name"
fi

It breaks the script and modifies the heredoc content. It should not move the then and keep it on his own line without prepended ;.

Note: Putting the command into the if is recommended by SC2181. Obviously <<<"${instance_config}" can be used but the issue is still present when using heredoc.