You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add rule requiring explicit value (instead of relying on implicit true) when creating an object using the syntax foo[key] if {...}
Reasoning
In v1, this creates an object hello={"world":true}:
hello[input.message] if {
input.message =="world"
}
While almost identical code in v0 created a set hello={"world"}:
hello[input.message] {
input.message =="world"
}
Considering the amount of documentation/discussions available for v0 syntax it's easy to mistake these two. And even when ignoring that aspect, it's better for readability to have it explicitly written out as such:
hello[input.message] :=true if {
input.message =="world"
}
Notes
There might be other instances where this rule (avoid implicit true) may apply, this was the one I stumbled upon
I believe that's the only case where the implict assignment is confusing, and especially when moving between v0 and v1. We'll look into adding a rule to check for that before next release.
Automating a fix here is a little trickier, I think. Because we can't know if the user was trying to define a set the "old way" or the intention was to define an object. So perhaps best to just report it and let the user decide how to fix it? Obviously we'll cover both cases in the rule's documentation.
Summary
Add rule requiring explicit value (instead of relying on implicit
true
) when creating an object using the syntaxfoo[key] if {...}
Reasoning
In
v1
, this creates an objecthello
={"world":true}
:While almost identical code in
v0
created a sethello
={"world"}
:Considering the amount of documentation/discussions available for
v0
syntax it's easy to mistake these two. And even when ignoring that aspect, it's better for readability to have it explicitly written out as such:Notes
true
) may apply, this was the one I stumbled uponAutomatic fix should be possiblesee commentThe text was updated successfully, but these errors were encountered: