This release of Regal updates to OPA v1.1.0, continuing to solidify support for v1 Rego with some nice new rules, performance improvements and bug fixes too.
New Rule: use-object-keys
There are some cases where using object.keys
is preferred over using comprehensions. For example:
Avoid
package policy
keys := {k | some k, _ in input.object}
Prefer
package policy
keys := object.keys(input.object)
This is preferred as it more clearly communicates the intent of the code, that is, to get the keys of the object rather than loop over it and collect the keys as you go. More details can be found on the use-object-keys rule page.
New Rule: non-loop-expression
Expressions in loops are evaluated in each iteration of the loop and so it's advisable to avoid using expressions which do not depend on the loop variable within the looping part of a rule in order to improve performance.
Avoid
package policy
allow if {
some email in input.emails
admin in input.roles # <- this is not required in the loop
endswith(email, "@example.com")
}
Prefer
package policy
allow if {
admin in input.roles # <- moved out of the loop
some email in input.emails
endswith(email, "@example.com")
}
This rule can't catch all cases, so still be on the look out. More details can be found on the non-loop-expression rule page.
Fixing non-raw-regex-pattern
The non-raw-regex-pattern
rule can now be automatically fixed with regal fix
or with a CodeAction for language server clients. #1382
Configuration File Loading
Regal will now use a ~/.config/regal
if no parent configuration is found. This is useful when working on Rego in temporary directories. #1378
Regal's language server will now use configuration files in the workspace tree if they exist rather than only looking at parent directories. This more closely matches the behavior of the lint command. #1372
Notable Improvements
- Avoid 'error' paths in our linting Rego to reduce allocations. #1351, #1360, #1374
- Implement the
opa-fmt
rule using in Rego, removing the need for a Go rule
linting path entirely. #1393 - More consistently use shared functions and remove dead code to make Regal easier to maintain. #1349,
#1392, #1383, #1379, #1358, #1356, #1355 - @anaypurohit0907 made their first PR in #1369 adding a new summary to the end of the compact report showing the number of files and violations. Also, #1387 adds a similar improvement to the end of the default 'Pretty' reporter output breaking down errors and warnings.
- Documentation for the
deprecated-builtin
rule now explains the upgrade process. #1366, thanks @tsandall for the suggestion!
Notable Fixes & Updates
- The
use-if
rule will now use only the rule name as the violation location, rather than the whole rule. #1362 - Parse errors are now shown in file diagnostics to language server clients
after a regression. #1408 - @jglasovic made their first PR in #1345
fixing a bug where the Debug CodeLens was left enabled. - Better handling of
.regal.yaml
file use. #1357, thanks @grosser for the input here. - Some great new open source adopters! #1384, thanks @chendrix for the Regal amigurumi!
Changelog
- 1eff70a: fix: lsp - filter out
regal.debug
codelens (#1345) (@jglasovic) - 93faa40: [create-pull-request] automated change (@charlieegan3)
- 193224a: [create-pull-request] automated change (@charlieegan3)
- 434dabf: build(deps): bump golangci/golangci-lint-action (#1350) (@dependabot[bot])
- d7f522e: Add workspace folder type, and "support" that capability (#1347) (@anderseknert)
- a5d1742: Language server refactoring (#1349) (@anderseknert)
- 7b693ee: perf: move config check out of loop (#1351) (@anderseknert)
- d9749f4: lsp: Ensure parse errors are saved as diagnostics correctly (#1352) (@charlieegan3)
- bea7398: Fix missing annotations in LSP parsing (#1354) (@anderseknert)
- 0a17534: chore: Use regal's parse options following (#1355) (@charlieegan3)
- 760b484: fix: Remove mandatory fixes (#1356) (@charlieegan3)
- 2b25493: config: Search for .regal.yaml and use for roots (#1357) (@charlieegan3)
- 6880526: Remove custom Ref stringer (#1359) (@anderseknert)
- 0d506bb: refactor: better use of test helpers (#1358) (@anderseknert)
- b29ad44: perf: always include
ignore_files
in data (#1360) (@anderseknert) - 856bf50: The compact output format should include a summary #1364 (#1369) (@anaypurohit0907)
- 9020000: Some style fixes (#1370) (@anderseknert)
- f78f94b: fix: better location reporting in
use-if
rule (#1362) (@anderseknert) - 1175266: docs: deprecated built-in replacements (#1366) (@anderseknert)
- 33408e5: Add optional govet checks (#1368) (@anderseknert)
- 1db229a: Small fixes (#1367) (@anderseknert)
- 6430f86: build(deps): bump the dependencies group with 3 updates (#1371) (@dependabot[bot])
- 14cbc3b: Bump OPA to v1.1.0 (#1373) (@anderseknert)
- e1247ea: Don't return error from
regal.last
(#1374) (@anderseknert) - 0e794a2: lsp: Use nested workspace configuration if found (#1372) (@charlieegan3)
- d41c3da: [create-pull-request] automated change (#1376) (@github-actions[bot])
- 1f9e2e4: Use .Keys() and .KeysSorted() from OPA (#1379) (@anderseknert)
- a295fef: config: Use global user config if required (#1378) (@charlieegan3)
- 1a3fcfb: linter: Show error if rule or category is invalid (#1381) (@charlieegan3)
- 0e38b37: Add a few more adopters (#1384) (@anderseknert)
- cb81676: build(deps): bump the dependencies group with 2 updates (#1385) (@dependabot[bot])
- 4777c2b: build(deps): bump github/codeql-action in the dependencies group (#1386) (@dependabot[bot])
- be9bc33: fix: non-raw regex pattern (#1382) (@charlieegan3)
- 13a4980: lsp: Add statsviz for profiling visuals (#1388) (@charlieegan3)
- ba53d75: Consistently use new
Set
type (#1383) (@anderseknert) - 4347b8a: lsp/test: Error in test should be log instead (#1389) (@charlieegan3)
- 8c15f1c: [create-pull-request] automated change (@charlieegan3)
- a283bee: Remove unused fixer code (#1392) (@anderseknert)
- 194116f: Rego-based opa-fmt (#1393) (@anderseknert)
- 69e3756: Be specific about number of errors vs warnings in regal lint summary #821 (#1387) (@anaypurohit0907)
- 48c9e5e: Some minor cleanups in reporter code (#1397) (@anderseknert)
- a4e3592: Fix false positive in
unused-output-variable
(#1398) (@anderseknert) - c75d66f: Rule:
use-object-keys
(#1399) (@anderseknert) - 52c7c9b: refactor: simplify data bundle creation (#1400) (@anderseknert)
- 3e6ef5b: [create-pull-request] automated change (#1402) (@github-actions[bot])
- 674e441: lsp: update log messages for root dir note (#1395) (@charlieegan3)
- 76e0760: build(deps): bump the dependencies group with 2 updates (#1404) (@dependabot[bot])
- c6d1a9d: Roast v0.8.1 (#1406) (@anderseknert)
- 539ba39: bundle: Add non-loop-expression rule (#1401) (@charlieegan3)
- 06af4df: lsp: Correctly parse eval and debug params (#1407) (@charlieegan3)
- b29e759: lsp: show parse errors in diagnostics (#1408) (@charlieegan3)