opa icon indicating copy to clipboard operation
opa copied to clipboard

Allow `not every`

Open anderseknert opened this issue 1 year ago • 6 comments

I know there are reasons why we currently don't, and that there are other ways to achieve the same outcome, but for someone not deeply familiar with Rego, it might not be obvious how to get there. Additionally, and certainly not to be dismissed, not every reads rather nicely compared to many of the alternatives.

report contains "missing important attribute" if {
    not every resource in list {
        resource.important_attribute
    }
}

As a "good enough" solution if we intend to keep the current behavior, we can improve the error message, and rather than to say:

unexpected every keyword: illegal negation of 'every'

We point the user to documentation where we explain why it can't be expressed that way, and what they should use instead.

A side note really, but a pretty nice side-effect of allowing this is how every provides a body of its own, and can be used even with "single-line" rules, which would allow the example above to be written as:

report contains "missing important attribute" if not every resource in list {
    resource.important_attribute
}

anderseknert avatar May 25 '24 20:05 anderseknert

When read as natural-language English, not every x in y could be interpreted as some x in y, which excludes no x in y. Not an argument against this change, just something we might want to clarify in the docs.

johanfylling avatar May 28 '24 08:05 johanfylling

When read as natural-language English, not every x in y could be interpreted as some x in y, which excludes no x in y.

What do you mean with "excludes no x in y"? 🤔

"Not every fruit in the basket is yellow" (not every x in y { p(x) }) ⬇️ "There is a fruit in the basked that is not yellow" (some x in y; not p(x))

srenatus avatar May 28 '24 08:05 srenatus

Although not logically correct, when you say that not every item in a group has a property, the listener might incorrectly infer the subtext that at least a non-zero amount does: "Not every fruit in the basket is yellow" == "Not every fruit in the basket is yellow, but some are". Just a quirk in how a listener/reader might fill in the blanks, even when there are none to fill. Might even be something not even worthwhile noting in the docs, as people are probably in a more precise state of mind when reading code.

johanfylling avatar May 28 '24 09:05 johanfylling

"All animals are equal, but some animals are more equal than others"

:)

anderseknert avatar May 28 '24 12:05 anderseknert

two feet bad

srenatus avatar May 28 '24 12:05 srenatus

This issue has been automatically marked as inactive because it has not had any activity in the last 30 days. Although currently inactive, the issue could still be considered and actively worked on in the future. More details about the use-case this issue attempts to address, the value provided by completing it or possible solutions to resolve it would help to prioritize the issue.

stale[bot] avatar Jun 27 '24 23:06 stale[bot]