Repository: patrickhoefler/dockerfilegraph
Pull request #313 (2023-03-23 20:41:42)

Fix linting errors


Patch:
diff --git a/internal/dockerfile2dot/build.go b/internal/dockerfile2dot/build.go
index 0f20f6e..6595d40 100644
--- a/internal/dockerfile2dot/build.go
+++ b/internal/dockerfile2dot/build.go
@@ -159,12 +159,12 @@ func addEdgesForStage(
 		}
 
 		edgeAttrs := map[string]string{}
-		if layer.WaitFor.Type == waitForType(copy) {
+		if layer.WaitFor.Type == waitForType(waitForCopy) {
 			edgeAttrs["arrowhead"] = "empty"
 			if edgestyle == "default" {
 				edgeAttrs["style"] = "dashed"
 			}
-		} else if layer.WaitFor.Type == waitForType(runMountTypeCache) {
+		} else if layer.WaitFor.Type == waitForType(waitForCache) {
 			edgeAttrs["arrowhead"] = "ediamond"
 			if edgestyle == "default" {
 				edgeAttrs["style"] = "dotted"
diff --git a/internal/dockerfile2dot/convert.go b/internal/dockerfile2dot/convert.go
index cafc7e2..a918c1e 100644
--- a/internal/dockerfile2dot/convert.go
+++ b/internal/dockerfile2dot/convert.go
@@ -65,7 +65,7 @@ func dockerfileToSimplifiedDockerfile(
 			// Set the waitFor ID
 			layer.WaitFor = WaitFor{
 				Name: replaceArgVars(child.Next.Value, argReplacements),
-				Type: waitForType(from),
+				Type: waitForType(waitForFrom),
 			}
 
 			simplifiedDockerfile.Stages[stageIndex].Layers = append(
@@ -85,7 +85,7 @@ func dockerfileToSimplifiedDockerfile(
 				if len(result) > 1 {
 					layer.WaitFor = WaitFor{
 						Name: string(result[1]),
-						Type: waitForType(copy),
+						Type: waitForType(waitForCopy),
 					}
 				}
 			}
@@ -107,7 +107,7 @@ func dockerfileToSimplifiedDockerfile(
 				if len(result) > 1 {
 					layer.WaitFor = WaitFor{
 						Name: string(result[1]),
-						Type: waitForType(runMountTypeCache),
+						Type: waitForType(waitForCache),
 					}
 				}
 			}
diff --git a/internal/dockerfile2dot/structs.go b/internal/dockerfile2dot/structs.go
index ffd388d..1508b4a 100644
--- a/internal/dockerfile2dot/structs.go
+++ b/internal/dockerfile2dot/structs.go
@@ -34,9 +34,9 @@ type ExternalImage struct {
 type waitForType int
 
 const (
-	copy waitForType = iota
-	from
-	runMountTypeCache
+	waitForCopy waitForType = iota
+	waitForFrom
+	waitForCache
 )
 
 // WaitFor holds the name of the stage or external image for which the builder


Test patch:
diff --git a/internal/dockerfile2dot/build_test.go b/internal/dockerfile2dot/build_test.go
index 34ad29b..a7b5877 100644
--- a/internal/dockerfile2dot/build_test.go
+++ b/internal/dockerfile2dot/build_test.go
@@ -41,7 +41,7 @@ func TestBuildDotFile(t *testing.T) {
 									Label: "FROM...",
 									WaitFor: WaitFor{
 										Name: "build",
-										Type: waitForType(from),
+										Type: waitForType(waitForFrom),
 									},
 								},
 							},
@@ -76,7 +76,7 @@ func TestBuildDotFile(t *testing.T) {
 									Label: "FROM...",
 									WaitFor: WaitFor{
 										Name: "build",
-										Type: waitForType(from),
+										Type: waitForType(waitForFrom),
 									},
 								},
 							},
diff --git a/internal/dockerfile2dot/convert_test.go b/internal/dockerfile2dot/convert_test.go
index 33e871c..9a8bfb5 100644
--- a/internal/dockerfile2dot/convert_test.go
+++ b/internal/dockerfile2dot/convert_test.go
@@ -31,7 +31,7 @@ func Test_dockerfileToSimplifiedDockerfile(t *testing.T) {
 						Layers: []Layer{
 							{
 								Label:   "FROM scratch",
-								WaitFor: WaitFor{Name: "scratch", Type: waitForType(from)}},
+								WaitFor: WaitFor{Name: "scratch", Type: waitForType(waitForFrom)}},
 						},
 					},
 				},
@@ -61,7 +61,7 @@ RUN --mount=type=cache,from=buildcache,source=/go/pkg/mod/cache/,target=/go/pkg/
 						Layers: []Layer{
 							{
 								Label:   "FROM ubuntu as base",
-								WaitFor: WaitFor{Name: "ubuntu", Type: waitForType(from)},
+								WaitFor: WaitFor{Name: "ubuntu", Type: waitForType(waitForFrom)},
 							},
 						},
 					},
@@ -69,15 +69,15 @@ RUN --mount=type=cache,from=buildcache,source=/go/pkg/mod/cache/,target=/go/pkg/
 						Layers: []Layer{
 							{
 								Label:   "FROM scratch",
-								WaitFor: WaitFor{Name: "scratch", Type: waitForType(from)},
+								WaitFor: WaitFor{Name: "scratch", Type: waitForType(waitForFrom)},
 							},
 							{
 								Label:   "COPY --from=base . .",
-								WaitFor: WaitFor{Name: "base", Type: waitForType(copy)},
+								WaitFor: WaitFor{Name: "base", Type: waitForType(waitForCopy)},
 							},
 							{
 								Label:   "RUN --mount=type=...",
-								WaitFor: WaitFor{Name: "buildcache", Type: waitForType(runMountTypeCache)},
+								WaitFor: WaitFor{Name: "buildcache", Type: waitForType(waitForCache)},
 							},
 						},
 					},
