StyraInc / rego-style-guide

Style guide for Rego

Home Page:https://docs.styra.com/opa/rego-style-guide

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Provide OPA policies for validating these style recommendations

Niksko opened this issue · comments

Some of these style recommendations lend themselves well to automated checking. Building on you great blog post on the subject, would it be worth adding Rego policies that deny Rego that doesn't conform to these style rules?

Thank you Nik! And I love that idea 👍

The "Limitations and gotchas" section of that blog provides a few pointers as to why this would currently be difficult to pull off for many of the recommendations provided in the style guide. Since the linter presented in the blog works on the the level of an AST, quite a few of the constructs recommended here would have been "compiled away" in the transition from Rego -> AST. This could be dealt with to some extent, if we at least provided the location of the original Rego code in the parse result, but sadly, currently we don't. Sooner or later, I believe we'll need to provide a real linter, which would allow writing "linter policies" not just at the level of an AST, but one that could operate on both the Rego layer, the AST, and potentially a layer of analysis, where the linter itself would provide a dataset optimized for linting.

This is high up on my list of priorities, but it's quite an undertaking :)

Done 😊 more rules to follow, for sure but we’re getting there. https://github.com/StyraInc/regal