diff --git a/bundle/regal/rules/idiomatic/equals_pattern_matching.rego b/bundle/regal/rules/idiomatic/equals_pattern_matching.rego index 5ba0410a..a10d42b8 100644 --- a/bundle/regal/rules/idiomatic/equals_pattern_matching.rego +++ b/bundle/regal/rules/idiomatic/equals_pattern_matching.rego @@ -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" @@ -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" diff --git a/bundle/regal/rules/idiomatic/equals_pattern_matching_test.rego b/bundle/regal/rules/idiomatic/equals_pattern_matching_test.rego index e7e8038d..2137535d 100644 --- a/bundle/regal/rules/idiomatic/equals_pattern_matching_test.rego +++ b/bundle/regal/rules/idiomatic/equals_pattern_matching_test.rego @@ -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",