Skip to content

Add Regal for linting Rego#454

Merged
jalseth merged 1 commit into
plexsystems:mainfrom
anderseknert:regal
Nov 27, 2023
Merged

Add Regal for linting Rego#454
jalseth merged 1 commit into
plexsystems:mainfrom
anderseknert:regal

Conversation

@anderseknert
Copy link
Copy Markdown
Contributor

I think you're all familiar with Regal by now, so I'll skip the introduction :) This PR introduces the OPA community's favorite linter to the Konstraint project, and along with that a bunch of fixes as suggested by the linter.

Regal checks addressed:

OPA strict mode compliance:

  • Variables must not shadow input

Both have been added to the CI pipeline to ensure future compliance. Make sure to check in every once in a while, as new Regal releases are published quite frequently, and there's often some useful new rule included in each release.

Fixes #446

Copy link
Copy Markdown
Collaborator

@jalseth jalseth left a comment

Choose a reason for hiding this comment

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

LGTM, thanks Anders!

The failing CI is unrelated to this change.

Copy link
Copy Markdown
Collaborator

@jalseth jalseth left a comment

Choose a reason for hiding this comment

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

@anderseknert Scratch that, please rebase on main. I think you will need to generate the Gatekeeper YAMLs as you changed the source and the acceptance tests verify the YAMLs are generated correctly.

@anderseknert
Copy link
Copy Markdown
Contributor Author

@jalseth it's bedtime here, but will do tomorrow 👍

I think you're all familiar with [Regal](https://github.com/styrainc/regal) by
now, so I'll skip the introduction :) This PR introduces the OPA community's
favorite linter to the Konstraint project, and along with that a bunch of fixes
as suggested by the linter.

Regal checks addressed:

* [import-after-rule](https://docs.styra.com/regal/rules/imports/import-after-rule)
* [line-length](https://docs.styra.com/regal/rules/style/line-length)
* [unconditional-assignment](https://docs.styra.com/regal/rules/style/unconditional-assignment)
* [use-assignment-operator](https://docs.styra.com/regal/rules/style/use-assignment-operator)
* [use-in-operator](https://docs.styra.com/regal/rules/idiomatic/use-in-operator)
* [use-some-for-output-vars](https://docs.styra.com/regal/rules/idiomatic/use-some-for-output-vars)

OPA strict mode compliance:

* Variables must not shadow `input`

Both have been added to the CI pipeline to ensure future compliance.
Make sure to check in every once in a while, as new Regal releases
are published quite frequently, and there's often some useful new
rule included in each release.

Fixes #446

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

@jalseth done 👍 make update-static fails with:

$ make update-static
go build -o build/konstraint
./build/konstraint create examples
WARN[0000] Skipping constraint generation due to use of parameters  name=RequiredLabels src=examples/required-labels/src.rego
INFO[0000] completed successfully                        num_policies=20
./build/konstraint create test/create --output test/create
Error: get violations: parse directory: filter rego files: 1 error occurred during loading: stat test/create: no such file or directory

But I was able to resolve that by simply creating the directory first.

There's also a test/doc directory created by running that command, but that does not seem to have been checked in previously, so I did not include that.

Copy link
Copy Markdown
Collaborator

@jalseth jalseth left a comment

Choose a reason for hiding this comment

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

Thanks again!

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.

Lint examples with regal

2 participants