Skip to content

Commit

Permalink
Fix top-level-iteration false positive with ref head vars (#854)
Browse files Browse the repository at this point in the history
Fixes #852

Signed-off-by: Anders Eknert <[email protected]>
  • Loading branch information
anderseknert committed Jun 19, 2024
1 parent 0536573 commit d3dad61
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
7 changes: 7 additions & 0 deletions bundle/regal/rules/bugs/top_level_iteration.rego
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ import data.regal.result
report contains violation if {
some rule in input.rules

# skip if vars in the ref head
count([part |
some i, part in rule.head.ref
i > 0
part.type == "var"
]) == 0

rule.head.value.type == "ref"

last := regal.last(rule.head.value.value)
Expand Down
6 changes: 6 additions & 0 deletions bundle/regal/rules/bugs/top_level_iteration_test.rego
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ test_success_top_level_known_var_ref if {
r == set()
}

# https://github.com/StyraInc/regal/issues/852
test_success_top_level_ref_head_vars_assignment if {
r := rule.report with input as ast.with_rego_v1(`foo[x] := input[x] if some x in [1, 2, 3]`)
r == set()
}

# https://github.com/StyraInc/regal/issues/401
test_success_top_level_input_assignment if {
r := rule.report with input as ast.with_rego_v1(`x := input`)
Expand Down

0 comments on commit d3dad61

Please sign in to comment.