Skip to content

Commit c6381d1

Browse files
committed
Fix regression in release relating to backticks
1 parent 2b4066e commit c6381d1

File tree

7 files changed

+54
-5
lines changed

7 files changed

+54
-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.1")
17+
fmt.Println("dockerfmt 0.3.2")
1818
},
1919
}

js/format.wasm

353 Bytes
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.1",
3+
"version": "0.3.2",
44
"type": "module",
55
"description": "",
66
"repository": "git+https://github.com/reteps/dockerfmt/tree/main/js",

lib/format.go

+12-1
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,15 @@ func formatShell(content string, hereDoc bool, c *Config) string {
234234
// Replace comments with a subshell evaluation -- they won't be run so we can do this.
235235
content = StripWhitespace(content, true)
236236
lineComment := regexp.MustCompile(`(\n\s*)(#.*)`)
237+
lines := strings.SplitAfter(content, "\n")
238+
for i := range lines {
239+
lineTrim := strings.TrimLeft(lines[i], " \t")
240+
if len(lineTrim) >= 1 && lineTrim[0] == '#' {
241+
lines[i] = strings.ReplaceAll(lines[i], "`", "×")
242+
}
243+
}
244+
content = strings.Join(lines, "")
245+
237246
content = lineComment.ReplaceAllString(content, "$1`$2#`\\")
238247

239248
/*
@@ -254,7 +263,7 @@ func formatShell(content string, hereDoc bool, c *Config) string {
254263
content = commentContinuation.ReplaceAllString(content, "&&$1")
255264

256265
// log.Printf("Content0: %s\n", content)
257-
lines := strings.SplitAfter(content, "\n")
266+
lines = strings.SplitAfter(content, "\n")
258267
/**
259268
if the next line is not a comment, and we didn't start with a continuation, don't add the `&&`.
260269
*/
@@ -293,6 +302,7 @@ func formatShell(content string, hereDoc bool, c *Config) string {
293302
// Now that we have a valid bash-style command, we can format it with shfmt
294303
// log.Printf("Content1: %s\n", content)
295304
content = formatBash(content, c)
305+
296306
// log.Printf("Content2: %s\n", content)
297307

298308
if !hereDoc {
@@ -320,6 +330,7 @@ func formatShell(content string, hereDoc bool, c *Config) string {
320330
}
321331
}
322332
content = strings.Join(lines, "")
333+
content = strings.ReplaceAll(content, "×", "`")
323334

324335
}
325336
return content

tests/in/run4.dockerfile

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
RUN arch="$(uname -m)" \
2+
&& curl -sfLO "https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-Linux-${arch}.sh" \
3+
&& chmod +x "Miniforge3-Linux-${arch}.sh" \
4+
&& ./"Miniforge3-Linux-${arch}.sh" -b -p /home/coder/conda \
5+
# Install conda and mamba hooks for future interactive bash sessions:
6+
&& /home/coder/conda/bin/mamba init bash \
7+
# Activate hooks in the current noninteractive session:
8+
&& . "/home/coder/conda/etc/profile.d/conda.sh" \
9+
&& . "/home/coder/conda/etc/profile.d/mamba.sh" \
10+
&& mamba activate \
11+
# Installing `pygraphviz` with pip would require `build-essentials`, `graphviz`,
12+
# and `graphviz-dev` to be installed at the OS level, which would increase the
13+
# image size. Instead, we install it from Conda, which prebuilds it and also
14+
# automatically installs a Conda-specific `graphviz` dependency.
15+
&& mamba install --yes "$(grep pygraphviz /requirements.txt | head -n 1)" \
16+
&& pip install --no-cache-dir -r /requirements.txt \
17+
&& rm "Miniforge3-Linux-${arch}.sh" \
18+
&& mamba clean --all --yes --quiet \
19+
&& pip cache purge

tests/out/run4.dockerfile

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
RUN arch="$(uname -m)" \
2+
&& curl -sfLO "https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-Linux-${arch}.sh" \
3+
&& chmod +x "Miniforge3-Linux-${arch}.sh" \
4+
&& ./"Miniforge3-Linux-${arch}.sh" -b -p /home/coder/conda \
5+
# Install conda and mamba hooks for future interactive bash sessions:
6+
&& /home/coder/conda/bin/mamba init bash \
7+
# Activate hooks in the current noninteractive session:
8+
&& . "/home/coder/conda/etc/profile.d/conda.sh" \
9+
&& . "/home/coder/conda/etc/profile.d/mamba.sh" \
10+
&& mamba activate \
11+
# Installing `pygraphviz` with pip would require `build-essentials`, `graphviz`,
12+
# and `graphviz-dev` to be installed at the OS level, which would increase the
13+
# image size. Instead, we install it from Conda, which prebuilds it and also
14+
# automatically installs a Conda-specific `graphviz` dependency.
15+
&& mamba install --yes "$(grep pygraphviz /requirements.txt | head -n 1)" \
16+
&& pip install --no-cache-dir -r /requirements.txt \
17+
&& rm "Miniforge3-Linux-${arch}.sh" \
18+
&& mamba clean --all --yes --quiet \
19+
&& pip cache purge

0 commit comments

Comments
 (0)