Skip to content

v0.22.0

Latest
Compare
Choose a tag to compare
@github-actions github-actions released this 22 May 11:35
· 9 commits to main since this release
9d148de

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.

codecompletion

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