Skip to content

Rule: Add rule to avoid using implicit true when building an object (require explicit value) #1396

@rplnt

Description

@rplnt

Summary

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
  • Automatic fix should be possible see comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions