Skip to content

Commit

Permalink
Fix: false positive with print and unused-return-value (#486)
Browse files Browse the repository at this point in the history
Fixes #474

Signed-off-by: Anders Eknert <anders@styra.com>
  • Loading branch information
anderseknert authored Nov 21, 2023
1 parent a7f0819 commit 60668b9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions bundle/regal/rules/bugs/unused_return_value.rego
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ report contains violation if {
ref_name := expr.terms[0].value[0].value
ref_name in ast.builtin_names

# special case as the "result" of print is ""
ref_name != "print"

config.capabilities.builtins[ref_name].decl.result != "boolean"

# no violation if the return value is declared as the last function argument
Expand Down
8 changes: 8 additions & 0 deletions bundle/regal/rules/bugs/unused_return_value_test.rego
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,11 @@ test_success_function_arg_return_ignored if {
}`)
r == set()
}

test_success_not_triggered_by_print if {
r := rule.report with data.internal.combined_config as {"capabilities": capabilities.provided}
with input as ast.with_rego_v1(`allow if {
print(lower("A"))
}`)
r == set()
}

0 comments on commit 60668b9

Please sign in to comment.