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: inconsistent-args #448

Merged
merged 1 commit into from
Nov 8, 2023
Merged

Rule: inconsistent-args #448

merged 1 commit into from
Nov 8, 2023

Conversation

anderseknert
Copy link
Member

Warn on inconsistent argument names in repeated function declarations.

Fixes #444

Base automatically changed from capabilities-for-rules to main November 8, 2023 13:00
@anderseknert anderseknert linked an issue Nov 8, 2023 that may be closed by this pull request
Copy link
Member

@johanfylling johanfylling left a comment

Choose a reason for hiding this comment

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

👍

bundle/regal/result.rego Show resolved Hide resolved
# regal ignore:prefer-some-in-iteration
name := ast.ref_to_string(ast.functions[i].head.ref)
args_list := [args |
some j
Copy link
Member

Choose a reason for hiding this comment

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

Probably won't make a dent on performance, but we could add a i != j here, right?

# regal ignore:prefer-some-in-iteration
args := ast.functions[j].head.args
]
count(args_list) > 1
Copy link
Member

Choose a reason for hiding this comment

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

Won't the arg list size always be > 1, as each rule is counted at least twice, once when iterating i and once for j?

Copy link
Member Author

Choose a reason for hiding this comment

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

But the args_list only iterates on j.


# regal ignore:prefer-some-in-iteration
name := ast.ref_to_string(ast.functions[i].head.ref)
args_list := [args |
Copy link
Member

Choose a reason for hiding this comment

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

We'd possibly get a perf boost by making args_list a set.

Copy link
Member

Choose a reason for hiding this comment

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

If we didn't need to account for primitives, we could then simply just have made a count(args_list) > 1 check 😄 .

Copy link
Member Author

Choose a reason for hiding this comment

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

We still need to iterate over it, so I don't think a set would perform better? 🤔


# Return the _second_ function found by name, as that
# is reasonably the location the inconsistency is found
find_function_by_name(name) := [fn |
Copy link
Member

Choose a reason for hiding this comment

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

Unless we can a pinpoint the first function with an actual argument name inconsistency, isn't it more clear to just point to the first function declaration.

Copy link
Member Author

Choose a reason for hiding this comment

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

Possibly, but the second function is at least arguably more likely to be inconsistent than the first :P

Warn on inconsistent argument names in repeated function declarations.

Fixes #444

Signed-off-by: Anders Eknert <[email protected]>
@anderseknert anderseknert merged commit 75ca4d1 into main Nov 8, 2023
2 checks passed
@anderseknert anderseknert deleted the inconsistent-args branch November 8, 2023 14:06
srenatus pushed a commit to srenatus/regal that referenced this pull request Oct 1, 2024
Warn on inconsistent argument names in repeated function declarations.

Fixes StyraInc#444

Signed-off-by: Anders Eknert <[email protected]>
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: inconsistent-args
2 participants