You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
shfmt: places ";then" on wrong line when using heredoc as stdin for a command #1047
#!/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.
Activity
Ledorub commentedon Apr 24, 2025
I'm also facing this issue. The only workaround I found is to disable the SC2181 and check the exit code in a separate if-statement.
jakub-bochenski commentedon May 29, 2025
is it possible to prevent shfmt from reformatting the
if thenstatements?refactor: emit the main.cf body from its own function
chore: pin shfmt 3.14.1 to match local and reformat heredoc ifs