-
-
Notifications
You must be signed in to change notification settings - Fork 380
Open
Description
Summary
When a heredoc with a trailing comment (e.g., <<-EOF # comment) is inside an indented block, shfmt duplicates the comment after EOF on each run. This is non-idempotent behavior.
Steps to reproduce
$ cat test.sh
#!/bin/bash
if true; then
cat <<-EOF # comment
content
EOF
fi
$ shfmt -w test.sh
$ cat test.sh
#!/bin/bash
if true; then
cat <<-EOF # comment
content
EOF
# comment
fi
$ shfmt -w test.sh
$ cat test.sh
#!/bin/bash
if true; then
cat <<-EOF # comment
content
EOF
# comment
# comment
fiEach invocation adds another copy of the comment.
Environment
- shfmt version: v3.12.0
- OS: Linux (Fedora 42)
Related issues
- syntax: inline comment on a heredoc gets misplaced #623 (closed) was about heredoc inline comments being misplaced
- Comments in a subshell are moved every time the formatter runs #1084 (open) is a similar non-idempotent comment formatting bug (spaces added to subshell comments)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels