-
Notifications
You must be signed in to change notification settings - Fork 149
feat: add support for resolves/rejects matchers in async queries #64
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
Conversation
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! Just one small thing: can you add some examples using resolves
and rejects
to await-async-query
valid examples within its doc?
Btw those util methods you added for checking this look like could be extracted in the future for checking proper resolves/rejects in other rules, so let's keep an eye on that in case we can reuse it in the future 💪
@@ -101,3 +105,18 @@ function isPromiseResolved(node) { | |||
// promise.then(...) | |||
return hasAThenProperty(parent); | |||
} | |||
|
|||
function hasClosestExpectResolvesRejects(node) { | |||
if (!node.parent) { |
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.
Is this necessary? Because on L34 the function is called with isAwaited(node.parent.parent)
, which implies that node.parent
cannot be undefined
.
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.
Good catch. I initially wrote a utility function called findClosestExpectCall
that was supposed to be reusable. At that time the node.parent
thing was necessary because the function was recursive. Then I refactored it and indeed, it's not necessary.
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 tried to remove the node.parent
check and test broke which is, in the end, logical. While isAwaited(node.parent.parent)
implies node.parent
cannot be undefined
, it's very possible that hasClosestExpectResolvesRejects
goes beyond node.parent.parent
(until the Program
node) in case you're not using an expect
statement.
I'll add the examples 😉 About the util methods, we could look into converting the codebase to typescript, especially this package: typescript-eslint/experimental-utils! |
I would also be in favor of that, as it makes working with the AST much easier and safer with the type declarations. |
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.
lgtm
Can we merge it then @Belco90 ? |
Sure! On it, sorry. |
🎉 This PR is included in version 1.5.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
I think I'll create a project within this github repo so we can discuss which things we need to address to migrate the plugin to TS and split proper work. |
Closes #51