From 49753d07d2bc9fe375b588a246b9471f588dfb10 Mon Sep 17 00:00:00 2001 From: Christoph Hartmann Date: Tue, 1 Aug 2023 00:59:28 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=B9=20improve=20bundle=20formatter?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/bundle/fmt.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/internal/bundle/fmt.go b/internal/bundle/fmt.go index 58e7660a..2d7910b1 100644 --- a/internal/bundle/fmt.go +++ b/internal/bundle/fmt.go @@ -4,6 +4,7 @@ import ( "bytes" "encoding/json" "os" + "strings" "github.com/cockroachdb/errors" "github.com/rs/zerolog/log" @@ -96,6 +97,18 @@ func FormatFile(filename string) error { } b, err := ParseYaml(data) + + // to improve the formatting we need to remove the whitespace at the end of the lines + // this is a bit hacky, but it works + for i := range b.Queries { + mql := b.Queries[i].Mql + lines := strings.Split(mql, "\n") + for j := range lines { + lines[j] = strings.TrimRight(lines[j], " ") + } + b.Queries[i].Mql = strings.Join(lines, "\n") + } + // we have v7 structs in v8 bundle, so it can happen that v7 parses properly // for that case we need to make sure all the structs are properly converted if err != nil || hasV7Structs(b) {