8000 Releases · StyraInc/regal · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Releases: StyraInc/regal

v0.34.0

30 May 13:07
47c70f0
Compare
Choose a tag to compare

After a month of development, we're happy to announce Regal v0.34. This version of the OPA community's favorite linter and language server brings you new 3 linter rules, performance improvements and much more.

With the v0.34.0 release, Regal now ships with more than 100 linter rules! 🎉
Which is pretty close to one new rule per week since the project started.

New rules

unresolved-reference

Category: imports

This one is particularly exciting! The new unresolved-reference rule reports any references (like data.users.permissions) that cannot be resolved (i.e. found) anywhere in the project. Some projects will have valid references that can't be resolved at the time Regal lints the project, and the rule provides configuration options to mark certain references, or entire paths (like data.users.*) as resolved. See the docs for the rule for more details.

This rule was contributed by @HookFirebolt and @bdumpp at Bankdata. Great work, and thank you both!

pointless-import

Category: imports

The new pointless-import rule will flags imports of the same package, and other import forms where the import has no real effect.

single-item-in

Category: idiomatic

The single-item-in rule reports cases of in being used on a single item collection, and suggests using an equality check instead.

Performance

  • Use OPA v1.5.0, which brings performance improvements to walk reducing linting time by about 10%.
  • Faster linting by avoiding walk in a few locations where possible.
  • Improve performance of aggregate rules.
  • Several performance optimizations to Regal's linter rules.

API

  • The linter API now has a new Prepare method that can be used to prepare the linter before reusing it across several runs.

Various

  • Some rules that would previously only scan the topmost level of a rule body will now recursively scan the whole rule.
  • The input completions provider has been rewritten in Rego (previously Go).
  • The automatic version check has been rewritten in Rego (previously Go).

Bugs

Docs

Changelog

v0.33.1

22 Apr 13:01
61e8bf6
Compare
Choose a tag to compare

This release adds 4 new linter rules to Regal, alongside significant performance improvements and several bug fixes.

New Rule: in-wildcard-key

Using a wildcard variable (_) for the key in the key-value form of iteration (some _, value in collection) is never needed, and can be replaced by the simple some value in … form . This rule flags cases where the key iteration is redundant. (Read more)

package policy

allow if {
    # Avoid: key iteration ('_') is redundant if only 'user' is used
    some _, user in input.users
    # do something with each user
}

allow if {
    # Prefer: clearer intent when only iterating values
    some user in input.users
    # do something with each user
}

PR #1466

New Rule: confusing-alias

While import aliases can improve readability, aliasing an import reference that is also imported without an alias is confusing, as both names point to the same resource. This rule catches such cases. (Read more)

package policy

# Avoid: both 'users' and 'employees' point to data.resources.users
import data.resources.users
import data.resources.users as employees

# Prefer: a single import for any given resource
# import data.resources.users

PR #1470

New Rule: mixed-iteration

Rego supports different styles of collection iteration. While "reference style" iteration (collection[_]) can be concise for deeply nested structures, mixing it with the some .. in style within a single iteration expression makes for code that’s more difficult to follow. This rule encourages consistency within a single iteration statement. (Read more)

package policy

allow if {
    # mixing 'some .. in' and reference iteration
    some resource in input.assets[_]
    # do something with resource
}

allow if {
    # using 'some .. in' iteration consistently
    some asset in input.assets
    some resource in asset
    # do something with resource
}

PR #1475

New Rule: narrow-argument

This new rule analyzes function arguments to suggest narrowing them down to the minimal value the function depends on. This can improve clarity and reusability. The rule considers incrementally defined functions across all their definitions. This is a powerful but opinionated rule and is thus in the custom category and is not on by default. See the documentation for how to enable it if you’re curious to try it out! (Read more)

package policy

# Avoid: the function only uses the 'email' property of the 'user' object
valid_user(user) if endswith(user.email, "acmecorp.com")
valid_user(user) if endswith(user.email, "acmecorp.org")

# Prefer: narrowing the argument to only what the function needs
valid_email(email) if endswith(email, "acmecorp.com")
valid_email(email) if endswith(email, "acmecorp.org")

