Skip to main content

unconditional-assignment

Summary: Unconditional assignment in rule body

Category: Style

Avoid

package policy

import rego.v1

full_name := name if {
name := concat(", ", [input.first_name, input.last_name])
}

divide_by_ten(x) := y if {
y := x / 10
}

names contains name if {
name := "Regal"
}

Prefer

package policy

import rego.v1

full_name := concat(", ", [input.first_name, input.last_name])

divide_by_ten(x) := x / 10

names contains "Regal"

Rationale

Rules that return values unconditionally should place the assignment directly in the rule head, as doing so in the rule body adds unnecessary noise.

Configuration Options

This linter rule provides the following configuration options:

rules:
style:
unconditional-assignment:
# one of "error", "warning", "ignore"
level: error

Community

If you think you've found a problem with this rule or its documentation, would like to suggest improvements, new rules, or just talk about Regal in general, please join us in the #regal channel in the Styra Community Slack!