v0.8.0
This is the most feature-packed release to date, adding a new output format, four new rules, and many improvements across the board!
New GitHub output format
The regal lint
command now accepts a new --format
option named github
. This is ideal for when Regal is run in CI/CD scenarios using GitHub Actions. This format will emit annotations for any violation, which will be visible in the pull request file view.
In addition to this, the GitHub output format will also create a linter report visible in the "Checks" tab:
This report summarizes the result of linting, with links provided to the documentation for any violation.
New rule: use-some-for-output-vars
Category: idiomatic
Using some
to declare output variables used in iteration (and elsewhere) has long been considered a best practice. Regal can now identify places where variables are introduced without some
and treat these as errros:
allow {
userinfo := data.users[id]
# ...
}
Unless the id
variable in the above example is declared elsewhere in the policy, it should be declared using some
:
allow {
some id
userinfo := data.users[id]
# ...
}
# alternatively, and arguably more idiomatic:
allow {
some id, userinfo in data.users
# ...
}
For more information, see the docs on use-some-for-output-vars.
New rule: prefer-some-in-iteration
Category: style
Similarly, the new prefer-some-in-iteration
rule will have Regal warn when using the "old" style of iteration which could be replaced in favor of some ... in
:
engineers[employee] {
employee := data.employees[_]
employee.role in engineering_roles
}
# Prefer some .. in
engineers[employee] {
some employee in data.employees
employee.role in engineering_roles
}
An exception to this rule may deeply nested iteration, where the shorter syntax is often preferable. Regal thus allows configuring the rule to allow exceptions from any given nesting level.
For more information, see the docs on prefer-some-in-iteration.
New rule: metasyntactic-variable
Category: testing
Using rule and variable names like "foo", "bar" or "baz" might be convenient in examples, but rarely has a place in production policy. The new metasyntactic-variable
rule will flag any occurences of these names. The ignore
directive may of course be used to e.g. allow these type of variables in tests or other legitimate locations.
For more information, see the docs on metasyntactic-variable.
New rule: file-length
Category: style
Having policy files span several hundred lines of code is often a signal to consider refactoring the code into smaller units, and to modularize properly using packages and imports. The new file-length
rule by default flags any file with more than 500 lines. This number can be changed via the rule's configuration.
For more information, see the docs on file-length.
Other improvements
In addition to the above features, this release comes with many smaller improvements to code, documentation and the pre-commit-hooks — not to mention a bunch of bugs that got fixed. Thanks to everyone who contributed to this release!
Changelog
- d906c0e: use-assignment-operator docs: Use := in Prefer example (#253) (@anderseknert)
- d466086: Update readme links to docs.styra.com (#255) (@charlieegan3)
- 2bf1476: Rule: use-some-for-output-vars (#254) (@anderseknert)
- 867d585: Some doc fixes (#256) (@anderseknert)
- 79275b5: Added
import future.keywords.if
where it belongs in the example. (#259) (@dkorolev) - 603cbd8: Update development docs (#262) (@mcguiresm)
- 12b72e3: Update builtin_metadata.rego (@anderseknert)
- 91fdf58: Add
use-some-for-output-vars
to table in README (#257) (@anderseknert) - 5b9aaae: Allows multiple # comments (#268) (@Parsifal-M)
- 241698b: Enable pre-commit hook for all hook types (#270) (@jharrisonSV)
- 2b3d7ed: Filter out files before parsing (#272) (@anderseknert)
- 1fdedad: Add GitHub output format (#273) (@anderseknert)
- 4bcfac0: Rule: prefer-some-in-iteration (#263) (@anderseknert)
- de1fc97: Ensure rule "name" logic works without rule.head.name (#278) (@anderseknert)
- a554c3e: bundle: rearrange embed.FS setup (#279) (@srenatus)
- 1e6418d: Rule: metasyntactic-variable (#280) (@anderseknert)
- e86f87d: Refactor: improve config.for_rule ergonomics (#281) (@anderseknert)
- 3a5f666: Rule: file-length (#283) (@anderseknert)
- f78e4a2: Bump dependencies (#284) (@anderseknert)
- 6253cae: Add
--debug
flag toregal lint
command (#287) (@anderseknert)