-
Notifications
You must be signed in to change notification settings - Fork 39
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
bundle: Add non-loop-expression rule #1401
Conversation
7ff418f
to
17c58e3
Compare
17c58e3
to
094959e
Compare
094959e
to
6f8b1ec
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome work here! Left a couple of comments but nothing blocking.
@@ -18,6 +18,8 @@ items contains item if { | |||
position := location.to_position(input.regal.context.location) | |||
line := input.regal.file.lines[position.line] | |||
|
|||
not endswith(trim_space(line), "=") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👏
There's nothing better than writing a Regal rule that finds issues in Regal.
bundle/regal/rules/performance/non-loop-expression/non_loop_expression.rego
Outdated
Show resolved
Hide resolved
bundle/regal/rules/performance/non-loop-expression/non_loop_expression.rego
Outdated
Show resolved
Hide resolved
`) | ||
|
||
sps == {"0": { | ||
5: { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting how the first level variable can't be numeric (due to that type checker bug), but seems to work for this next level. That should be fixed of course, but certainly out of scope for this PR :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah this was an ongoing pain when working on this one
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm hoping that @johanfylling can fix that in OPA soon :)
bundle/regal/rules/performance/non-loop-expression/non_loop_expression_test.rego
Outdated
Show resolved
Hide resolved
|
||
## Exceptions | ||
|
||
This rule cannot yet detect the following cases. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great!
Fixes StyraInc#93 Signed-off-by: Charlie Egan <[email protected]>
Signed-off-by: Charlie Egan <[email protected]>
Signed-off-by: Charlie Egan <[email protected]>
Signed-off-by: Charlie Egan <[email protected]>
Like we predicted, this rule costs a lot. 6 million allocations compared to main is probably a record! But the value of the rule is also great, so we'll have to make the best of it. Some perf tweaks help shave off at least 1 million allocations, and we're now down to 5. Next up, I'll be taking a look at where most of the cost in OPA is while evaluating this. Funnily, I also found a missing case in the `use-object-keys` rule I added just today, from seeing a set comprehension being used to get keys but not getting flagged by the rule. Turned out `object.keys` was also noticeably faster :) ``` 1872039250 ns/op 3277562680 B/op 64585680 allocs/op // main 1990034458 ns/op 3577600880 B/op 70427856 allocs/op // non-loop-expression PR 1981020667 ns/op 3515957384 B/op 69337090 allocs/op // use built-ins to get _exprs row 1976604792 ns/op 3518227272 B/op 69422952 allocs/op // inline ast.is_wildcard 1957780375 ns/op 3518962424 B/op 69226825 allocs/op // uglier loops 1923554667 ns/op 3501324176 B/op 68954057 allocs/op // object.keys(sps) ``` Signed-off-by: Anders Eknert <[email protected]>
This will be detected by another rule. Signed-off-by: Charlie Egan <[email protected]>
Signed-off-by: Charlie Egan <[email protected]>
Signed-off-by: Charlie Egan <[email protected]>
1210a55
to
daa95a3
Compare
Fixes #93
TODO:
print
statements