Releases: StyraInc/regal
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)
v0.25.0
This release brings 2 new rules to the Regal linter as well as a number of improvements to the Regal Language Server.
Rules
New rule unused-output-variable
Category: bugs
In this example, if x
is unused later in the rule, it is considered an unused output variable.
package policy
allow if {
some x
role := input.user.roles[x]
# do something with "role", but not "x"
}
Unused output variables should be replaced by wildcards (_
), as it makes it clear that the variable isn't going to be used.
For more information, see the docs on unused-output-variable.
New rule use-strings-count
Category: idiomatic
strings.count
is a new OPA built-in function and should be used in place of counting indexes (count(indexof_n("foobarbaz", "a"))
) as was common before.
Not only is strings.count
more readable, but it also performs better.
For more information, see the docs on use-strings-count.
Other Rule Updates
The argument-always-wildcard
rule will now ignore mock_
prefixed functions by default, as wildcard arguments are commonly used in mocked functions.
Linter
- The JUnit XML output format is now a supported by
regal lint
. This can be used by e.g. GitLab CI/CD jobs to have linter violations printed in the code view in GitLab merge requests. Thanks @sebhoss for the work on this one! - Regal's version of OPA has been updated to v0.67.0, you'll need to be using this version to use the remediation for the
use-strings-count
rule. - The
--var-values
flag fromopa test
(added to OPA in v0.66.0) is now supported by theregal test
command. This allows custom policy authors to see the the variable values in scope of a failed test.
Regal Language Server
Code Lens Support
Regal now provides a Code Lens for direct evaluation of packages or rules within the editor, providing immediate feedback. In supported editors, you can now evaluate a package or rule by pressing "Evaluate" above its declaration, with the results displayed in-line.
code.lens.eval.mov
Input data provided via input.json
, and data.json
/data.yaml
files from bundle directories in the workspace are also available at evaluation time.
Improved Formatter
The language server can now be configured to use regal fix
as a formatter when saving buffers. In VS Code, setting opa.formatter
to regal-fix
will enable this feature.
Other editors can use this by setting the initializationOptions.formatter
.
New Contributors
Thanks @rinx for their work on creating the Regal Nix package! (and updating our docs) and @sebhoss for the JUnit output format.
Changelog
- 6a0a9b5: docs: add nixpkgs/regal to the adopters list (#920) (@rinx)
- 3abd5c0: Rule: unused-output-variable (#922) (@anderseknert)
- d3a77ce: Ensure
unused-output-variable
actually is output variable (#925) (@anderseknert) - 8382e1c: Add
except-function-name-pattern
option toargument-always-wildcard
(#924) (@anderseknert) - 886ef2e: Add
--var-values
flag toregal test
command (#930) (@anderseknert) - 69a9923: Fix false positive in
messy-rule
when ref head rules are used (#927) (@anderseknert) - 3d4e14a: build(deps): bump github/codeql-action from 3.25.12 to 3.25.13 (#932) (@dependabot[bot])
- 2a29cd2: Add JUnit output format (#929) (@sebhoss)
- c0348af: lsp: Address bug in multi file test case (#933) (@charlieegan3)
- 7565b81: docs: Update notes on neovim and packaging (#934) (@charlieegan3)
- 4a4f705: build(deps): bump github/codeql-action from 3.25.13 to 3.25.14 (#938) (@dependabot[bot])
- 5b2055b: reporter: Trim long lines of location text (#937) (@charlieegan3)
- 6c92606: Bump OPA version to v0.67.0 (#941) (@anderseknert)
- 68b2c5d: build(deps): bump ossf/scorecard-action from 2.3.3 to 2.4.0 (#946) (@dependabot[bot])
- 99fb078: build(deps): bump github/codeql-action from 3.25.14 to 3.25.15 (#945) (@dependabot[bot])
- f2b1029: Include function args in
ast.vars
(andprefer-snake-case
rule) (#947) (@anderseknert) - 7bc7868: Extend
redundant-existence-check
to fail redundant ref checks (#949) (@anderseknert) - 8a8b8ad: Rule:
prefer-strings-count
(#948) (@anderseknert) - 29f74d9: lsp: Add Neovim as known client identifier (#951) (@charlieegan3)
- af89fef: build(deps): bump golangci/golangci-lint-action from 6.0.1 to 6.1.0 (#952) (@dependabot[bot])
- d070132: lsp: Skip textDocument/completion for ignored files (#953) (@charlieegan3)
- 565f509: lsp: Poll workspace state to detect state changes (#954) (@charlieegan3)
- 4f86595: lsp: Notify when a fix fails (#955) (@charlieegan3)
- 27afe15: lsp/format,cmd/fix: Apply rego.v1 formatting by default (#958) (@charlieegan3)
- b3a79c0: build(deps): bump actions/upload-artifact from 4.3.4 to 4.3.5 (#961) (@dependabot[bot])
- 7bd66d9: Allow using
regal fix
as a formatter (#960) (@anderseknert) - dfe21e6: lsp: Auto update examples index (#956) (@charlieegan3)
- ba7c196: fix: Remove foo dir (#962) (@charlieegan3)
- 8414b8b: lsp: Update example index with PRs not commits (#963) (@charlieegan3)
- e000dd0: lsp: Update example index PR title (#966) (@charlieegan3)
- 3f3ad8e: perf: Walk less (#965) (@anderseknert)
- 95d1eb1: lsp: Update rego-by-examples index (#967) (@github-actions[bot])
- a318e6c: lsp: Add code lens support for evaluating rules (#968) (@anderseknert)
- 01b64a4: build(deps): bump actions/upload-artifact from 4.3.5 to 4.3.6 (#970) (@dependabot[bot])
- 6614f5e: build(deps): bump github/codeql-action from 3.25.15 to 3.26.0 (#971) (@dependabot[bot])
- 086cb25: docs: Fix spelling mistakes (#969) (@charlieegan3)
- 63e7155: LSP: Provide output.json option for non-VS Code clients (#972) (@anderseknert)
- ff67859: Fix code lens issue with ref head rules (#973) (@anderseknert)
- f6e2e14: lsp: No error when missing keywords for hover (#974) (@charlieegan3)
- 4ba405e: lsp: Generate correct rule name when during Eval (#975) (@charlieegan3)
- f2ac449: lsp: include
print
output in eval response (#978) (@anderseknert) - 3236efd: Add end location to
metasyntactic-variable
violations (#977) (@anderseknert) - e886f35: Add end location to
line-length
violation (#981) (@anderseknert) - 4ebdd7e: Add end location to
non-raw-regex-pattern
violations (#980) (@anderseknert) - 04b8a75: lsp/perf: don't traverse .git or .idea dirs (#984) (@anderseknert)
- fc0dc04: Document the Code Lens Evaluation feature (#983) (@anderseknert)
- c5aa188: lsp: Workspace eval, return rule head locations (#985) (@charlieegan3)
- 789fccf: build(deps): bump github/codeql-action from 3.26.0 to 3.26.1 (#986) (@dependabot[bot])
- acbdb88: lsp: Implement bundle use in workspace Eval (#987) (@charlieegan3)
- e4fcb0f: build(deps): bump github/codeql-action from 3.26.1 to 3.26.2 (#988) (@dependabot[bot])
- 1e14d08: Update capabilities.json to include
strings.count
(#990) (@anderseknert)
v0.24.0
This release brings 4 new rules to Regal's linter as well as a number of improvements to the language server.
Rules
New Rule if-object-literal
This rule helps users avoid an error case where an object follows an if
. Typically this represents an incomplete rule.
allow if {}
Read the docs on if-object-literal
.
New Rule pointless-reassignment
Variables in Rego are immutable, so adding a new variable for an existing short variable only adds noise. Read the docs on pointless-reassignment
.
New Rule argument-always-wildcard
Sometimes, particularly after refactoring, a function argument is always a wildcard (_
):
my_func(name, _)
my_func("Alice", _)
This rule catches such cases as they typically offer an opportunity for further refactoring or an error where the argument should be used in one or more cases. Read the docs on argument-always-wildcard
.
New Rule annotation-without-metadata
Rules containing METADATA
annotation syntax without a METADATA
header will not be parsed and represents a likely mistake.
# description: allow allows
allow if {
# ... some conditions
}
Read the docs on annotation-without-metadata
.
New Rule var-shadows-builtin
Variables that share the name of a built-in group or function should be renamed to avoid confusion.
# variable `http` shadows `http.send` built-in function
allow if {
http := startswith(input.url, "http://")
# ...
}
Read the docs on var-shadows-builtin
.
Regal Language Server
Snippet Completions
We have extended the support for completions to add snippets for some
and every
. Both key:value and collection formats are supported.
Screen.Recording.2024-07-16.at.17.31.42.mov
Example Links on Keyword and Built-in Hover
We've been building out a new documentation section called 'Rego By Example'. We have detailed guides here for some of the common keywords and built-in functions. Users can now browse directly to these from their editors by hovering over supported keywords and functions.
Screen.Recording.2024-07-16.at.17.34.05.mov
Supported:
- Keywords
some
andevery
- Function Groups
io.jwt
,regex
,time
, andcontains
- (more coming soon!)
Suggestions for Variables in Local Scope
We've got lots of completions providers now, this new one suggestions previously defined local variables like this:
Project Housekeeping
Start-up Version Check
With much work going into keeping a regular stream of updates, we felt it was important to help users stay up-to-date. In this release we have laid the groundwork for this by having Regal consult the latest releases on GitHub at startup and reporting if the current version is now outdated.
Please see Remote Features for more information and for instructions on how to disable this.
Use OSSF Scorecard
The OpenSSF Scorecard evaluates open source projects against security best practices to identify potential risks and areas for improvement. In this release we have added a workflow to scan the project on a schedule.
New Contributors
Thanks @maruloop for your first contribution to the project in #865 - and for working on this reviewdog integration for our project.
Changelog
- 96246a3: Skip nil check (#819) (@charlieegan3)
- b6588dc: Cache rq binary (#820) (@charlieegan3)
- 90b2bcc: Check Regal version at start-up (#824) (@charlieegan3)
- 53dbce6: Don't call completion providers inside of comments (#831) (@anderseknert)
- 3af7d06: Don't suggest
if
orcontains
following import (#834) (@anderseknert) - e3e12a9: Fix markdown content rendering for Zed editor (#829) (@anderseknert)
- 34fc452: Rule:
if-object-literal
(#835) (@anderseknert) - 5901874: Better support rule head keyword completions (#836) (@charlieegan3)
- b24bde4: lsp: perform no operation when processing events for ignored files (#837) (@charlieegan3)
- fb0250c: Completion suggestions for variables in local scope (#840) (@anderseknert)
- d8dda73: build(deps): bump github.com/spf13/cobra from 1.8.0 to 1.8.1 (#842) (@dependabot[bot])
- 8dd71c8: Add support for ignored files in ls formatting (#845) (@charlieegan3)
- 1edfd88: Completion of locals in more places (#847) (@anderseknert)
- 1191c41: Better
default
suggestions (#848) (@anderseknert) - 7bf1c93: [lsp] Implement rulerefs in rego (#849) (@charlieegan3)
- e9a2ab6: Add more to docs on
prefer-some-in-iteration
(#851) (@anderseknert) - 0536573: Port Import provider to Rego (#853) (@charlieegan3)
- d3dad61: Fix
top-level-iteration
false positive with ref head vars (#854) (@anderseknert) - 39e57db: Clear the store when reloading config (#855) (@charlieegan3)
- 82fd171: More Rego completion providers (#858) (@anderseknert)
- 72f63aa: Precompute refs in file at update (#859) (@charlieegan3)
- 5cb412d: Drop print statement (#860) (@charlieegan3)
- f082b73: Improve performance of rulerefs (#861) (@charlieegan3)
- 0175ee4: Add new blog to README (#862) (@anderseknert)
- ec060ef: Add reviewdog/action-regal to the adopters file (#865) (@maruloop)
- 3b5b83e: docs: update adopters and roadmap (#866) (@anderseknert)
- 2fa61d7: Completions: package name suggested from any path component (#869) (@anderseknert)
- 6cebb1c: Add snippets provider (#870) (@anderseknert)
- 5a61015: Add snippet suggestion for metadata annotation (#871) (@anderseknert)
- 0dad5f0: OPA v0.66.0 (#873) (@anderseknert)
- 300eef2: perf: refactor to avoid excessive
walk
ing (#877) (@anderseknert) - ce8b8ff: Rule:
pointless-reassignment
(#878) (@anderseknert) - 23c3bf5: Docs: add separate page for language server features (#880) (@anderseknert)
- 67de577: Use OSSF scorecard (#884) (@anderseknert)
- 6b6ffc4: [StepSecurity] ci: Harden GitHub Actions (#885) (@step-security-bot)
- a4c96a4: Fix token permissions (#886) (@anderseknert)
- 8110bc5: Rule:
argument-always-wildcard
(#883) (@anderseknert) - 6153d57: Rule:
annotation-without-metadata
(#882) (@anderseknert) - 0ed98f9: build(deps): bump ossf/scorecard-action from 2.3.1 to 2.3.3 (#890) (@dependabot[bot])
- b412ac9: build(deps): bump actions/checkout from 4.1.1 to 4.1.7 (#892) (@dependabot[bot])
- 1e597c8: build(deps): bump github/codeql-action from 3.24.9 to 3.25.11 (#889) (@dependabot[bot])
- 7773c3c: build(deps): bump actions/upload-artifact from 3.pre.node20 to 4.3.3 (#891) (@dependabot[bot])
- b7c7385: Rule:
var-shadows-builtin
(#893) (@anderseknert) - 4ec7018: Fix negative number returned by rulerefs provider issue (#894) (@anderseknert)
- d000d21: Remove used refs completion provider (#896) (@anderseknert)
- bb790c5: Completions:
rulerefs
optimizations (#898) (@anderseknert) - 812ab2b: Fix bug causing
prefer-some-in-iteration
not to be reported (#902) (@anderseknert) - a18e386: Fix some
prefer-snake-case
violations not getting reported (#900) (@anderseknert) - 35d6703: build(deps): bump actions/upload-artifact from 4.3.3 to 4.3.4 (#903) (@dependabot[bot])
- 288d9c3: rule: Fix pointless issue when using with (#907) (@charlieegan3)
- bcfc9b7: Dependabot/go modules/GitHub.com/owenrumney/go sarif/v2 2.3.3 (#909) (@charlieegan3)
- a6e97af: docs: Update language server docs (#910) (@charlieegan3)
- 1efd82c: ls...
v0.23.1
This is a patch release containing a number of fixes. Most of the issues fixed in this release were not directly related to v0.23.0, but we simply don't like the idea of waiting for the next release to address known bugs.
Bugs fixed
- Ignore directives (like
# regal ignore:unresolved-import
) didn't work properly for aggregate rules (i.e. rules that require multiple files to determine if the rule is violated or not). That's now been fixed. Thanks @nejec for bringing this to our attention! - Fix missing rule type in the header of the unresolved-import rule documentation
- An empty
.regal/config.yaml
file would previously have Regal fail with an error. Now it'll simply print a warning and continue with the default configuration - Fix an issue in the language server where completion suggestions would sometimes repeat a word already typed in
- Remove an init call in the language server that would take ~100 milliseconds to process, even for commands that didn't make use of the language server (like
regal lint
) - The
regal lint --format json
would previously output errors as pretty-printed text rather than JSON. That has now been fixed. - The
textDocument/diagnostic
response from the language server is nownull
rather than an empty object. This solves an issue observed with the Neovim client.
Changelog
- 3bcdc33: docs: move code of conduct (#800) (@anderseknert)
- 69f4dcb: docs: set the rule type for unresolved-import (#804) (@charlieegan3)
- 29a9c85: docs: abs link for do.rq (#806) (@charlieegan3)
- e1ed668: Support ignore directives in aggregate rules (#809) (@anderseknert)
- 99f8463: lsp: Use text edit for builtins providers (#814) (@charlieegan3)
- 9091021: Use config.docs.resolve_url consistently (#813) (@anderseknert)
- c2ec08f: lint/fix: roll over empty config (#815) (@charlieegan3)
- 982d13b: lsp/refs: Just in time init for refs util (#816) (@charlieegan3)
- d0def34: cmd/lint: show JSON errors (#817) (@charlieegan3)
v0.23.0
This release adds 3 new linter rules to Regal, greatly improved completion suggestions in the language server, and a number of other improvements and fixes.
New rule: leaked-internal-reference
Category: bugs
Following the recently added style guide recommendation to use underscore prefixes to denote internal rules and functions, this was the first rule to help enforce that convention. The leaked-internal-reference
rule will flag any reference to a rule or function with an underscore prefix that is not defined in the same package:
package policy
import rego.v1
# this will be flagged, as `_allow` is considered internal to the `authz` package
allow if data.authz._allow
For more information, see the docs on leaked-internal-reference.
New rule: internal-entrypoint
Category: bugs
Rules annotated as entrypoints are public by definition and must not be prefixed with an underscore.
Avoid
package policy
import rego.v1
# METADATA
# entrypoint: true
_authorize if {
# some conditions
}
Prefer
package policy
import rego.v1
# METADATA
# entrypoint: true
allow if _authorize
_authorize if {
# some conditions
}
For more information, see the docs on internal-entrypoint.
New rule: ambiguous-scope
Category: idiomatic
The default scope for metadata annotating a rule is the rule
scope, which applies to the individual rule statement only. This default is sensible for a rule defined only once, but is somewhat ambiguous for a rule defined incrementally, like the allow
rule in the examples below. Was the intention really to annotate that single definition, or the rule as whole? Most likely the latter.
If only a single rule in a group of incremental rule definitions is annotated, it should have it's scope
set explicitly to either document
or rule
. If all incremental definitions are annotated, explicit scope: rule
is not required.
Avoid
# METADATA
# description: allow is true if the user is admin, or the requested resource is public
allow if user_is_admin
allow if public_resource
Prefer
# METADATA
# description: allow is true if the user is admin, or the requested resource is public
# scope: document
allow if user_is_admin
allow if public_resource
Or (scope rule
implied, but all incremental definitions annotated)
# METADATA
# description: allow is true if the user is admin
allow if user_is_admin
# METADATA
# description: allow is true if the requested resource is public
allow if public_resource
Or (scope rule
explicit)
# METADATA
# description: allow is true if the user is admin
# scope: rule
allow if user_is_admin
allow if public_resource
For more information, see the docs on ambiguous-scope.
For more information about the scope
metadata attribute, see the OPA docs.
Language server: Greatly improved completion suggestions
Last release introduced a minimal implementation of code completion, which means that the language server supports providing completion suggestions while editing Rego in an editor that supports the Regal languge server, such as VS Code using the OPA VS Code extension.
This release provides greatly improved completion suggestions, including:
- References to packages, rules and functions (both imported and complete references)
- Keywords like
import
,default
,contains
,if
- Completions on
input
attributes based on those previously used - Common rule names like
allow
anddeny
- New package names based on directory structure
- Many more suggestions based on the context of the cursor position
Using completion suggestions now feels like a total game changer for productivity, and we really recommend trying it out!
Other improvements
- Bump OPA version to v0.65.0
- Improve LSP implementation to better handle different clients
- Don't show completion suggestions for internal references outside of their package
- Show different types of icons in completion suggestions based on what's suggested
Docs
- Update README to reflect current LSP features
- Add new documentation page for integrating Regal in build pipelines (thanks @Parsifal-M!)
- Fix typo in messy-rule documentation (thanks @Parsifal-M!)
- Add instructions for installing Regal via asdf (thanks @smorimoto for providing the plugin!)
- Rename development.md -> CONTRIBUTING.md to align with convention
- Add SECURITY.md doc under
docs
directory
Bugs fixed
- Fixed false positive when importing
input
ordata
in ignored-import - Fix possible concurrent read of maps in completion provider
- Filter out ignored files in
regal fix
command (thanks @oren-zohar for reporting the issue!)
Breaking changes
These changes do not affect regular users of Regal, but possibly power users that have built their own custom rules relying on these helpers.
- Remove the
regal.json_pretty
built-in function. Users can now usejson.marshal_with_options
from OPA instead. - Remove the
ast.name
function in favor ofast.ref_to_string
Thank you to all contributors, community members and users! 🎉
If you have any questions, would like to discuss the release, or talk about Regal in general, you'll find us in the Styra Community Slack!
Changelog
- 0de5d4f: Use Go 1.22 (#737) (@anderseknert)
- e21051b: docs: update the readme with the lsp features (#738) (@charlieegan3)
- 153f9a0: Better align with specification based on Zed client testing (#741) (@anderseknert)
- c9d0868: lsp: ensure completion items is not null (#740) (@charlieegan3)
- eb30185: lsp: Identify Zed editor client (#742) (@charlieegan3)
- 87efaf1: fixes typo in messy rule docs (#744) (@Parsifal-M)
- 7b60e7c: Build pipeline docs (Github/Gitlab) (#743) (@Parsifal-M)
- f0875e3: Fix false positive when importing input/data in
ignored-import
(#747) (@anderseknert) - 10aa4b7: lsp: Add package/rule ref completions (#739) (@charlieegan3)
- e10ec82: Don't suggest completions for internal rules or functions (#754) (@anderseknert)
- 372185b: Use completion item kind table for completions icons (#756) (@anderseknert)
- 2275b89: Add completions for default and import keywords (#759) (@anderseknert)
- cf93614: lsp: Return copies of cache maps (#760) (@charlieegan3)
- cf030b4: cmd/fix: Filter files loaded for fixing (#762) (@charlieegan3)
- 285a12d: lsp/completions: Implement better package items (#763) (@charlieegan3)
- 48aa1db: lsp: Provide data ref completions in rules (#769) (@charlieegan3)
- 51bd977: lsp: completions for rule heads (#770) (@charlieegan3)
- 7ea6999: lsp: Show subpackage scope (#772) (@charlieegan3)
- e7a11ae: lsp: Rule head & input doc completion improvements (#773) (@charlieegan3)
- 51dd1f6: lsp: Enable common rule completions (#775) (@charlieegan3)
- 6c91202: OPA v0.65.0 (#777) (@anderseknert)
- 83ae84a: breaking: Remove
regal.json_pretty
built-in function (#785) (@anderseknert) - 2c095e6: Rule:
leaked-internal-reference
(#782) (@anderseknert) - 86c28d7: Rule:
internal-entrypoint
(#784) (@anderseknert) - 96329cf: Add asdf instructions (#786) (@anderseknert)
- d1799ae: Add info on Zed extension (#787) (@anderseknert)
- df57e69: lsp: Show docs for diagnostics in Zed (#789) (@charlieegan3)
- 3886d9d: Rename development.md -> CONTRIBUTING.md (#788) (@anderseknert)
- b4eaad3: Add basic security disclosure doc (#790) (@anderseknert)
- fdda4b5: lsp: implement used refs completions (#794) (@charlieegan3)
- f9e8949: build(deps): bump goreleaser/goreleaser-action from 5 to 6 (#796) (@dependabot[bot])
- 47c6247: Rule:
ambiguous-scope
(#795) (@anderseknert) - fdc479f: Prepare for goreleaser 2.0.0 (#797) (@anderseknert)
- 5f6e238: Refactor: remove
name
function in favor ofref_to_string
(#798) (@anderseknert) - 8...
v0.22.0
This is a release brings 3 new linter rules, as well as some exciting new features, improvements and fixes to both the linter and the language server.
New rule: impossible-not
Category: bugs
The impossible-not
rule will flag when the not
keyword is used to test a partial (multi-value) rule. Even when a set contains no values, it isn't considered "falsey", so using not
in that context is essentially a constant condition. This mistake is particularly common in tests:
package policy
import rego.v1
partial_rule contains item if {
# ...
}
package policy_test
import rego.v1
test_partial_rule if {
# This will now be flagged, as the not-condition is impossible
not partial_rule with input as {
# ...
}
}
Future versions of this rule may detect even more impossible not
conditions.
For more information, see the docs on impossible-not.
New rule: messy-rule
Category: style
Rules that are defined incrementally should be be placed in a sequence, and with no other rule definitions in between. The new messy-rule
linter will help identify such cases, and suggest a re-organization.
Avoid
package policy
allow if something
unrelated_rule if {
# ...
}
allow if something_else
Prefer
package policy
allow if something
allow if something_else
unrelated_rule if {
# ...
}
For more information, see the docs on messy-rule.
New rule: trailing-default-rule
Category: style
The new trailing-default-rule
linter will flag rules with default default
conditions where the default
assignment isn't placed before the other rules. Putting the default
rule first makes it easier to read the policy, knowing there's a default fallback condition for the rules requiring more complex conditions to be met.
Avoid
package policy
import rego.v1
allow if {
# some conditions
}
default allow := false
Prefer
package policy
import rego.v1
default allow := false
allow if {
# some conditions
}
For more information, see the docs on trailing-default-rule.
Language server: Code completion suggestions
The Regal language server now provides a minimal implementation of the code completion feature. This first implementation will help suggest package name based on directory structure, the rego.v1
import and built-in functions at certain locations. This provides a big productivity boost, as users no longer need to jump back to the OPA docs to find the built-in function they need.
More completion suggestions will follow in the next releases, like references to rules and functions. Stay tuned!
Other improvements
- The external-reference rule now detects more cases than previously (thanks @asleire for reporting this issue!)
- The
regal new rule
command now also creates an empty documentation template for the rule - The
regal fix
command now provides documentation for which rules it can fix - The language server will now send a warning back to the client if CRLF line endings are detected in a file (thanks @asleire for the suggestion!)
- The language server will now report parser errors on the whole line instead of just the first character, making them easier to spot
- The language server will now provide links to documentation for any error encountered that has corresponding docs
- Bump OPA version to v0.64.1
Bugs fixed
- Fix issues with loading config file on Windows
- Improve handling of inlay hints in files with parser errors
- Fix bug where
regal lint --profile
would report wrong metrics - Where needed, the language server now properly returns
null
instead of empty object, as per the specification (thanks @sspaink for raising that!) - The language server "find definition" feature now honors ignore directives found in the
.regal/config.yaml
file - Fix false positive in redundant-existence-check rule when the
with
keyword is used (thanks @asleire for reporting this issue!)
Changelog
- a106547: build(deps): bump golangci/golangci-lint-action from 5.0.0 to 5.1.0 (#692) (@dependabot[bot])
- 9a36acb: OPA v0.64.1 (#689) (@anderseknert)
- 32e995f: Use macos-13 for amd64 build (#690) (@anderseknert)
- 92eebc9: build(deps): bump golangci/golangci-lint-action from 5.1.0 to 5.3.0 (#694) (@dependabot[bot])
- 0c96e96: build(deps): bump golangci/golangci-lint-action from 5.3.0 to 6.0.0 (#697) (@dependabot[bot])
- f4eb0f8: Rule:
impossible-not
(#698) (@anderseknert) - f3daf4f: build(deps): bump golangci/golangci-lint-action from 6.0.0 to 6.0.1 (#702) (@dependabot[bot])
- 3abf326: lsp: Fix issue with parse error inlay hints (#701) (@charlieegan3)
- fc92818: lsp: URI to path conversions respect os.Separator (#703) (@charlieegan3)
- 904cb31: lsp: Rename lastValidLine variable (#704) (@charlieegan3)
- 2bda636: lsp: don't add "constant" to the document symbol description (#706) (@anderseknert)
- d826f64: report: Fix profile count aggregation (#707) (@charlieegan3)
- 2023f32: Add a few tasks for VS Code (#710) (@anderseknert)
- e225bda: Singe file
impossible-not
(#713) (@anderseknert) - 3e92381: Rule:
messy-rule
(#714) (@anderseknert) - 0b79d20: Add docs as part of
regal new rule
command (#715) (@anderseknert) - a5aa616: Rule:
trailing-default-rule
(#716) (@anderseknert) - 00ea15e: Send warning to client on CRLF line endings (#717) (@anderseknert)
- e9bc522: build(deps): bump github.com/fatih/color from 1.16.0 to 1.17.0 (#718) (@dependabot[bot])
- 6a17d1d: lsp/completions: Implement a minimal completions provider (#709) (@charlieegan3)
- 05098f2: lsp: Return null when no hover items (@charlieegan3)
- d54f730: Revert "lsp: Return null when no hover items" (@charlieegan3)
- f9065f6: Return
null
instead of empty structs (#721) (@anderseknert) - 85411cf: Some fixes for detecting external refs (#723) (@anderseknert)
- 8bd0650: lsp: parse errors lint whole line (#727) (@charlieegan3)
- e6056e5: docs: add docs for regal fix function (#726) (@charlieegan3)
- 1aa0f50: Various fixes (#730) (@anderseknert)
- 9d7530a: lsp: show correct opa error hint links (#728) (@charlieegan3)
- d1525ce: lsp: find definition should honor ignored files (#732) (@anderseknert)
- 1b0e3fa: Fix false positive in
redundant-existence-check
whenwith
is used (#734) (@anderseknert) - 2ca2df8: Update capabilities.json (#735) (@anderseknert)
- 9d148de: lsp: Fix ast error line index bug (#736) (@charlieegan3)
v0.21.3
No one wants to wait for bugs to get fixed! So we don't. This third patch release following v0.21.0 fixes an issue where deleted or renamed files would still have violations reported by the language server.
Changelog
- e170834: fix: Avoid panic in config finder (#686) (@anderseknert)
- 51c9a94: fix: make sure deleted items aren't added back to the cache (#685) (@anderseknert)
v0.21.2
This is patch release addressing two bugs reported by users.
The first bug fixed is in the new unresolved-import rule, where Regal would mistakenly report a reference to a map-generating rule as unresolved. Thanks @nevumx for making us aware of that issue!
The other bug fixed was a panic that could occur when Regal traverses directories looking for a config file. The cause of this is still not known, but at least we'll now fail gracefully and without a panic. Thanks @scoop96 for reporting the issue!
Changelog
- 0cb54f0: Fix false positive in
unresolved-import
and map rules (#680) (@anderseknert) - e42be60: build(deps): bump golangci/golangci-lint-action from 4.0.0 to 5.0.0 (#683) (@dependabot[bot])
- 0c3043d: Avoid panic when searching for
.regal/config.yaml
(#684) (@anderseknert)
v0.21.1
This patch releases fixes an issue in the language server, which would previously send back an error to the client (i.e. your editor) when a new and empty file was created in the workspace. This would have the server fail to read any document symbols as a result. This has now been fixed to only log the error on the server without sending it back to the client.
Thanks @johanfylling for reporting the issue!
Changelog
- 03c38aa: lsp: More graceful shutdown (#676) (@charlieegan3)
- 55a1294: fix: log but don't send back file read errors in documentSymbol handle (#678) (@anderseknert)
v0.21.0
This is a big release, bringing new regal fix
command, several features to the Regal language server, a new linter rule, and many improvements and fixes.
New command: regal fix
The regal fix
command allows you to automatically fix some of the (style) issues reported by the Regal linter. This command is available in the CLI and can be run on a single file or a directory. The following linter rules are supported by the regal fix
command:
More rules will be added in future releases.
The regal fix
command respects the .regal/config.yaml
file, and will only fix issues that aren't ignored by configuration.
New rule: unresolved-import
Category: imports
OPA does not resolve imports until runtime, and when it does, unresolved imports are simply undefined. The unresolved-import rule helps catch these issues early by flagging imports that can't be statically resolved by Regal. Since imports could refer to data documents or rules imported at runtime, this linter rule allows providing a list of of references that should be ignored by the linter.
For more information, see the docs on unresolved-import.
Language Server: Code Actions
Similarly to the regal fix
command, code actions allows fixing some issues reported by Regal but directly from the editor. This release adds code actions to remediate the following linter rules:
- opa-fmt
- use-rego-v1
- use-assignment-operator
- no-whitespace-comment
- Navigate to documentation of any reported linter issue
Language Server: Go to Definition
Ctrl/cmd + clicking a reference in the editor now navigates to the definition of the reference, as Regal now implements the "go to definition" feature of the language server protocol.
Language Server: Formatting
The Regal language server now supports formatting Rego files using the opa fmt
command. This can be triggered either by running the "Format document" command in your editor, or from where a opa-fmt
linter violation is reported in the package.
Language Server: Document Symbols
Symbols — like packages, rules and functions, are now provided by Regal upon requests from an editor. This allows for a quick overview of the structure of a Rego file, and provides "breadcrumbs" to navigate the symbols of an open Rego document.
Language Server: Workspace Symbols
Similarly to document symbols, Regal now reports symbols from the entire workspace, allowing users to search and navigate to any top-level symbol (i.e. package, rule or function) in the workspace.
Language Server: Folding Ranges
Regal now provides folding ranges for Rego files in the workspace, allowing users to fold (i.e. expand or collapse) blocks of code, comments and imports in the editor.
Other improvements
- The language server now searches for the
.regal/config.yaml
file in directories above the workspace if not found before. This allows using a shared configuration file for multiple projects. Thanks @bdjgs for requesting this feature! - Report not just the line but the exact position of use-assignment-operator violations
- The result of a hovering over a built-in function is now cached for faster rendering
Bugs fixed
- Fix bug where whitespace in directory names caused the language server to stop working. Thanks @frittsy for reporting this issue!
Documentation
- Fix wrong category of double-negative rule
Changelog
- de1ff4b: Code action for OPA fmt (#630) (@charlieegan3)
- 0f5b374: lsp: URI decode workspace URIs (#631) (@charlieegan3)
- 1255e7d: Refactor LSP logging (#632) (@charlieegan3)
- 128b5b4: Add quote from Jimmy Ray (#634) (@anderseknert)
- b5b6d56: Open docs code action (#635) (@charlieegan3)
- 5fbf293: Cache result of createHoverContent (#639) (@anderseknert)
- 37d87bf: rules: OPA fmt rule location fix (#633) (@charlieegan3)
- 6904ed9: Add code action for
use-rego-v1
(#640) (@anderseknert) - 8de5461: Implement textDocument/formatting (#641) (@anderseknert)
- 40ed03f: lsp: Accept but ignore cancelled requests (#642) (@charlieegan3)
- fe1dc3a: lsp: Enable formatting functionality (#643) (@charlieegan3)
- c31886e: lsp: Load config from parent dirs (#650) (@charlieegan3)
- ae359bf: Fix wrong category for
double-negative
rule (#652) (@anderseknert) - 8e253b4: Calculate correct column of
=
inuse-assignment-operator
(#655) (@anderseknert) - 63148df: Calculate column index from 1 in
use-assignment-operator
(#656) (@anderseknert) - 8c9b76b: lsp: Increase test buffered channel size (#657) (@charlieegan3)
- dfd9ee2: fixer: Regal fix command (#653) (@charlieegan3)
- 3e0fcd2: Rule:
unresolved-import
(#658) (@anderseknert) - c717dd6: lsp: fix flaky test (#660) (@charlieegan3)
- 5a8c5c1: lsp: refactor types (#662) (@charlieegan3)
- 8ae24da: lsp: Implement code actions for new fixes (#661) (@charlieegan3)
- c803b41: lsp: Support folding ranges (#663) (@anderseknert)
- 2a59305: lsp: handle
textDocument/documentSymbol
(#668) (@anderseknert) - f108c69: lsp: Error handling fixes (#669) (@charlieegan3)
- f546004: lsp: handle
textDocument/definition
requests (#664) (@anderseknert) - af1bdb8: Add LSP section to README (#674) (@anderseknert)
- 24c0b85: lsp: implement
workspace/symbol
(#673) (@anderseknert)