Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🧹 improve bundle formatter #670

Merged
merged 1 commit into from
Aug 1, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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