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

Review Rego snippets in docs and update to follow current best practices #4599

Closed
anderseknert opened this issue Apr 20, 2022 · 5 comments
Closed

Comments

@anderseknert
Copy link
Member

anderseknert commented Apr 20, 2022

Some things to consider for the review. Obviously up for discussion!

  • Use := for file level assignments
  • Prefer foo in bar over foo == bar[_] or foo[bar]
  • Prefer some foo in bar over foo := bar[_], some foo, bar in baz over bar := baz[foo]
  • Prefer every foo in bar { .. } over iteration with helper rules
  • Prefer metadata annotations over comments on rules and packages

Additionally, we should use opa fmt for consistent formatting of snippets, and use opa check --strict to catch mistakes (unless of course that's what's being demonstrated in a snippet).

@johanfylling
Copy link
Contributor

johanfylling commented Apr 20, 2022

Perhaps we could update the build step (or add a linting step) for docs to automatically search for rego blocks and diff those against the output of opa fmt for that same block 🤔 .

@srenatus
Copy link
Contributor

@johanfylling totally. unfortunately, there's another prereq to that: #4104 (now #4508)

@srenatus
Copy link
Contributor

💭 Actually, we don't have to have opa fmt operate on things less-than-a-module if we integrate the check with live-blocks. The live-blocks scripts will at some point assemble the complete module, and feed it into opa eval, so we could also have an opa fmt check there.

tsandall added a commit to tsandall/opa that referenced this issue Apr 20, 2022
This partially addresses open-policy-agent#4599.

Signed-off-by: Torin Sandall <torinsandall@gmail.com>
tsandall added a commit to tsandall/opa that referenced this issue Apr 20, 2022
This partially addresses open-policy-agent#4599.

Signed-off-by: Torin Sandall <torinsandall@gmail.com>
tsandall added a commit that referenced this issue Apr 20, 2022
This partially addresses #4599.

Signed-off-by: Torin Sandall <torinsandall@gmail.com>
rokkiter pushed a commit to rokkiter/opa that referenced this issue Apr 26, 2022
This partially addresses open-policy-agent#4599.

Signed-off-by: Torin Sandall <torinsandall@gmail.com>
@stale
Copy link

stale bot commented May 20, 2022

This issue has been automatically marked as inactive because it has not had any activity in the last 30 days.

@stale stale bot added the inactive label May 20, 2022
@anderseknert
Copy link
Member Author

This eventually culminated into the Rego Style Guide. Having a mix of styles in the docs could actually be good, I think, as long as the recommended path is documented somewhere. Closing this for now, but if someone feels that there are some particular part of our docs that need an update, do holler out!

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

3 participants