-
-
Notifications
You must be signed in to change notification settings - Fork 541
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
feat(lint): support class methods in noFloatingPromises #5028
Conversation
CodSpeed Performance ReportMerging #5028 will not alter performanceComparing Summary
|
42789b0
to
62b4b6f
Compare
62b4b6f
to
8994cb5
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.
Thank you @kaykdm, the code looks good, however this checks only class declarations, and doesn't check for class expressions. We should add them
.ancestors() | ||
.skip(1) | ||
.find_map(|ancestor| { | ||
if ancestor.kind() == JsSyntaxKind::JS_CLASS_DECLARATION { |
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.
A class can be initialised as an a declaration or an expression. This means we have to cover expressions too. They have a different node. Check the playground:
class A {}
const b = class {}
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 have added support for class initialized as an expression.
Also, I have added support for method calls from outside of the Class
class Test {
async returnsPromise(): Promise<string> {
return 'value';
}
}
const test = new Test();
test.returnsPromise(); // diagnostic here
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.
Thank you. It seels that class expression aren't supported yet:
const b = class {}
Do you plan to do that in 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.
Oh, I see! Now I understand what you mean.
I will do that tomorrow. If you want to merge this PR now, please go ahead, and I will create a separate PR for adding that support.
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 created a PR! #5098
Support for unnamed class expressions in noFloatingPromises
was already implemented when I added support for named class expressions, as shown below. However, the test cases were missing, so I have added test cases for unnamed class expressions.
const b = class B {}
crates/biome_js_analyze/src/lint/nursery/no_floating_promises.rs
Outdated
Show resolved
Hide resolved
crates/biome_js_analyze/src/lint/nursery/no_floating_promises.rs
Outdated
Show resolved
Hide resolved
1c8d3cf
to
df9db9f
Compare
5e2016d
to
a405360
Compare
1768d6e
to
3a7f181
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.
Thank you @kaykdm
I will merge this PR so you can look at the class expression in a separate PR
Summary
related: #3187 and #4956
This pull request introduces the support for class methods in
noFloatingPromises
Example of invalid code:
calling an async method in the same class
calling an async method from the parent class
property method
functions
calling an async method from outside
Example of valid code: