From 94dbc96105ec2786b8c67681eaf2e4e9e9bb0e07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patryk=20Ma=C5=82ek?= Date: Thu, 7 Nov 2024 16:11:25 +0100 Subject: [PATCH] ci: add prealloc to linter rules --- .golangci.yml | 1 + cmd/gateway_dump.go | 2 +- kong2kic/route.go | 2 +- kong2tf/generate_resource.go | 2 +- 4 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 5e40286e3..665e57207 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -27,6 +27,7 @@ linters: - nilerr - nolintlint - predeclared + - prealloc - revive - stylecheck - unconvert diff --git a/cmd/gateway_dump.go b/cmd/gateway_dump.go index 9e63931e1..f37e15ad6 100644 --- a/cmd/gateway_dump.go +++ b/cmd/gateway_dump.go @@ -30,7 +30,7 @@ func listWorkspaces(ctx context.Context, client *kong.Client) ([]string, error) if err != nil { return nil, fmt.Errorf("fetching workspaces from Kong: %w", err) } - var res []string + res := make([]string, 0, len(workspaces)) for _, workspace := range workspaces { res = append(res, *workspace.Name) } diff --git a/kong2kic/route.go b/kong2kic/route.go index 0c014c7ea..2f71a463d 100644 --- a/kong2kic/route.go +++ b/kong2kic/route.go @@ -87,7 +87,7 @@ func createIngressPaths( servicePort *int, pathType k8snetv1.PathType, ) []k8snetv1.HTTPIngressPath { - var paths []k8snetv1.HTTPIngressPath + paths := make([]k8snetv1.HTTPIngressPath, 0, len(route.Paths)) for _, path := range route.Paths { sCopy := *path if strings.HasPrefix(sCopy, "~") { diff --git a/kong2tf/generate_resource.go b/kong2tf/generate_resource.go index 1e293cfca..2e0fac1e0 100644 --- a/kong2tf/generate_resource.go +++ b/kong2tf/generate_resource.go @@ -219,7 +219,7 @@ func generateParents(parents map[string]string) string { return "" } - var result []string + result := make([]string, 0, len(parents)) for k, v := range parents { v = strings.ReplaceAll(v, "-", "_") // if parent ends with _id, use it as-is