Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rule: messy-rule #672

Closed
anderseknert opened this issue Apr 22, 2024 · 0 comments · Fixed by #714
Closed

Rule: messy-rule #672

anderseknert opened this issue Apr 22, 2024 · 0 comments · Fixed by #714

Comments

@anderseknert
Copy link
Member

anderseknert commented Apr 22, 2024

While working on support for document symbols, one of the open questions was how to best represent Rego's incremental rule definitions for a format that largely expects location ranges for identification. @charlieegan3 suggested a rule to enforce that incremental rules and function definitions are grouped together in a package. So something like this would be discouraged:

package p

allow if something

unrelated_rule if {
    # ...
}

allow if something_else

In favor of:

package p

allow if something

allow if something_else

unrelated_rule if {
    # ...
}

Looking at the Regal code base, we're violating this frequently ourselves 😅 And since it "doesn't matter" it's easy to forget about without tooling to help enforce this. Needless to say, this would be a style category rule, or possibly even custom if we think this should be optional. But as the document symbols feature showed us, even style can have a real-world impact.

@anderseknert anderseknert changed the title Rule: messy-rules Rule: messy-rule May 13, 2024
anderseknert added a commit that referenced this issue May 13, 2024
Help identify incremental rule definitions that aren't grouped together.

Fixes #672

Signed-off-by: Anders Eknert <anders@styra.com>
anderseknert added a commit that referenced this issue May 13, 2024
Help identify incremental rule definitions that aren't grouped together.

Also fix two violations against this rule that we had in our own codebase.

Fixes #672

Signed-off-by: Anders Eknert <anders@styra.com>
anderseknert added a commit that referenced this issue May 13, 2024
Help identify incremental rule definitions that aren't grouped together.

Also fix two violations against this rule that we had in our own codebase.

Fixes #672

Signed-off-by: Anders Eknert <anders@styra.com>
anderseknert added a commit that referenced this issue May 13, 2024
Help identify incremental rule definitions that aren't grouped together.

Also fix two violations against this rule that we had in our own codebase.

Fixes #672

Signed-off-by: Anders Eknert <anders@styra.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

1 participant