Skip to content

Commit

Permalink
🧹 improve bundle formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-rock committed Jul 31, 2023
1 parent 4c2f4c8 commit 49753d0
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions internal/bundle/fmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"encoding/json"
"os"
"strings"

"github.com/cockroachdb/errors"
"github.com/rs/zerolog/log"
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 49753d0

Please sign in to comment.