Back to Opa

detached-metadata

docs/projects/regal/rules/style/detached-metadata.md

1.16.11.2 KB
Original Source

detached-metadata

Summary: Detached metadata annotation

Category: Style

Avoid

rego
package authz

 # METADATA
 # description: allow any requests by admin users

allow if {
    "admin" in input.user.roles
}

Prefer

rego
package authz

# METADATA
# description: allow any requests by admin users
allow if {
    "admin" in input.user.roles
}

Rationale

Metadata annotations should be placed directly above the package, rule or function they are annotating. While OPA accepts any number of newlines between an annotation and the package/rule it applies to, this makes it difficult to connect the two when reading the policy. Always optimize for readability!

Configuration Options

This linter rule provides the following configuration options:

yaml
rules:
  style:
    detached-metadata:
      # one of "error", "warning", "ignore"
      level: error