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

Add a suggestion to match the package name and file location #35

Merged
merged 7 commits into from
Aug 27, 2024

Conversation

charlieegan3
Copy link
Member

@charlieegan3 charlieegan3 commented Aug 27, 2024

4c7c854 is the new content.

Copy link
Member

@anderseknert anderseknert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for doing this! We've had some discussons on this yesterday, so sorry from dropping that here now 😅 But good to get to the bottom of the details before we publish.

style-guide.md Outdated
@@ -51,6 +51,8 @@ Rego policies. If you enjoy this style guide, make sure to check it out!
* [Avoid using the last argument for the return value](#avoid-using-the-last-argument-for-the-return-value)
* [Regex](#regex)
* [Use raw strings for regex patterns](#use-raw-strings-for-regex-patterns)
* [Packages](#packages)
* [Package name should make file location](#package-name-should-make-file-location)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make -> match?

style-guide.md Outdated
@@ -200,11 +206,13 @@ developer experience as well as the quality of your policies.
The built-in functions use `snake_case` for naming — follow that convention for your own rules, functions, and variables.

**Avoid**

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I disabled this rule in the Regal repo, as IMHO, it just makes the code blocks feel detached... but I don't feel strongly about it. Fine to change here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverted in a620cb3


```rego
# foo/bar.rego
package bar.foo
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's been some discussion between me and @srenatus about this yesterday, and there's basically two ideas here (not necessarily represented by any of us 😆):

  1. Only directory structure (and not filename) should mirror the package path. Otherwise, you'd be forced to have all your code for any given package kept in a single file, which isn't ideal. See for example the number of files contributing to regal.ast. I kinda like this idea, but one unresolved issue with it is how to deal with tests. Surely we don't want to recommend using a foo/bar_test directory for foo.bar_test? So if we go with this option, I think tests should only need to match up their package path with the directory structure up until _test.

  2. Directory structure and filename should contribute to the package path. This is basically how the bundle/regal/rules directory works looks right now, and since there's always only one file per rule (+ test), this has worked well. But while we don't have the problem of multiple files contributing to a single package, it's hard to make that a general recommendation.

Since this is the Rego Style Guide and not Regal, perhaps we can simply describe both of these approaches with their pros and cons, and then settle for one default in Regal, but allow configuration toggles for flexibility.

I think that what matters most is not how exactly, but that this is done consistently across a project.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added an updated version in 9b7f0f5

Copy link
Member

@anderseknert anderseknert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@charlieegan3 charlieegan3 merged commit 4d8fa7f into main Aug 27, 2024
1 check passed
@charlieegan3 charlieegan3 deleted the dir-structure branch August 27, 2024 10:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants