Skip to content

Commit

Permalink
chore: Use regal's parse options following (#1355)
Browse files Browse the repository at this point in the history
#1354

Signed-off-by: Charlie Egan <[email protected]>
  • Loading branch information
charlieegan3 authored Jan 21, 2025
1 parent bea7398 commit 0a17534
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
8 changes: 6 additions & 2 deletions internal/explorer/stages.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/open-policy-agent/opa/v1/ir"

compile2 "github.com/styrainc/regal/internal/compile"
"github.com/styrainc/regal/internal/parse"
)

type CompileResult struct {
Expand Down Expand Up @@ -73,7 +74,10 @@ func CompilerStages(path, rego string, useStrict, useAnno, usePrint bool) []Comp
Stage: "ParseModule",
})

mod, err := ast.ParseModuleWithOpts(path, rego, ast.ParserOptions{ProcessAnnotation: useAnno})
opts := parse.ParserOptions()
opts.ProcessAnnotation = useAnno

mod, err := ast.ParseModuleWithOpts(path, rego, opts)
if err != nil {
result[0].Error = err.Error()

Expand Down Expand Up @@ -124,7 +128,7 @@ func getOne(mods map[string]*ast.Module) *ast.Module {
}

func Plan(ctx context.Context, path, rego string, usePrint bool) (string, error) {
mod, err := ast.ParseModuleWithOpts(path, rego, ast.ParserOptions{ProcessAnnotation: true})
mod, err := ast.ParseModuleWithOpts(path, rego, parse.ParserOptions())
if err != nil {
return "", err //nolint:wrapcheck
}
Expand Down
9 changes: 6 additions & 3 deletions pkg/rules/rules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"testing"

"github.com/open-policy-agent/opa/v1/ast"

"github.com/styrainc/regal/internal/parse"
)

func TestInputFromTextWithOptions(t *testing.T) {
Expand All @@ -29,9 +31,10 @@ p { true }`,
t.Run(name, func(t *testing.T) {
t.Parallel()

_, err := InputFromTextWithOptions("p.rego", tc.Module, ast.ParserOptions{
RegoVersion: tc.RegoVersion,
})
opts := parse.ParserOptions()
opts.RegoVersion = tc.RegoVersion

_, err := InputFromTextWithOptions("p.rego", tc.Module, opts)
if err != nil {
t.Errorf("Expected no error, got %v", err)
}
Expand Down

0 comments on commit 0a17534

Please sign in to comment.