PR #1488

Performance Improvements

Several improvements have been made to reduce memory allocations and improve overall linting performance. Numbers below refer to Regal’s benchmark for linting its own policies.

  • Optimized config loading and parsing, saving around 2.7 million allocations (#1491).
  • Reduced allocations by approximately 2 million (#1494).
  • Improved the performance of the use-strings-count rule, saving almost 1 million allocations (#1465).
  • Optimized reference comparisons and small iteration patterns, saving around 300k allocations (#1472).
  • Included performance enhancements alongside an update to the external-reference rule to make it more configurable (#1496).

OPA v1.3.0

Regal has been upgraded to use OPA v1.3.0. This brings several upstream improvements, including support for the new one-liner grouping in formatting (see OPA#6760). (#1459)

Bug Fixes

  • Fixed a bug in the handling of Rego input from stdin. Thanks @tokyowizard for the report! (#1474)
  • Fixed a panic that could occur in FindConfigRoots when supplied with unexpected arguments. (#1487)

Other Rule Updates

  • The external-reference rule can now be configured with a maximum number of allowed external references, instead of solely flagging all external uses within a function. If you previously had this rule disabled, you might want to try enabling it now, and possibly tweak its configuration to your liking. (#1496)
  • The rule-length rule now has a separate setting (max-test-rule-length) with a higher default value (60 vs 30) for test rules, acknowledging that tests often include substantial data. (#1476)
  • Updated documentation for the rule-named-if rule based on community feedback received via the page feedback form (please let us know if you see issues! & thanks for the report!) (#1463)

Dependencies

This release also updates Regals dependencies as follows.

Go Mod:

GitHub Actions:

Changelog

Read more

v0.33.0

22 Apr 12:26
61e8bf6
Compare
Choose a tag to compare

This release is the same tag as v0.33.1, please see that release for the release notes.

Another v0.33.1 was released to trigger the rebuilding of some assets that were deleted in a draft release.

v0.32.0

25 Mar 17:34
fe6de2e
Compare
Choose a tag to compare

This release adds 3 new linter rules to Regal, as well as many improvements and fixes.

New Rule: redundant-loop-count

A loop iterating over empty collections evaluates to nothing, and counting the collection before the loop to ensure it's not empty is therefore redundant. This rule catches cases where this check is not needed. (Read more)

package policy

allow if {
    # redundant count and > comparison
    count(input.user.roles) > 0

    some role in input.user.roles
    # .. do more with role ..
}

PR #1452.

New Rule: import-shadows-rule

This new rule catches cases where users have named rules the same as an import. Imported identifier have higher precedence than rules and this can lead to confusing behaviours. (Read more)

package policy

import data.resources

# 'resources' shadowed by import 
resources contains resource if {
    # ...
}

PR #1450.

Thanks @kroekle for suggesting this rule!

New Rule: time-now-ns-twice

This new rule will catch cases where time.now_ns() is called multiple times within a single rule. This does not work in Rego since both calls will return the same value. This rule catches this case early and directs users to read about more appropriate tools. (Read more)

package policy

timed if {
    now := time.now_ns()
    # do some work here
    # this doesn't work! result is always 0
    print("work done in:", time.now_ns() - now, "ns)
}

PR #1457.

Other Rule Updates

OPA v1.2.0

While this may not seem too exciting, OPA v1.2.0 contains some performance improvements that has quite a substantial impact on Regal. We know, because we made those improvements in OPA largely to speed up Regal's linting! v0.32.0 should be considerably faster than previous versions, which should be noticeable in large policy projects in particular.

Language Server

In the language server, we addressed two bugs relating to the fixing of the idiomatic/directory-package-mismatch rule. See #1427 & #1432.

Dependencies

Go Mod:

GitHub Actions:

See #1453, #1442, #1435, #1426, #1422 and #1423 for PRs making the above updates. golangci-lint v2 update in #1455. OPA 1.2 update in #1429.

New Users

Add yourself to docs/adopters.md to get here next time!

New Contributors

Changelog

v0.31.1

25 Feb 21:36
4fd08cb
Compare
Choose a tag to compare

This patch release fixes some issues reported by users, as well as some encountered while working on Regal. Most notably:

  • Fix issue where an absolute path to the config file wouldn't work on Windows (thanks @geirs73 for reporting this!)
  • Fix issue where configured ignore values had no effect if Regal ran from the root directory (thanks @nevumx for the issue!)
  • Fix issue in language server when files with : in their name are present in the workspace
  • Fix issue in language server where Code Lens annotations (like Evaluate and Debug) would appear and reappear quickly when parse errors where encountered and fixed, leading to a "flickering" editor window

Changelog

v0.31.0

11 Feb 16:56
b29e759
Compare
Choose a tag to compare

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< 8000 /h1>

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

v0.30.2

16 Jan 17:41
2c6ee8e
Compare
Choose a tag to compare

This release includes a fix for an issue where a missing Regal dir would cause a fatal error when running regal fix (#1341), thanks @grosser for the report again.

Also included is an a fix for an issue where Regal would template files without a Regal extension after renaming them from a Rego file.

Changelog

v0.30.1

16 Jan 14:58
5986638
Compare
Choose a tag to compare

Regal v0.30.1 is a patch release following the significant v0.30.0 release with first class OPA v1.0.0 support. This patch release addresses some issues discovered in the language server relating to the OPA update as well as a minor new feature.

New options for Regal config location

In addition to the .regal/config.yaml path we've used thus far, it's now possible to use a .regal.yaml instead. This is intended to be used by those preferring a single file rather than a dedicated directory. The config directory will still be required for users with custom rules. It is not possible to use $root/.regal/config.yaml and $root/.regal.yaml in the same directory at the same time. Regal will still use the config file nearest the root in the directory hierarchy, even if they are of different types. Thanks to @grosser for the suggestion!

Changelog

Full Changelog: v0.30.0...v0.30.1

v0.30.0

13 Jan 15:27
351b5bb
Compare
Choose a tag to compare

Regal v0.30.0 is the first release to fully support OPA 1.0 while at the same time being fully compatible with older versions of OPA and Rego. This process helped improve both Regal and OPA, as a few things to fix in both projects got identified along the way!

Full support for OPA 1.0, while maintaining compatibility with earlier versions

Regal now seamlessly supports working with both pre-1.0 and 1.0+ policies, or even a mix of both! See Regal's new documentation on OPA 1.0 to learn more about how to get the most out of Regal when working with Rego of any version.

As part of this upgrade, all the Regal docs have now been updated to use OPA/Rego 1.0 syntax, in examples and anywhere else Rego is used.

Finally, and perhaps needless to say — Regal itself and all of its linter policies are now upgraded to OPA 1.0!

Much Faster Linting

A mission that started out with the goal of improving the performance of Regal's linter, ended up with multiple PR's
to improve evaluation performance in OPA. This of course benefits not just Regal, but all users of OPA! However, since
the regal lint command was used for benchmarking, most optimizations have been along the hot path of that command.

Linting with Regal is now almost 2x as fast as before, while consuming 2/3 of the memory previously needed. And we have
more improvements lined up in OPA for the next release, so stay tuned!

Notable Improvements

  • The evaluation code lens now supports using an input.yaml file as input, in addition to input.json. Thanks @mrgadgil for suggesting this feature!
  • The redundant-existence-check rule now also reports redudant checks of function arguments
  • New InputFromTextWithOptions functions for users of the Go API
  • Faster evaluation by avoiding custom function calls in hot path
  • Reduced time to evaluation by performance improvements in Roast input conversion
  • The language server now logs the version of Regal and the path to the binary at startup, helping users know which Regal binary is being used

Notable Fixes

Changelog

v0.29.2

15 Nov 09:16
20a5cfa
Compare
Choose a tag to compare

This patch release fixes an issue where the new defer-assignment rule would sometimes report a false positive when the variable was used inside of a with clause on the next line.

Thanks @nevumx for reporting the issue!

Changelog

0