Skip to content

fix: preserve blank line after ONBUILD <directive>#53

Merged
reteps merged 1 commit into
mainfrom
fix-onbuild-fmt
Apr 25, 2026
Merged

fix: preserve blank line after ONBUILD <directive>#53
reteps merged 1 commit into
mainfrom
fix-onbuild-fmt

Conversation

@reteps
Copy link
Copy Markdown
Owner

@reteps reteps commented Apr 25, 2026

Summary

Fixes #52.

Inner directives nested under ONBUILD are parsed by buildkit with StartLine=0/EndLine=0, so their OriginalMultiline is empty. Formatters like formatBasic (ARG, LABEL, USER, …) and formatEnv fall back to n.Original, which has no trailing newline. As a result, FormatOnBuild returned e.g. "ONBUILD ARG FOO=bar" with no trailing \n, and the subsequent blank line + directive collapsed onto the following line.

The fix appends a trailing newline in FormatOnBuild when the formatted inner directive lacks one, which is the invariant every other directive formatter already provides.

Test plan

  • New fixture tests/in/onbuild-blank-lines.dockerfile / tests/out/onbuild-blank-lines.dockerfile covering ONBUILD ARG / ENV / LABEL with blank lines around them
  • go test ./... passes
  • Manually verified the formatter is now idempotent on the repro case from the issue

🤖 Generated with Claude Code

Inner directives nested under ONBUILD are parsed with StartLine=0, so
their OriginalMultiline is empty and formatters like formatBasic/formatEnv
fall back to n.Original, which has no trailing newline. FormatOnBuild
then returned "ONBUILD ARG FOO=bar" without a newline, causing the next
directive (and any blank line separating it) to collapse onto the same
position.

Fixes #52.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@reteps reteps merged commit da61aca into main Apr 25, 2026
3 checks passed
@reteps reteps deleted the fix-onbuild-fmt branch April 25, 2026 03:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ONBUILD formatted incorrectly

1 participant