Skip to content

Commit

Permalink
Fix false positive when importing input/data in ignored-import (#747)
Browse files Browse the repository at this point in the history
Fixes #746

Signed-off-by: Anders Eknert <anders@styra.com>
  • Loading branch information
anderseknert authored May 27, 2024
1 parent 7b60e7c commit f0875e3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions bundle/regal/rules/imports/ignored_import.rego
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import_paths contains path if {
path := [p.value | some p in imp.path.value]

path[0] in {"data", "input"}
count(path) > 1
}

report contains violation if {
Expand Down
18 changes: 18 additions & 0 deletions bundle/regal/rules/imports/ignored_import_test.rego
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,21 @@ test_success_import_not_ignored if {
r := rule.report with input as module
r == set()
}

# this is covered by the avoid-importing-input rule,
# and `input` is arguably never unused as it's a global variable
test_success_import_input_not_ignored if {
module := ast.policy(`import input`)

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

# this is covered by the redundant-data-import rule,
# and `data` can never be considered unused in Rego
test_success_import_data_not_ignored if {
module := ast.policy(`import data`)

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

0 comments on commit f0875e3

Please sign in to comment.