Skip to content

Commit be6d167

Browse files
committed
Fixup comment at start of run
1 parent f202b5d commit be6d167

File tree

7 files changed

+47
-5
lines changed

7 files changed

+47
-5
lines changed

cmd/version.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ var versionCmd = &cobra.Command{
1414
Use: "version",
1515
Short: "Print the version number of dockerfmt",
1616
Run: func(cmd *cobra.Command, args []string) {
17-
fmt.Println("dockerfmt 0.3.3")
17+
fmt.Println("dockerfmt 0.3.4")
1818
},
1919
}

js/format.wasm

-2.43 KB
Binary file not shown.

js/package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@reteps/dockerfmt",
3-
"version": "0.3.3",
3+
"version": "0.3.4",
44
"type": "module",
55
"description": "",
66
"repository": "git+https://github.com/reteps/dockerfmt/tree/main/js",

lib/format.go

+11-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"log"
99
"os"
1010
"regexp"
11+
"slices"
1112
"strings"
1213

1314
"github.com/google/shlex"
@@ -313,10 +314,15 @@ func formatShell(content string, hereDoc bool, c *Config) string {
313314
lines := strings.SplitAfter(content, "\n")
314315
prevIsComment := false
315316
prevCommentSpacing := ""
317+
firstLineIsComment := false
316318
for i := range lines {
317319
lineTrim := strings.TrimLeft(lines[i], " \t")
318320
// fmt.Printf("LineTrim: %s, %v\n", lineTrim, prevIsComment)
319321
if len(lineTrim) >= 1 && lineTrim[0] == '#' {
322+
if i == 0 {
323+
firstLineIsComment = true
324+
lines[i] = strings.Repeat(" ", int(c.IndentSize)) + lineTrim
325+
}
320326
lineParts := strings.SplitN(lines[i], "#", 2)
321327

322328
if prevIsComment {
@@ -329,6 +335,10 @@ func formatShell(content string, hereDoc bool, c *Config) string {
329335
prevIsComment = false
330336
}
331337
}
338+
// TODO: this formatting isn't perfect (see tests/out/run5.dockerfile)
339+
if firstLineIsComment {
340+
lines = slices.Insert(lines, 0, "\\\n")
341+
}
332342
content = strings.Join(lines, "")
333343
content = strings.ReplaceAll(content, "×", "`")
334344

@@ -387,7 +397,7 @@ func GetHeredoc(n *ExtendedNode) (string, bool) {
387397
return "", false
388398
}
389399

390-
printAST(n, 0)
400+
// printAST(n, 0)
391401
args := []string{}
392402
cur := n.Next
393403
for cur != nil {

tests/in/run5.dockerfile

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# https://github.com/un-ts/prettier/issues/441#issuecomment-2793674631
2+
FROM ghcr.io/zerocluster/node/app
3+
4+
RUN \
5+
# install dependencies
6+
NODE_ENV=production npm install-clean \
7+
\
8+
# cleanup
9+
&& /usr/bin/env bash <(curl -fsSL https://raw.githubusercontent.com/softvisio/scripts/main/env-build-node.sh) cleanup
10+
11+
RUN \
12+
# install dependencies
13+
# multiline comment
14+
NODE_ENV=production npm install-clean \
15+
\
16+
# cleanup
17+
&& /usr/bin/env bash <(curl -fsSL https://raw.githubusercontent.com/softvisio/scripts/main/env-build-node.sh) cleanup

tests/out/run5.dockerfile

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# https://github.com/un-ts/prettier/issues/441#issuecomment-2793674631
2+
FROM ghcr.io/zerocluster/node/app
3+
4+
RUN \
5+
# install dependencies
6+
NODE_ENV=production npm install-clean \
7+
# cleanup
8+
&& /usr/bin/env bash <(curl -fsSL https://raw.githubusercontent.com/softvisio/scripts/main/env-build-node.sh) cleanup
9+
10+
RUN \
11+
# install dependencies
12+
# multiline comment
13+
NODE_ENV=production npm install-clean \
14+
# cleanup
15+
&& /usr/bin/env bash <(curl -fsSL https://raw.githubusercontent.com/softvisio/scripts/main/env-build-node.sh) cleanup

0 commit comments

Comments
 (0)