From 6fcb50d164a70f0d90c499d9e61db4b8dca38e95 Mon Sep 17 00:00:00 2001 From: joshAtRula Date: Thu, 12 Dec 2024 15:12:00 -0500 Subject: [PATCH] Append new lines to end of json files before writing --- pkg/utils/json_utils.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pkg/utils/json_utils.go b/pkg/utils/json_utils.go index aeb8ad4b6..c2bfb08db 100644 --- a/pkg/utils/json_utils.go +++ b/pkg/utils/json_utils.go @@ -51,6 +51,11 @@ func WriteToFileAsJSON(filePath string, data any, fileMode os.FileMode) error { return err } + // Ensure that the JSON content ends with a newline + if len(indentedJSON) == 0 || indentedJSON[len(indentedJSON)-1] != '\n' { + indentedJSON = append(indentedJSON, '\n') + } + err = os.WriteFile(filePath, indentedJSON, fileMode) if err != nil { return err