Skip to content

Commit da61aca

Browse files
authored
Merge pull request #53 from reteps/fix-onbuild-fmt
2 parents bf2867e + d9fca78 commit da61aca

3 files changed

Lines changed: 28 additions & 0 deletions

File tree

lib/format.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,12 @@ func FormatOnBuild(n *ExtendedNode, c *Config) string {
201201
if len(n.Node.Next.Children) == 1 {
202202
output, ok := FormatNode(n.Next.Children[0], c)
203203
if ok {
204+
// Inner directives nested under ONBUILD have StartLine=0, so their
205+
// OriginalMultiline is empty and formatters that fall back to n.Original
206+
// (which has no trailing newline) produce output without one.
207+
if !strings.HasSuffix(output, "\n") {
208+
output += "\n"
209+
}
204210
return n.directive() + " " + output
205211
}
206212
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
FROM alpine
2+
3+
ONBUILD ARG FOO=bar
4+
5+
RUN echo $FOO
6+
7+
ONBUILD ENV BAR=baz
8+
9+
ONBUILD LABEL foo=bar
10+
11+
RUN echo done
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
FROM alpine
2+
3+
ONBUILD ARG FOO=bar
4+
5+
RUN echo $FOO
6+
7+
ONBUILD ENV BAR=baz
8+
9+
ONBUILD LABEL foo=bar
10+
11+
RUN echo done

0 commit comments

Comments
 (0)