Repository navigation
fix(run): preserve empty continuation lines and comments among flags - #82
Merged
Merged
Conversation
Lines holding only a backslash, used as visual separators inside long RUN instructions, were dropped wherever mvdan/sh's printer drops them: before a line starting with "&&" and at the start of the content (right after the flags). Comments placed before or between RUN flags were dropped too, because flags are rebuilt from the parsed n.Flags. - Shell content: turn each empty continuation line into a marker comment before shfmt (the comment placeholders already survive every position) and back into a "\\" line afterwards, aligned with the next line. A "\\" line with no surrounding whitespace joins two words, so it is left alone. - Flags region: scan the original source for comment and empty continuation lines among the flags and re-emit them, one item per line. Without such lines the existing flag layout is unchanged. - Drop the redundant continuation the comment handling added after flags that already end in " \\", which produced a stray "\\" line. tests/out/run5.dockerfile now keeps its separator line. Fixes #59 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
4 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #59.
\alone) in the shell body are preserved in every position, including before&&lines and right after the flags. This uses the approach suggested in the issue: each one becomes a marker comment placeholder for the shfmt pass and is turned back into\afterwards, aligned with the following line. A\line with no whitespace around it (good\/\/night) joins two words into one, so it is left alone. That case came from buildkit's owncontinueIndenttest file.\lines before or between RUN flags are preserved. The original source is scanned from the keyword throughn.Flags. When such lines exist, each item goes on its own line. Otherwise the existing flag layout is untouched.\line that appeared when a comment followed the flags.Behavior change
tests/out/run5.dockerfilenow keeps its\line before# cleanup, as #59 asks.Test plan
tests/in/empty-continuation.dockerfilecovers every case from the issue plus pipes/||, non-mount flags, trailing whitespace, CMD, and glued words. Its output is idempotent.scanFlagsRegionandisEmptyContinuationrun5.go test ./...🤖 Generated with Claude Code