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
with shfmt -i0 (because those are tabs, take care when copying). The actual content of the nested heredoc is completely deindented, and the INNER end marker is indented too far (seems to gain an extra tab for every line in the inner heredoc).
I'm not in a hurry, but this seems wrong. shfmt support is important enough for me that I wont use this construct until it works 😄. Once again thanks for the project, and maybe for fixing this!
What seems to happen is the extraIndenter has an embedded bufWriter of which the Write method is called by (e *extraIndenter) WriteByte(b byte). I added an override which forwards it to the WriteByte method like WriteString. I have to be honest, I don't know exactly why it happens on a nested heredoc only. I saw the policy on LLM PR's and this is a bit of skirting the line, as I wrote the code myself, but the debugging was assisted. It does fix the issue, without breaking any tests.
diff --git i/syntax/printer.go w/syntax/printer.go
index d11e6146..3678b6ab 100644
--- i/syntax/printer.go+++ w/syntax/printer.go@@ -1620,6 +1620,13 @@ func (e *extraIndenter) WriteString(s string) (int, error) {
return len(s), nil
}
+func (e *extraIndenter) Write(b []byte) (int, error) {+ for i := range len(b) {+ e.WriteByte(b[i])+ }+ return len(b), nil+}+
func startsWithLparen(node Node) bool {
switch node := node.(type) {
case *Stmt:
diff --git i/syntax/printer_test.go w/syntax/printer_test.go
index a3231b03..ae23a93c 100644
--- i/syntax/printer_test.go+++ w/syntax/printer_test.go@@ -544,6 +544,7 @@ var printTests = []printCase{
"f <<-EOF\n\t{\n\t\ttoo little indented\n\t}\nEOF",
},
samePrint("<<-EOF\n\t$foo\nEOF\n\n{\n\tbar\n}"),
+ samePrint("f <<-A\n\ta $(\n\t\tg <<-B\n\t\t\tb1\n\t\t\tb2\n\t\tB\n\t)\nA"),
samePrint("f <<EOF\nEOF\n# comment"),
samePrint("f <<EOF\nEOF\n# comment\nbar"),
samePrint("f <<EOF # inline\n$(\n\t# inside\n)\nEOF\n# outside\nbar"),
Thanks! Please feel free to send a PR, if your model is convinced that this solution is right (and why). The guidance against PRs are aimed at github users who send PRs indiscriminately to resolve existing issues, aiming only to pad their resumes.
Fascinating what happened there. Anyway, I now fully understand the change I made and why it was necessary, and made a pull request. Thanks for the comments!
Activity
milhnl commentedon Aug 28, 2026
What seems to happen is the
extraIndenterhas an embeddedbufWriterof which theWritemethod is called by(e *extraIndenter) WriteByte(b byte). I added an override which forwards it to theWriteBytemethod likeWriteString. I have to be honest, I don't know exactly why it happens on a nested heredoc only. I saw the policy on LLM PR's and this is a bit of skirting the line, as I wrote the code myself, but the debugging was assisted. It does fix the issue, without breaking any tests.mvdan commentedon Aug 28, 2026
Thanks! Please feel free to send a PR, if your model is convinced that this solution is right (and why). The guidance against PRs are aimed at github users who send PRs indiscriminately to resolve existing issues, aiming only to pad their resumes.
milhnl commentedon Aug 31, 2026
Fascinating what happened there. Anyway, I now fully understand the change I made and why it was necessary, and made a pull request. Thanks for the comments!
syntax: fix nested heredoc indentation
syntax: fix nested heredoc indentation