Back to Opa

superfluous-object-get

docs/projects/regal/rules/idiomatic/superfluous-object-get.md

1.16.11.0 KB
Original Source

superfluous-object-get

Summary: Superfluous object.get call

Category: Idiomatic

Avoid

rego
package policy

allow if {
    object.get(input, ["path", "to", "value"], "default") == "expected"
}

Prefer

rego
package policy

allow if {
    input.path.to.value == "expected"
}

Rationale

The object.get function is sometimes used to guard against undefined references halting evaluation. Immediately comparing the result of the call to a constant value that isn't the same as the default is however superfluous, as the expression will evaluate the same without using object.get. In such cases the call can simply be removed.

Configuration Options

This linter rule provides the following configuration options:

yaml
rules:
  idiomatic:
    superfluous-object-get:
      # one of "error", "warning", "ignore"
      level: error