Skip to content

Commit

Permalink
Fix false positive in unresolved-import and map rules (#680)
Browse files Browse the repository at this point in the history
Thanks @nevumx for reporting this

Signed-off-by: Anders Eknert <[email protected]>
  • Loading branch information
anderseknert authored Apr 25, 2024
1 parent 55a1294 commit 0cb54f0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion bundle/regal/rules/imports/unresolved_import.rego
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ custom_regal_package_and_import(pkg_path, path) if {
# the package part will always be included exported refs
# but if we have a rule like foo.bar.baz
# we'll want to include both foo.bar and foo.bar.baz
to_paths(pkg_path, ref) := [to_path(pkg_path, ref)] if count(ref) < 3
to_paths(pkg_path, ref) := util.all_paths(to_path(pkg_path, ref)) if count(ref) < 3

to_paths(pkg_path, ref) := paths if {
count(ref) > 2
Expand Down
18 changes: 18 additions & 0 deletions bundle/regal/rules/imports/unresolved_import_test.rego
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,24 @@ test_success_resolved_import_in_middle_of_explicit_paths if {
r == set()
}

test_success_map_rule_resolves if {
agg1 := rule.aggregate with input as regal.parse_module("p1.rego", `package foo
import data.bar.x
`)

agg2 := rule.aggregate with input as regal.parse_module("p2.rego", `package bar
import rego.v1
x[y] := z if {
some y in input.ys
z := {"foo": y + 1}
}
`)

r := rule.aggregate_report with input as {"aggregate": (agg1 | agg2)}
r == set()
}

test_success_map_rule_may_resolve_so_allow if {
agg1 := rule.aggregate with input as regal.parse_module("p1.rego", `package foo
import data.bar.x.y
Expand Down

0 comments on commit 0cb54f0

Please sign in to comment.