From 28776bad7f818988cb4c8bc8b54b1b6d43137b7a Mon Sep 17 00:00:00 2001 From: Janpreet Singh Date: Mon, 29 Jul 2024 23:26:11 -0400 Subject: [PATCH] Code changes --- main.go | 2 +- packages/engine/formatter.go | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/main.go b/main.go index e228d17..517bff8 100644 --- a/main.go +++ b/main.go @@ -15,7 +15,7 @@ import ( "github.com/janpreet/kado/packages/opa" "github.com/janpreet/kado/packages/render" "github.com/janpreet/kado/packages/terraform" - "github.com/janpreet/kado/packages/terragrunt" // Import the new package + "github.com/janpreet/kado/packages/terragrunt" ) func convertYAMLToSlice(yamlData map[string]interface{}) []map[string]interface{} { diff --git a/packages/engine/formatter.go b/packages/engine/formatter.go index dfce009..744f696 100644 --- a/packages/engine/formatter.go +++ b/packages/engine/formatter.go @@ -10,7 +10,7 @@ import ( "strings" ) -// FormatKDFile formats a single .kd file with proper indentation and without extra newlines at the end. + func FormatKDFile(filePath string) error { file, err := os.Open(filePath) if err != nil { @@ -45,7 +45,7 @@ func FormatKDFile(filePath string) error { buffer.WriteString(" " + trimmedLine + "\n") } else { if commentRegex.MatchString(trimmedLine) { - // Remove extra spaces in comments + trimmedLine = strings.TrimSpace(trimmedLine) trimmedLine = strings.Replace(trimmedLine, "#", "#", 1) } @@ -64,7 +64,7 @@ func FormatKDFile(filePath string) error { formattedLines = append(formattedLines, buffer.String()) } - // Remove the last newline if it exists + if len(formattedLines) > 0 && formattedLines[len(formattedLines)-1] == "\n" { formattedLines = formattedLines[:len(formattedLines)-1] } @@ -79,7 +79,7 @@ func FormatKDFile(filePath string) error { return nil } -// FormatKDFilesInDir formats all .kd files in a given directory with proper indentation and without extra newlines at the end. + func FormatKDFilesInDir(dir string) error { return filepath.Walk(dir, func(path string, info os.FileInfo, err error) error { if err != nil {