Skip to content

Commit 6bb4a4b

Browse files
committed
pass the parser around
1 parent 9eecc29 commit 6bb4a4b

File tree

5 files changed

+15
-13
lines changed

5 files changed

+15
-13
lines changed

cmd/lint.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package cmd
22

33
import (
44
"fmt"
5+
"github.com/bruin-data/bruin/pkg/sqlparser"
56
"io"
67
"os"
78
path2 "path"
@@ -108,7 +109,12 @@ func Lint(isDebug *bool) *cli.Command {
108109

109110
logger.Debugf("built the connection manager instance")
110111

111-
rules, err := lint.GetRules(fs, &git.RepoFinder{}, c.Bool("exclude-warnings"))
112+
parser, err := sqlparser.NewSQLParser()
113+
if err != nil {
114+
printError(err, c.String("output"), "Could not initialize sql parser")
115+
}
116+
117+
rules, err := lint.GetRules(fs, &git.RepoFinder{}, c.Bool("exclude-warnings"), parser)
112118
if err != nil {
113119
printError(err, c.String("output"), "An error occurred while building the validation rules")
114120

cmd/run.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package cmd
33
import (
44
"context"
55
"fmt"
6+
"github.com/bruin-data/bruin/pkg/sqlparser"
67
"io"
78
"log"
89
"os"
@@ -267,7 +268,12 @@ func Run(isDebug *bool) *cli.Command {
267268
infoPrinter.Printf("Running only the asset '%s'\n", task.Name)
268269
}
269270

270-
rules, err := lint.GetRules(fs, &git.RepoFinder{}, true)
271+
parser, err := sqlparser.NewSQLParser()
272+
if err != nil {
273+
printError(err, c.String("output"), "Could not initialize sql parser")
274+
}
275+
276+
rules, err := lint.GetRules(fs, &git.RepoFinder{}, true, parser)
271277
if err != nil {
272278
errorPrinter.Printf("An error occurred while linting the pipelines: %v\n", err)
273279
return cli.Exit("", 1)

go.mod

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ require (
88
cloud.google.com/go/bigquery v1.60.0
99
github.com/DATA-DOG/go-sqlmock v1.5.0
1010
github.com/alecthomas/chroma/v2 v2.13.0
11-
github.com/cenkalti/backoff v2.2.1+incompatible
1211
github.com/charmbracelet/bubbletea v1.1.2
1312
github.com/databricks/databricks-sql-go v1.6.0
1413
github.com/denisbrodbeck/machineid v1.0.1

go.sum

-2
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,6 @@ github.com/bahlo/generic-list-go v0.2.0/go.mod h1:2KvAjgMlE5NNynlg/5iLrrCCZ2+5xW
109109
github.com/buger/jsonparser v1.1.1 h1:2PnMjfWD7wBILjqQbt530v576A/cAbQvEW9gGIpYMUs=
110110
github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0=
111111
github.com/cactus/go-statsd-client/statsd v0.0.0-20200423205355-cb0885a1018c/go.mod h1:l/bIBLeOl9eX+wxJAzxS4TveKRtAqlyDpHjhkfO0MEI=
112-
github.com/cenkalti/backoff v2.2.1+incompatible h1:tNowT99t7UNflLxfYYSlKYsBpXdEet03Pg2g16Swow4=
113-
github.com/cenkalti/backoff v2.2.1+incompatible/go.mod h1:90ReRw6GdpyfrHakVjL/QHaoyV4aDUVVkXQJJJ3NXXM=
114112
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
115113
github.com/charmbracelet/bubbletea v1.1.2 h1:naQXF2laRxyLyil/i7fxdpiz1/k06IKquhm4vBfHsIc=
116114
github.com/charmbracelet/bubbletea v1.1.2/go.mod h1:9HIU/hBV24qKjlehyj8z1r/tR9TYTQEag+cWZnuXo8E=

pkg/lint/list.go

+1-8
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ import (
66
"github.com/bruin-data/bruin/pkg/git"
77
"github.com/bruin-data/bruin/pkg/glossary"
88
"github.com/bruin-data/bruin/pkg/jinja"
9-
"github.com/bruin-data/bruin/pkg/sqlparser"
10-
"github.com/pkg/errors"
119
"github.com/samber/lo"
1210
"github.com/spf13/afero"
1311
)
@@ -16,19 +14,14 @@ type repoFinder interface {
1614
Repo(path string) (*git.Repo, error)
1715
}
1816

19-
func GetRules(fs afero.Fs, finder repoFinder, excludeWarnings bool) ([]Rule, error) {
17+
func GetRules(fs afero.Fs, finder repoFinder, excludeWarnings bool, parser sqlParser) ([]Rule, error) {
2018
gr := GlossaryChecker{
2119
gr: &glossary.GlossaryReader{
2220
RepoFinder: finder,
2321
FileNames: []string{"glossary.yml", "glossary.yaml"},
2422
},
2523
}
2624

27-
parser, err := sqlparser.NewSQLParser()
28-
if err != nil {
29-
return make([]Rule, 0), errors.Wrap(err, "failed to instantiate sql parser")
30-
}
31-
3225
rules := []Rule{
3326
&SimpleRule{
3427
Identifier: "task-name-valid",

0 commit comments

Comments
 (0)