v0.26.0
v0.26.0 brings 2 new linter rules to Regal, a debugger API backend, and noticeably faster linting.
Regal v0.26.0 is likely the first consumer of the new debugger API that landed in OPA v0.68.0 just last week — and in turn uses this to expose a first ever Debug Adapter Protocol (DAP) backend for Rego! Next release of the OPA VS Code extension will leverage Regal to provide developers a first-class debugging experience for Rego. Stay tuned!
Thanks to @johanfylling for tirelessly working to make this happen — in both OPA, Regal, and the OPA VS Code extension.
Rules
New rule: directory-package-mismatch
Category: idiomatic
The directory-package-mismatch
rule is a first of its kind in Regal, as it reports issues in project structure rather than in code. This rule codifies an old best practice in Rego projects: the package
name (path) should be mirrored in the directory structure a policy resides in. Put simply, a policy declaring package rbac.user.roles
should be placed in a rbac/user/roles
directory.
The directory-package-mismatch
rule not only helps enforce this convention, but provides both CLI (regal fix
) and editor support for fixing these issues automatically.
Note: When used on an existing project, this rule will likely result in a lot of violations being reported. While regal fix
can remediate that in a matter of seconds (by moving policy files according to their package paths), make sure to commit or stash any existing changes before running it, and then review the result. Read the docs for details!
For more information, see the docs on directory-package-mismatch.
New Rule: sprintf-arguments-mismatch
Category: bugs
The new sprintf-arguments-mismatch
rule checks that the formatting directives (%s
, %d
, etc) in a sprintf
call match the supplied number arguments.
Wrong
msg := sprintf("number of issues (%d) must not be higher than %d", [count(issues)])
Correct
msg := sprintf("number of issues (%d) must not be higher than %d", [count(issues), 10])
For more information, see the docs on sprintf-arguments-mismatch.
Debug Adapter Protocol Backend
This release add support in Regal for the Debug Adapter Protocol. Similar to the language server protocol, this new functionality will support users of compatible clients to step-by-step debug their Rego projects in an interactive manner. Client implementation in the VS Code OPA extension soon to follow!
Language Server: auto-completion based on input.json
Both the OPA VS Code extension, and Regal supports placing an input.json
file in the workspace and automatically have it used as input for evaluation. If found, Regal will now additionally use this to provide completion suggestions on input
based on the fields found in that file. If you haven't made it a habit yet to keep an input.json
file in your workspace, now is a good time to start!
New RoAST library for custom AST serialization
Regal now uses a new, custom and optimized AST format to improve the performance of Regal. The new library is integrated into Regal in this release and represents around a 50% reduction in AST JSON size, and a 25% performance improvement in linting over the previous implementation.
For more information, see the docs in the roast project repo.
Special thanks to our contributors from the community!
Changelog
- ee341d9: cosmetic: fix a few typos (reprise) (#994) (@msorens)
- c70b0bd: build(deps): bump dario.cat/mergo from 1.0.0 to 1.0.1 (#996) (@dependabot[bot])
- 29a7bb5: lsp: Update rego-by-examples index (#998) (@github-actions[bot])
- 4bbeb59: build(deps): bump github/codeql-action from 3.26.2 to 3.26.3 (#999) (@dependabot[bot])
- f28ac7d: Use new Roast library for custom AST serialization (#1001) (@anderseknert)
- 1fecb4c: Add
input.json
completion provider (#1005) (@anderseknert) - 1ca1c0f: build(deps): bump github/codeql-action from 3.26.3 to 3.26.4 (#1004) (@dependabot[bot])
- c9e4a7e: Rule:
sprintf-arguments-mismatch
(#1011) (@anderseknert) - 0f971ff: build(deps): bump github/codeql-action from 3.26.4 to 3.26.5 (#1012) (@dependabot[bot])
- 2c75c96: Remove some code made redundant by roast (#1013) (@anderseknert)
- 11320cd: Pin OPA version in Actions to v0.67.1 (#1019) (@anderseknert)
- 683f8de: lint: Advertise regal fix command (#1016) (@charlieegan3)
- a9d4e2f: Bug hunt (#1020) (@anderseknert)
- a92a31f: fix: respect ref head rules in
rule-name-repeats-package
(#1022) (@anderseknert) - 9ee83e8: Rule:
directory-package-mismatch
(#1024) (@anderseknert) - afa1ee2: build(deps): bump github/codeql-action from 3.26.5 to 3.26.6 (#1026) (@dependabot[bot])
- ebdc067: Allow tests to be in 'test' package (#1027) (@anderseknert)
- b1551ee: lsp: Clean workspace root from eval errors (#1028) (@charlieegan3)
- 9cd3b05: Add EOPA as an engine option (#1000) (@charlesdaniels)
- 147a731: Fix build issue + version in README (#1030) (@anderseknert)
- 6fac539: OPA v0.68.0 (#1031) (@anderseknert)
- 29d16c6: Remove code to workaround bug fixed in OPA v0.68.0 (#1032) (@anderseknert)
- 1a58b8c: Add DAP implementation for debugging OPA (#926) (@johanfylling)
- a525c98: Some schema fixes (#1033) (@anderseknert)
- 15ddb34: Fix missing locals completions (#1034) (@anderseknert)
- 7929744: docs/editors: add helix config (#1037) (@srenatus)
- dc5ab30: docs: Point LS feature links to docs site (#1038) (@charlieegan3)
- 743975a: build(deps): bump actions/upload-artifact from 4.3.6 to 4.4.0 (#1039) (@dependabot[bot])
- 8e890ae: Allow fixing directory structure not matching package paths (#1035) (@anderseknert)
- cc4ba21: Add support for
--dry-run
and dirty git workspace abort (#1042) (@charlieegan3) - 7da45a4: build(deps): bump peter-evans/create-pull-request from 6.1.0 to 7.0.0 (#1041) (@dependabot[bot])
- ccb66fc: Codecov experiment (#1045) (@anderseknert)
- fe9e0d9: build: check yaml and json formatting with dprint (#1047) (@charlieegan3)
- 02d9538: Docs: Document fixing issues, project roots, and new features (#1043) (@anderseknert)
- fef46d7: fix: Update root detection (#1049) (@charlieegan3)
- 66a3a76: lsp: Clear old directories when renaming (#1050) (@charlieegan3)
- 7a4811b: Fix
directory-package-mismatch
issue when lint called with "." (#1053) (@anderseknert) - ced7c70: fix: Require use of --force to fix without git (#1052) (@charlieegan3)
- bf6e879: lsp: Template new empty files & template on format (#1051) (@charlieegan3)