Skip to content
Merged
Show file tree
Hide file tree
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
8 changes: 8 additions & 0 deletions cmd/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package cmd
import (
"fmt"
"io"
"io/fs"
"os"

"github.com/spf13/cobra"
Expand Down Expand Up @@ -87,6 +88,7 @@ func checkModules(params checkParams, args []string) error {
WithSkipBundleVerification(true).
WithProcessAnnotation(true).
WithCapabilities(capabilities).
WithFilter(filterFromPaths(params.ignore)).
AsBundle(path)
if err != nil {
return err
Expand Down Expand Up @@ -130,6 +132,12 @@ func checkModules(params checkParams, args []string) error {
return nil
}

func filterFromPaths(paths []string) loader.Filter {
return func(abspath string, info fs.FileInfo, depth int) bool {
return loaderFilter{Ignore: paths}.Apply(abspath, info, depth)
}
}

func outputErrors(format string, err error) {
var out io.Writer
if err != nil {
Expand Down
21 changes: 21 additions & 0 deletions cmd/check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,27 @@ func TestCheckIgnoresNonRegoFiles(t *testing.T) {
})
}

func TestCheckIgnoreBundleMode(t *testing.T) {
t.Parallel()

files := map[string]string{
"ignore.rego": `invalid rego`,
"include.rego": `package valid`,
}

test.WithTempFS(files, func(root string) {
params := newCheckParams()

params.ignore = []string{"ignore.rego"}
params.bundleMode = true

err := checkModules(params, []string{root})
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
})
}

func TestCheckFailsOnInvalidRego(t *testing.T) {
files := map[string]string{
"test.rego": `package test
Expand Down