Skip to content

Releases: StyraInc/regal

v0.23.1

10 Jun 13:58
d0def34
Compare
Choose a tag to compare

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 now null rather than an empty object. This solves an issue observed with the Neovim client.

Changelog

v0.23.0

05 Jun 19:41
89d3a7a
Compare
Choose a tag to compare

This is a 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 and deny
  • 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 or data 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 use json.marshal_with_options from OPA instead.
  • Remove the ast.name function in favor of ast.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

Read more

v0.22.0

22 May 11:35
9d148de
Compare
Choose a tag to compare

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

v0.21.3

26 Apr 10:24
51c9a94
Compare
Choose a tag to compare

No one wants to wait for bugs to get fixed! So we don't. This third patch release following v0.21.0 fixes an issue where deleted or renamed files would still have violations reported by the language server.

Changelog

v0.21.2

25 Apr 14:47
0c3043d
Compare
Choose a tag to compare

This is patch release addressing two bugs reported by users.

The first bug fixed is in the new unresolved-import rule, where Regal would mistakenly report a reference to a map-generating rule as unresolved. Thanks @nevumx for making us aware of that issue!

The other bug fixed was a panic that could occur when Regal traverses directories looking for a config file. The cause of this is still not known, but at least we'll now fail gracefully and without a panic. Thanks @scoop96 for reporting the issue!

Changelog

v0.21.1

24 Apr 15:15
55a1294
Compare
Choose a tag to compare

This patch releases fixes an issue in the language server, which would previously send back an error to the client (i.e. your editor) when a new and empty file was created in the workspace. This would have the server fail to read any document symbols as a result. This has now been fixed to only log the error on the server without sending it back to the client.

Thanks @johanfylling for reporting the issue!

Changelog

v0.21.0

23 Apr 12:01
24c0b85
Compare
Choose a tag to compare

This is a big release, bringing new regal fix command, several features to the Regal language server, a new linter rule, and many improvements and fixes.

New command: regal fix

The regal fix command allows you to automatically fix some of the (style) issues reported by the Regal linter. This command is available in the CLI and can be run on a single file or a directory. The following linter rules are supported by the regal fix command:

More rules will be added in future releases.

The regal fix command respects the .regal/config.yaml file, and will only fix issues that aren't ignored by configuration.

New rule: unresolved-import

Category: imports

OPA does not resolve imports until runtime, and when it does, unresolved imports are simply undefined. The unresolved-import rule helps catch these issues early by flagging imports that can't be statically resolved by Regal. Since imports could refer to data documents or rules imported at runtime, this linter rule allows providing a list of of references that should be ignored by the linter.

For more information, see the docs on unresolved-import.

Language Server: Code Actions

Similarly to the regal fix command, code actions allows fixing some issues reported by Regal but directly from the editor. This release adds code actions to remediate the following linter rules:

Screenshot 2024-04-23 at 10 25 14

Language Server: Go to Definition

Ctrl/cmd + clicking a reference in the editor now navigates to the definition of the reference, as Regal now implements the "go to definition" feature of the language server protocol.

Screenshot 2024-04-23 at 10 37 02

Language Server: Formatting

The Regal language server now supports formatting Rego files using the opa fmt command. This can be triggered either by running the "Format document" command in your editor, or from where a opa-fmt linter violation is reported in the package.

Language Server: Document Symbols

Symbols — like packages, rules and functions, are now provided by Regal upon requests from an editor. This allows for a quick overview of the structure of a Rego file, and provides "breadcrumbs" to navigate the symbols of an open Rego document.

Screenshot 2024-04-23 at 14 00 14

Language Server: Workspace Symbols

Similarly to document symbols, Regal now reports symbols from the entire workspace, allowing users to search and navigate to any top-level symbol (i.e. package, rule or function) in the workspace.

Screenshot 2024-04-23 at 07 26 20

Language Server: Folding Ranges

Regal now provides folding ranges for Rego files in the workspace, allowing users to fold (i.e. expand or collapse) blocks of code, comments and imports in the editor.

Screenshot 2024-04-23 at 10 45 44

Other improvements

  • The language server now searches for the .regal/config.yaml file in directories above the workspace if not found before. This allows using a shared configuration file for multiple projects. Thanks @bdjgs for requesting this feature!
  • Report not just the line but the exact position of use-assignment-operator violations
  • The result of a hovering over a built-in function is now cached for faster rendering

Bugs fixed

  • Fix bug where whitespace in directory names caused the language server to stop working. Thanks @frittsy for reporting this issue!

Documentation

Changelog

v0.20.1

09 Apr 15:47
e16ffba
Compare
Choose a tag to compare

This release fixes a panic encountered in the language server when Regal traverses a directory it cannot read while walking the workspace.

Thanks @frittsy for reporting the issue!

Changelog

v0.20.0

08 Apr 12:36
6df97b3
Compare
Choose a tag to compare

This release adds various improvements to the functionality of the language server as well as also including a number of housekeeping updates and fixes.

Language Server: Hover support for built-in function definitions

The language server protocol supports requesting information about the tokens under the cursor. This release implements support for such requests when users are hovering over Rego's built-in functions. Clicking the link in the tooltip heading will take you to the OPA docs for that built-in.

318763769-c21a5954-abd2-4ea6-a758-bec233687491

Language Server: Inlay Hints

Inlay Hint requests are also supported from this release. Inlay hints are allow named function arguments to be shown as users edit function calls.

screenshot_2024-04-03_at_14 17 30

Improvements

  • Running the language server with --verbose will now show the full request response logs.
  • File ignore config is now also supported by the language server.
  • Unresolved imports are not flagged as part of prefer-package-imports

Updates

  • This release updates OPA to v0.63.0, see the OPA changelog for more detail.
  • Go SARIF has also been updated to 2.3.1

Changelog

v0.19.0

18 Mar 17:00
4f559f2
Compare
Choose a tag to compare

This release adds several new options for setting configuration options for rules in groups, allowing users to keep a static configuration across updates, or to ignore certainly classes of rules. v0.19.0 also includes a number of fixes to both linter rules and the language server integration, making for an even better experience when using Regal from VS Code or other LSP clients.

New default rule configuration option

The rules section in the Regal configuration file may now include a default attribute either at the top level, or in any specific category. This allows enabling/disabling entire categories of rules, or to avoid Regal to "break" CI/CD builds on updates if new rules are introduced. While it's arguably good to have new problems surfaced, we recognize that some organizations value stability first, and may opt for more controlled upgrades.

Example, using a default configuration to ignore all rules except for those explicitly listed:

rules:
  default:
    level: ignore
  bugs:
    constant-condition:
      level: error
    deprecated-builtin:
      level: error
    duplicate-rule:
      level: error

Example, using a default configuration to enable all rules except for those in the style category:

rules:
  default:
    level: error
  style:
    level: ignore

To learn more about the new default option, and the precedence rules for the various ways to ignore rules, see the Regal docs.

Fixes

  • Fix false positive in prefer-some-in-iteration in function args
  • Fix false positive in several rules not counting imports in scope
  • Many fixes and improvements related to the LSP integration — see the changelog below for details

Changelog