Skip to content

Commit

Permalink
Remove rule.head.name usage (#357)
Browse files Browse the repository at this point in the history
And use rule.head.ref consistently

Fixes #331

Signed-off-by: Anders Eknert <anders@styra.com>
  • Loading branch information
anderseknert committed Sep 30, 2023
1 parent 57d77d1 commit c937e34
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 19 deletions.
4 changes: 1 addition & 3 deletions bundle/regal/ast.rego
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ package_name := concat(".", [path.value |
# note that what constitutes the "name" of a ref-head rule is
# ambiguous at best, i.e. a["b"][c] { ... } ... in those cases
# we currently return the first element of the ref, i.e. "a"
name(rule) := rule.head.name if {
rule.head.name
} else := rule.head.ref[0].value
name(rule) := rule.head.ref[0].value

named_refs(refs) := [ref |
some i, ref in refs
Expand Down
9 changes: 1 addition & 8 deletions bundle/regal/rules/style/prefer_snake_case.rego
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ report contains violation if {
some ref in ast.named_refs(rule.head.ref)
not util.is_snake_case(ref.value)

violation := result.fail(rego.metadata.chain(), result.location(location_of(ref, rule)))
violation := result.fail(rego.metadata.chain(), result.location(ref))
}

report contains violation if {
Expand All @@ -24,10 +24,3 @@ report contains violation if {

violation := result.fail(rego.metadata.chain(), result.location(var))
}

# annoyingly, rule head refs are missing location when a rule.head.name is present,
# or rather when there's only a single item in the ref.. this inconsistency should
# probably be fixed in OPA, but until then, there's this.
location_of(ref, rule) := ref if ref.location

else := rule.head
9 changes: 1 addition & 8 deletions bundle/regal/rules/testing/metasyntactic_variable.rego
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ report contains violation if {
# }
not ast.is_chained_rule_body(rule, input.regal.file.lines)

violation := result.fail(rego.metadata.chain(), result.location(location_of(ref, rule)))
violation := result.fail(rego.metadata.chain(), result.location(ref))
}

report contains violation if {
Expand All @@ -53,10 +53,3 @@ report contains violation if {

violation := result.fail(rego.metadata.chain(), result.location(var))
}

# annoyingly, rule head refs are missing location when a rule.head.name is present,
# or rather when there's only a single item in the ref.. this inconsistency should
# probably be fixed in OPA, but until then, there's this.
location_of(ref, rule) := ref if ref.location

else := rule.head

0 comments on commit c937e34

Please sign in to comment.