-
-
Notifications
You must be signed in to change notification settings - Fork 526
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
base: next
Are you sure you want to change the base?
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
let js_this_expression = any_js_expression.as_js_this_expression()?; | ||
let js_name = static_member_expr.member().ok()?; | ||
let value_token = js_name.value_token().ok()?; | ||
if !check_this_expression(js_this_expression, &value_token.to_string(), model)? { |
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.
Most of the times, you don't want to use to_string
. You want to use methods like text_trimmed()
or inner_string_text
to_string
allocates a string.
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 replaced it with text_trimmed
class_member_list: JsClassMemberList, | ||
target_name: &str, | ||
) -> Option<AnyJsClassMember> { | ||
class_member_list.into_iter().find(|member| match member { |
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.
class_member_list.into_iter().find(|member| match member { | |
class_member_list.iter().find(|member| match member { |
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.
fixed!
1c8d3cf
to
df9db9f
Compare
5e2016d
to
a405360
Compare
1768d6e
to
3a7f181
Compare
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: