Back to Opa

use-object-keys

docs/projects/regal/rules/idiomatic/use-object-keys.md

1.16.11.0 KB
Original Source

use-object-keys

Summary: Prefer to use object.keys

Category: Idiomatic

Avoid

rego
package policy

keys := {k | some k, _ in input.object}

# or

keys := {k | some k; input.object[k]}

Prefer

rego
package policy

keys := object.keys(input.object)

Rationale

Instead of using a set comprehension to collect keys from an object, prefer to use the built-in function object.keys. This option is both more declarative and better conveys the intent of the code.

Configuration Options

This linter rule provides the following configuration options:

yaml
rules:
  idiomatic:
    use-object-keys:
      # one of "error", "warning", "ignore"
      level: error