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: use-underscore-prefix #779

Open
anderseknert opened this issue Jun 1, 2024 · 0 comments
Open

Rule: use-underscore-prefix #779

anderseknert opened this issue Jun 1, 2024 · 0 comments

Comments

@anderseknert
Copy link
Member

While it's an optional pattern, we're already starting to reap some tooling benefits from using underscore prefixes to denote private/internal rules and functions. These include things like avoiding completion suggestions to show up for these references (as they aren't meant to be referenced), or cheaply determine if a rule or function is unused or not (as we only need to check the same file for use). The Rego Style Guide was recently updated to include this recommendation, and we've got a few ideas for how to improve our tools to better make use of it going forward. So let's do it!

One obvious way to encourage the convention would be to check all references in a project, and for any rule or function that isn't referenced outside of its own package, suggest that it's made "private". We could easily (well sort of) have the regal fix command (and a corresponding LSP Code Action) automatically rewrite rules and functions to follow the convention too.

As with any good rule, there are some notable exceptions:

  • Tests. These by definition can't have an underscore prefix, and should already be ignored by tooling for most purposes where an underscore prefix would be used.
  • Rules that are marked as entrypoints.
  • Possibly more?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: TODO
Development

No branches or pull requests

1 participant