Skip to content

Commit

Permalink
detached-metadata: allow detached if document scope (#469)
Browse files Browse the repository at this point in the history
Fixes #466

Thanks @hans-d for the pointer!

Signed-off-by: Anders Eknert <[email protected]>
  • Loading branch information
anderseknert authored Nov 15, 2023
1 parent fe6f14e commit be7ed72
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
9 changes: 9 additions & 0 deletions bundle/regal/rules/style/detached_metadata.rego
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,14 @@ report contains violation if {
# no need to +1 the index here as rows start counting from 1
trim_space(input.regal.file.lines[last_row]) == ""

annotation := annotation_at_row(block[0].Location.row)
annotation.scope != "document"

violation := result.fail(rego.metadata.chain(), result.location(block[0]))
}

annotation_at_row(row) := annotation if {
some annotation in input.annotations

annotation.location.row == row
}
15 changes: 15 additions & 0 deletions bundle/regal/rules/style/detached_metadata_test.rego
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,18 @@ allow := true
`)
r == set()
}

test_success_detached_document_scope_ok if {
r := rule.report with input as regal.parse_module("p.rego", `
package p
# METADATA
# scope: document
# descriptiom: allow allows
# METADATA
# title: allow
allow := true
`)
r == set()
}

0 comments on commit be7ed72

Please sign in to comment.