Skip to content

Commit

Permalink
Fix unconditional-assignment with else clause
Browse files Browse the repository at this point in the history
To be revisited once the issue in OPA is resolved.

Fixes #178

Signed-off-by: Anders Eknert <anders@styra.com>
  • Loading branch information
anderseknert committed Jun 26, 2023
1 parent cafd6b7 commit 9674e0e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
5 changes: 5 additions & 0 deletions bundle/regal/rules/style/unconditional_assignment.rego
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ report contains violation if {
# a `print` call.. but let's keep it simple for now
count(rule.body) == 1

# Remove this and consider proper handling of else once
# https://github.com/open-policy-agent/opa/issues/5777
# is resolved
not rule["else"]

# Var assignment in rule head
rule.head.value.type == "var"
rule_head_var := rule.head.value.value
Expand Down
7 changes: 7 additions & 0 deletions bundle/regal/rules/style/unconditional_assignment_test.rego
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,10 @@ test_success_unconditional_assignment_but_with_in_body if {
r := rule.report with input as ast.policy(`x := y { y := 5 with input as 1 }`)
r == set()
}

test_success_unconditional_assignment_but_else if {
r := rule.report with input as ast.policy(`msg := x {
x := input.foo
} else := input.bar`)
r == set()
}

0 comments on commit 9674e0e

Please sign in to comment.