-
Notifications
You must be signed in to change notification settings - Fork 10
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
New codemod: use-generator #135
Conversation
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #135 +/- ##
==========================================
+ Coverage 96.29% 96.32% +0.03%
==========================================
Files 64 65 +1
Lines 2697 2721 +24
==========================================
+ Hits 2597 2621 +24
Misses 100 100
|
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.
Looks pretty good, just needs the builtin check.
@@ -0,0 +1,13 @@ | |||
Imagine that someone handed you a pile of 100 apples and then asked you to count how many of them were green without putting any of them down. You'd probably find this quite challenging and you'd struggle to hold the pile of apples at all. Now imagine someone handed you the apples one at a time and asked you to just count the green ones. This would be a much easier task. |
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.
Mostly a nitpick, but this is the kind of language I'd avoid in documentations. Be direct and on point.
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.
Maybe this is a little too whimsical but it's important to remember that a big part of our vision here involves educating developers and security professionals on best practices. This means we actually need to make our content as engaging as possible. I'm not necessarily saying I've succeeded in that here, but I'm going to leave it as-is and see what feedback we receive.
match original_node.func: | ||
# NOTE: could also support things like `list` and `tuple` | ||
# but it's a less compelling use case | ||
case cst.Name("any" | "all" | "sum" | "min" | "max"): |
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.
As you have pointed it out, those could use an extra step to check if they are builtin functions. You can do this using the ScopeProvider
. Query the metadata for assignments for this Name
node and check if it is a BuiltinAssignment
.
""" | ||
maybe_assignment = self.find_single_assignment(node) | ||
if maybe_assignment and isinstance(maybe_assignment, BuiltinAssignment): | ||
return matchers.matches(node.func, matchers.Name()) |
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 90% sure this is redundant, as in any function that that matches the if
predicate will have node.func
as Name()
.
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.
That's fair. I'll leave it for now but we could revisit.
Overview
Implement new codemod:
use-generator
Description
libcst
constructs