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)