Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rule: defer-assignment #1147

Open
anderseknert opened this issue Sep 27, 2024 · 0 comments
Open

Rule: defer-assignment #1147

anderseknert opened this issue Sep 27, 2024 · 0 comments

Comments

@anderseknert
Copy link
Member

anderseknert commented Sep 27, 2024

Example somewhat exaggerated, but hopefully well suited for demonstration.

Avoid

allow if {
    resp := http.send({"method": "get", "url": "http://example.org"})
    
    "developer" in input.user.roles # if this fails, `resp` assignment was for nothing
    resp.status.code == 200
}

Prefer

allow if {
    "developer" in input.user.roles

    resp := http.send({"method": "get", "url": "http://example.org"})
    resp.status.code == 200
}

The basic idea would be to recommend moving assignments next to where they're used, as having checks in between where the value of assignment isn't used may render the (potentially costly) assignment redundant.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant