open-policy-agent / opa

Open Policy Agent (OPA) is an open source, general-purpose policy engine.
https://www.openpolicyagent.org
Apache License 2.0
9.31k stars 1.29k forks source link

Formatter rewrites quoted reference containing keyword to non-quoted one which fails to parse #6766

Open anderseknert opened 1 month ago

anderseknert commented 1 month ago
package p

import rego.v1

foo := data.foo.bar["contains"]("baz")

running opa fmt on this file rewrites the ref:

package p

import rego.v1

foo := data.foo.bar.contains("baz")

which doesn't parse, as contains is of course a keyword

(although, a keyword that is also a built-in function, and shouldn't be considered a keyword at this location, but that's another issue)

anderseknert commented 1 month ago

I guess this is like the third issue we have where the real problem is how keywords can't be used in refs. We should just fix that.