@@ -117,7 +117,7 @@ RUN --mount=type=cache,source=/go/pkg/mod/cache/,target=/go/pkg/mod/cache/,from=
 						Layers: []Layer{
 							{
 								Label:   "FROM ubuntu:22.04...",
-								WaitFor: WaitFor{Name: "ubuntu:22.04", Type: waitForType(from)},
+								WaitFor: WaitFor{Name: "ubuntu:22.04", Type: waitForType(waitForFrom)},
 							},
 							{
 								Label: "USER app",
@@ -131,7 +131,7 @@ RUN --mount=type=cache,source=/go/pkg/mod/cache/,target=/go/pkg/mod/cache/,from=
 								Label: "FROM php:8.0-fpm-...",
 								WaitFor: WaitFor{
 									Name: "php:8.0-fpm-alpine3.15",
-									Type: waitForType(from),
+									Type: waitForType(waitForFrom),
 								},
 							},
 						},
@@ -140,15 +140,15 @@ RUN --mount=type=cache,source=/go/pkg/mod/cache/,target=/go/pkg/mod/cache/,from=
 						Layers: []Layer{
 							{
 								Label:   "FROM scratch",
-								WaitFor: WaitFor{Name: "scratch", Type: waitForType(from)},
+								WaitFor: WaitFor{Name: "scratch", Type: waitForType(waitForFrom)},
 							},
 							{
 								Label:   "COPY --from=base . .",
-								WaitFor: WaitFor{Name: "base", Type: waitForType(copy)},
+								WaitFor: WaitFor{Name: "base", Type: waitForType(waitForCopy)},
 							},
 							{
 								Label:   "RUN --mount=type=...",
-								WaitFor: WaitFor{Name: "buildcache", Type: waitForType(runMountTypeCache)},
+								WaitFor: WaitFor{Name: "buildcache", Type: waitForType(waitForCache)},
 							},
 						},
 					},
@@ -191,7 +191,7 @@ COPY --from=download-get-pip get-pip.py ./
 								Label: "FROM scratch AS d...",
 								WaitFor: WaitFor{
 									Name: "scratch",
-									Type: waitForType(from),
+									Type: waitForType(waitForFrom),
 								},
 							},
 							{Label: "ADD https://deb.n..."},
@@ -204,7 +204,7 @@ COPY --from=download-get-pip get-pip.py ./
 								Label: "FROM scratch AS d...",
 								WaitFor: WaitFor{
 									Name: "scratch",
-									Type: waitForType(from),
+									Type: waitForType(waitForFrom),
 								}},
 							{Label: "ADD https://boots..."},
 						},
@@ -216,21 +216,21 @@ COPY --from=download-get-pip get-pip.py ./
 								Label: "FROM alpine AS final",
 								WaitFor: WaitFor{
 									Name: "alpine",
-									Type: waitForType(from),
+									Type: waitForType(waitForFrom),
 								},
 							},
 							{
 								Label: "COPY --from=downl...",
 								WaitFor: WaitFor{
 									Name: "download-node-setup",
-									Type: waitForType(copy),
+									Type: waitForType(waitForCopy),
 								},
 							},
 							{
 								Label: "COPY --from=downl...",
 								WaitFor: WaitFor{
 									Name: "download-get-pip",
-									Type: waitForType(copy),
+									Type: waitForType(waitForCopy),
 								},
 							},
 						},
diff --git a/internal/dockerfile2dot/load_test.go b/internal/dockerfile2dot/load_test.go
index 05a0cfd..65280f2 100644
--- a/internal/dockerfile2dot/load_test.go
+++ b/internal/dockerfile2dot/load_test.go
@@ -45,7 +45,7 @@ func TestLoadAndParseDockerfile(t *testing.T) {
 						Layers: []Layer{
 							{
 								Label:   "FROM scratch",
-								WaitFor: WaitFor{Name: "scratch", Type: waitForType(from)}},
+								WaitFor: WaitFor{Name: "scratch", Type: waitForType(waitForFrom)}},
 						},
 					},
 				},
@@ -65,7 +65,7 @@ func TestLoadAndParseDockerfile(t *testing.T) {
 						Layers: []Layer{
 							{
 								Label:   "FROM scratch",
-								WaitFor: WaitFor{Name: "scratch", Type: waitForType(from)}},
+								WaitFor: WaitFor{Name: "scratch", Type: waitForType(waitForFrom)}},
 						},
 					},
 				},