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 Regal for linting Rego #194

Merged
merged 1 commit into from
Oct 18, 2023
Merged

Add Regal for linting Rego #194

merged 1 commit into from
Oct 18, 2023

Conversation

anderseknert
Copy link
Contributor

Hi there, GKE friends 👋😃

This PR introduces Regal for linting Rego policy for the project. I've limited linting (and fixes) to the gke-policies-v2 directory here, but I'd be happy to expand this to the v1 directory as well if you think that'd be valuable.

Along with a configuration file to disable some of the linters that'd require a more concentrated effort to adhere to, I've fixed the following reported violations, which while mostly style-related, seems like they'd be good to enforce for modern Rego:

I've also included linting as a step for the GitHub Action that runs tests of all the policies.

Let me know what you think!

@google-cla
Copy link

google-cla bot commented Oct 15, 2023

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@mikouaj mikouaj self-assigned this Oct 18, 2023
Hi there, GKE friends 👋😃

This PR introduces [Regal](https://github.com/StyraInc/regal) for linting Rego policy
for the project. I've limited linting (and fixes) to the `gke-policies-v2` directory
here, but I'd be happy to expand this to the v1 directory as well if you think that'd
be valuable.

Along with a configuration file to disable some of the linters that'd require a more
concentrated effort to adhere to, I've fixed the following reported violations, which
while mostly style-related, seems like they'd be good to enforce for modern Rego:

* [use-some-for-output-vars](https://docs.styra.com/regal/rules/use-some-for-output-vars)
* [non-raw-regex-pattern](https://docs.styra.com/regal/rules/idiomatic/non-raw-regex-pattern)
* [prefer-package-imports](https://docs.styra.com/regal/rules/imports/prefer-package-imports)
* [chained-rule-body](https://docs.styra.com/regal/rules/style/chained-rule-body)
* [identically-named-tests](https://docs.styra.com/regal/rules/testing/identically-named-tests)
* [use-assignment-operator](https://docs.styra.com/regal/rules/style/use-assignment-operator)

I've also included linting as a step for the GitHub Action that runs tests of all the
policies.

Let me know what you think!

Signed-off-by: Anders Eknert <[email protected]>
@anderseknert
Copy link
Contributor Author

Pushed update to include copyright header in .regal/config.yaml.

Copy link
Member

@mikouaj mikouaj left a comment

Choose a reason for hiding this comment

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

Thank you @anderseknert for introducing Regal to our project!
Its a really useful tool and I will definitely consider it in the other projects as well. Also I will scan ignored rules and see what else can we adapt.

@anderseknert
Copy link
Contributor Author

I'm very happy to hear that @mikouaj! 😃 Let me know if there's anything I can do to help with that.

@mikouaj mikouaj merged commit 1d9ea08 into google:main Oct 18, 2023
5 checks passed
@anderseknert anderseknert deleted the regal branch October 18, 2023 15:55
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