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: duplicate-rule #530

Merged
merged 1 commit into from
Jan 11, 2024
Merged

Rule: duplicate-rule #530

merged 1 commit into from
Jan 11, 2024

Conversation

anderseknert
Copy link
Member

As the name implies, flag duplicate rules when found. See the docs included in the PR for more details, including current limitations.

This rule should be an aggregate rule, but it was hairy enough to pull off with a single file scope, so I decided to hold off on that for now. This provides value already, so let's ship it and consider looking into making this aggregate later.

Fixes #427

# Remove whitespace from textual representation of rule and create a hash from the result.
# This provides a decent, and importantly *cheap*, approximation of duplicates. We can then
# parse the text of these suspected duplicate rules to get a more exact result.
rules_hashed := [crypto.md5(regex.replace(text, `\s`, "")) | some text in rules_as_text]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
rules_hashed := [crypto.md5(regex.replace(text, `\s`, "")) | some text in rules_as_text]
rules_hashed := [crypto.md5(regex.replace(text, `\s+`, "")) | some text in rules_as_text]

Might be a tiny bit faster?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright :)

Copy link
Member

@charlieegan3 charlieegan3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!

As the name implies, flag duplicate rules when found. See the docs included
in the PR for more details, including current limitations.

This rule should be an aggregate rule, but it was hairy enough to pull off
with a single file scope, so I decided to hold off on that for now. This
provides value already, so let's ship it and consider looking into making
this aggregate later.

Fixes #427

Signed-off-by: Anders Eknert <anders@styra.com>
@anderseknert anderseknert merged commit 071463b into main Jan 11, 2024
3 checks passed
@anderseknert anderseknert deleted the duplicate-rule branch January 11, 2024 13:03
srenatus pushed a commit to srenatus/regal that referenced this pull request Oct 1, 2024
As the name implies, flag duplicate rules when found. See the docs included
in the PR for more details, including current limitations.

This rule should be an aggregate rule, but it was hairy enough to pull off
with a single file scope, so I decided to hold off on that for now. This
provides value already, so let's ship it and consider looking into making
this aggregate later.

Fixes StyraInc#427

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
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rule: duplicate-rule
2 participants