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

Fix false positive in unresolved-import and map rules #680

Merged
merged 1 commit into from
Apr 25, 2024
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
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
Loading