Releases: StyraInc/regal
v0.28.0
New Rule: missing-metadata #1131
The new missing-metadata
rule helps ensure policies are documented by requiring METADATA
comments on public packages and rules. Metadata comments are used to explain functionality and annotate Rego constructs with other data.
Note: missing-metadata
is a custom rule and so is not enabled by default for all users.
fixer: Automated fixing of directory-package-mismatch
This release brings improvements to regal fix
, the command to automatically fix supported violations (#1120, #1127).
Fixes for the directory-package-mismatch violations involve moving files based on their packages. For example a file with package foo.bar
in policies/policy.rego
would need to be moved to foo/policy.rego
. In previous versions of Regal, when multiple files in a large code base with the same filename needed to be moved to the same package directory, Regal would output a confusing error message.
Regal v0.28.0 outputs a clear error message by default and adds a new --on-conflict=rename
modifying flag to allow conflicting files to automatically be renamed when this scenario is encountered.
Linter Improvements
- Support for linting Rego syntax passed to Regal via Standard Input (stdin).
- An important yet under-the-hood improvement to use a new data format for AST node locations. This makes violation locations more specific and brings a 5% linting speed improvement too.
Language Server Performance Improvements
- An update to the implementation of the server to reduce the number of expensive ‘full workspace’ linting jobs. By caching the aggregate rule data and updating it incrementally, full workspace jobs can now be completed in less than a third of the time previously taken.
- Making CodeLenses configurable makes supporting other clients easier. Thanks @rinx for the work in #1176 and for all the work you do to make Regal and Neovim play nice.
- Update to the server templating to better handle projects without a Regal config file. Files in the workspace root will no longer be templated either, but will still violate directory-package-mismatch.
- Makes an improvement to ensure the loading of the Regal rules happens once, saving around 30ms on every keypress-trigger, file diagnostic update event.
Dependency Updates
Github Actions Updates
- golangci/golangci-lint-action 6.1.0 -> 6.1.1 #1163
- peter-evans/create-pull-request 7.0.3 -> 7.0.5 #1114
- github/codeql-action 3.26.7 -> 3.26.11 #1117, #1137, #1157, #1174
- actions/checkout 4.1.7 -> 4.2.0 #1142
- codecov/codecov-action 4.5.0 -> 4.6.0 #1162, #1164
- actions/cache 4.0.2 -> 4.1.0 #1179
Changelog
- 63ec93d: docs: correct line endings for GIF files (#1114) (@charlieegan3)
- 980f726: build(deps): bump peter-evans/create-pull-request from 7.0.3 to 7.0.5 (#1116) (@dependabot[bot])
- 54c8c9d: build(deps): bump github/codeql-action from 3.26.7 to 3.26.8 (#1117) (@dependabot[bot])
- 95a1bf3: tests: Minor test wait improvement (#1121) (@charlieegan3)
- 838c6fa: Allow
regal lint -
to lint from stdin (#1122) (@anderseknert) - a23bb63: fixer: Address rename conflicts with explanation (#1120) (@charlieegan3)
- 23cb827: fixer: add --on-conflict flag to support renaming (#1127) (@charlieegan3)
- d41bea9: debug: registering custom built-ins (#1128) (@johanfylling)
- 4aa2fef: tests: Address incorrect built-in function check (#1129) (@charlieegan3)
- f6f2f6d: Rule:
missing-metadata
(#1131) (@anderseknert) - ab3b3b8: tests: Remove global builtins state (#1134) (@charlieegan3)
- b424eb6: Use betteralign for struct alignment (#1132) (@anderseknert)
- 464a7bc: Completions: don't suggest loop vars as locals on same line (#1135) (@anderseknert)
- 6ecb36c: bundle: Load bundle once (#1136) (@charlieegan3)
- 7cd8744: build(deps): bump github/codeql-action from 3.26.8 to 3.26.9 (#1137) (@dependabot[bot])
- a201715: linter: support single file aggregate data collection and parameterised aggregate data in Lint() (#1139) (@charlieegan3)
- 2730887: Bump roast to v0.3.0 and live free from
annotations
on module (#1140) (@anderseknert) - 64cba9e: build(deps): bump actions/checkout from 4.1.7 to 4.2.0 (#1142) (@dependabot[bot])
- efd4420: Fix
detached-metadata
issues (#1143) (@anderseknert) - 75db465: Link to source code in rule docs (#1144) (@anderseknert)
- e205cd9: Go code cleanup (#1148) (@anderseknert)
- 3cba1c6: fix: fix var name for commit hash (#1150) (@rinx)
- 4a97b56: Adapt to new location format (#1153) (@anderseknert)
- 036a6b6: Bump OPA to v0.69.0 (#1152) (@anderseknert)
- 06db4bb: internal/lsp/hover: "fix" codeql finding (#1156) (@srenatus)
- bfc0f9e: internal/capabilities: update eopa caps (@srenatus)
- 1161ede: CONTRIBUTING: update script name (@srenatus)
- 81edb95: workflow: add update-caps (#1158) (@srenatus)
- f7acfda: build(deps): bump github/codeql-action from 3.26.9 to 3.26.10 (#1157) (@dependabot[bot])
- a55d2f4: Fix some minor issues reported by IntelliJ (#1159) (@anderseknert)
- 2f94fc7: Fix nits (#1161) (@srenatus)
- f208f46: build(deps): bump golangci/golangci-lint-action from 6.1.0 to 6.1.1 (#1166) (@dependabot[bot])
- 94fea76: build(deps): bump codecov/codecov-action from 4.5.0 to 4.6.0 (#1162) (@dependabot[bot])
- 7b5cd08: Exclude
print
from "function return value in args" check (#1165) (@anderseknert) - 8ca0197: Custom rule authoring improvements (#1168) (@anderseknert)
- 85b7be7: Bump roast to v0.4.2 to solve data race (#1170) (@anderseknert)
- 67162e6: lsp: Update LSP linting to run incrementally after file change (#1146) (@charlieegan3)
- f70b892: build(deps): bump github/codeql-action from 3.26.10 to 3.26.11 (#1174) (@dependabot[bot])
- fc88817: Correct example index rego path (#1177) (@charlieegan3)
- b751858: lsp/templating: gracefully handle unknown root (#1171) (@charlieegan3)
- 69fb6ca: Use test logger for client handler (#1178) (@charlieegan3)
- ed287dc: build(deps): bump actions/cache from 4.0.2 to 4.1.0 (#1179) (@dependabot[bot])
- 9503967: feat(lsp): add initialization options about codelenses (#1176) (@rinx)
v0.27.0
Debug Adapter Protocol Support
Back in #926 (v0.26.0), support was added for the Debug Adapter Protocol (DAP), based on the new OPA SDK added in #6876 (documentation). This release improves on this making it ready for consumption in clients. Namely, the addition of a new Debug Code Lens in #1103 and a bug fix for ast.ref_to_string
which brings the Regal implementation inline with OPA’s (#1106).
Please see our documentation here to get started.
Neovim DAP Support
Thanks to community member @rinx, DAP support is also available in the Neovim editor. This is based on nvim-dap, and @rinx’s own project nvim-dap-rego. This is an awesome contribution which represents an important improvement for Neovim users of Regal. Thank you Rintaro Okamura for all your work here, it is appreciated.
New Rule: comprehension-term-assignment
This rule flags cases where an intermediate assignment is used within a comprehension body when the value can be directly used as the comprehension term. It enforces the removal of redundant assignments, encouraging more concise and readable code.
# avoid
names := [name |
some user in input.users
name := user.name
]
# prefer
names := [user.name | some user in input.users]
Compiler Stage Source Explorer
A new Source Action has been added to allow users of compatible clients to explore the compiler stages of the Rego code they’re working on.
By integrating opa-explorer with Regal, it’s now possible to launch a web server to view the explorer output. Users will see a "Source Action" in the context menu of Rego files, which opens the explorer for that file. This feature is currently limited to VS Code due to available commands. Currently, only a single file is loaded into the explorer for compilation.
Source Action shown in VS Code
Browser showing the given file's compiler explorer
Test Flake Fixes
This release contains a number of fixes for flakey tests that have been disrupting the contributor experience. If you experience flakes and re-run checks on a PR, please leave a comment to let us know so we can look into it. #1112, #1102, #1101
Changelog
- b567b5d: Rule:
comprehension-term-assignment
(#1098) (@anderseknert) - da50d28: Add source action to explore compiler stages (#1096) (@anderseknert)
- a672964: lsp: Make length check of inlay hints fatal (#1101) (@charlieegan3)
- b4e5a8e: lsp: Update contents before diagnosticRequestFile (#1100) (@charlieegan3)
- d754094: Address races in test cases (#1102) (@charlieegan3)
- 822e42c: Add
Debug
Code Lens (#1103) (@anderseknert) - df31dda: More stringent ast.ref_to_string (#1106) (@anderseknert)
- ce26bbc: fix:
sprintf-arguments-mismatch
false positive when var used as format (#1107) (@anderseknert) - 67dc988: build(deps): bump peter-evans/create-pull-request from 7.0.1 to 7.0.2 (#1108) (@dependabot[bot])
- 7bf7685: docs/editor: write about nvim-dap (#1109) (@rinx)
- 03f14ff: build(deps): bump github/codeql-action from 3.26.6 to 3.26.7 (#1110) (@dependabot[bot])
- ba11c48: build(deps): bump peter-evans/create-pull-request from 7.0.2 to 7.0.3 (#1111) (@dependabot[bot])
- 06734bb: lsp: Address test concurrency issues (#1112) (@charlieegan3)
- f1606de: docs: Add docs for DAP support (#1113) (@charlieegan3)
v0.26.2
This releases contains a bug fixes for an issue introduced in v0.26.0 as well as a number of other minor improvements.
Notable Bug fixes:
- #1087 fixes an issue in the marshalling of ASTs using RoAST
- #1056 Makes a change to no longer suggest built in functions for default rules
- #1065 fixes an issue where git was required even when fixing in dry run mode
- #1069 fixes an edge case in
use-some-for-output-vars
- #1078, #1080, #1083, #1085 fix issues relating to file rename updates from the client
- #1093 addresses an issue where the fix command produced the incorrect result due to relative paths
- #1081 ensures that
.manifest
files are correctly detected as 'roots' when fixing
New features:
- #1059 updates the language server to suggest boolean values at relevant times
- #1088 adds a new feature for rule authors to use the files from their project as input for evaluation
Changelog
- b1afdf6: build(deps): bump peter-evans/create-pull-request from 7.0.0 to 7.0.1 (#1057) (@dependabot[bot])
- 9c6a0c9: completion: Don't show builtins on default rules (#1056) (@charlieegan3)
- dd9ee43: Increase test coverage (#1058) (@anderseknert)
- 410d775: lsp/completions: add boolean provider (#1059) (@charlieegan3)
- 337862e: tests: Fatal error when no inlay hints are found (#1060) (@charlieegan3)
- 1ef7511: cmd/fix: Only require git when dry-run unset (#1065) (@charlieegan3)
- 8778ec2: fix: Have
use-some-for-output-vars
find comprehension body vars (#1069) (@anderseknert) - d579c9c: build: introduce regal_standalone build flag, use for lint's "fix" hint (#1070) (@srenatus)
- 2690748: 100% test coverage (#1074) (@anderseknert)
- 2e07303: Remove
ast.all_refs
(#1076) (@anderseknert) - 332f6dd: Ensure custom rules docs are up to date (#1079) (@anderseknert)
- 28bac91: lsp: Address empty module issues on rename (#1078) (@charlieegan3)
- 6badb5d: lsp: Always send empty diagnostics when deleted (#1080) (@charlieegan3)
- 146895c: lsp: Correct Path to URI encoding (#1083) (@charlieegan3)
- 71e17a3: e2e: Sort output from fix hint (#1084) (@charlieegan3)
- a562087: Fix issue where .manifest files didn't register as roots (#1081) (@anderseknert)
- 786b89e: Bump roast to v0.2.0 to ensure annotations encodes correctly (#1087) (@anderseknert)
- 3bbfd1e: Add
regal eval:use-as-input
directive (#1088) (@anderseknert) - 0c1ef19: lsp: Rename on template (#1085) (@charlieegan3)
- 52f3377: lsp: Fix Eval issue caused by missing comments (#1091) (@charlieegan3)
- 6f9b32f: cmd/fix: Address relative path root matching (#1093) (@charlieegan3)
v0.26.1
This releases contains a bug fix for an issue introduced in v0.26.0. The bug was caused by a change the required data to complete a formatting Rego 'fix'.
Changelog
- 1cfdee9: Fix LSP formatting that broke in v0.26.0 (#1055) (@anderseknert)
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)