Skip to content

Commit

Permalink
equals-pattern-matching: fix false positive with else (#434)
Browse files Browse the repository at this point in the history
Fixes #433

Signed-off-by: Anders Eknert <[email protected]>
  • Loading branch information
anderseknert authored Oct 31, 2023
1 parent dd36d70 commit 20bd3f5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions bundle/regal/rules/idiomatic/equals_pattern_matching.rego
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ report contains violation if {
some fn in ast.functions
ast.generated_body(fn)

not fn["else"]

arg_var_names := {arg.value |
some arg in fn.head.args
arg.type == "var"
Expand All @@ -43,6 +45,8 @@ report contains violation if {
some fn in ast.functions
not ast.generated_body(fn)

not fn["else"]

arg_var_names := {arg.value |
some arg in fn.head.args
arg.type == "var"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,15 @@ test_success_actually_pattern_matching if {
r == set()
}

test_success_skipped_on_else if {
module := ast.policy(`f(x) {
x == 1
} else := false`)

r := rule.report with input as module
r == set()
}

expected := {
"category": "idiomatic",
"description": "Prefer pattern matching in function arguments",
Expand Down

0 comments on commit 20bd3f5

Please sign in to comment.