-
-
Notifications
You must be signed in to change notification settings - Fork 458
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
Implement most of the Eslint plugin promise #4252
Conversation
Your org has enabled the Graphite merge queue for merging into mainAdd the label “merge” to the PR and Graphite will automatically add it to the merge queue when it’s ready to merge. Or use the label “hotfix” to add to the merge queue as a hot fix. You must have a Graphite account and log in to Graphite in order to use the merge queue. Sign up using this link. |
a3e0f0a
to
45b57c0
Compare
CodSpeed Performance ReportMerging #4252 will degrade performances by 3.97%Comparing Summary
Benchmarks breakdown
|
99c861c
to
8975004
Compare
Ok, this PR is clearly way too big and I just discovered the ability to make a util::promise module which seems to be good to refactor a bunch of rules. Moving this into a draft and I'll split up some commits. |
8975004
to
dec5ba5
Compare
return; | ||
}; | ||
|
||
if ident.name == "Promise" && ctx.semantic().is_reference_to_global_variable(ident) { |
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 wondering what is common in oxlint here, there is:
let AstKind::NewExpression(new_expr) = node.kind() else {
return;
};
if !new_expr.callee.is_specific_id("Array") {
return;
}
Which would also run for:
class Array {};
const list = new Array(5).map(_ => {});
So that seems like it should be refactored?
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.
And maybe we should get is_global_id("Array", ctx)
which also checks if the global reference.
return true; | ||
} | ||
|
||
// foo().then(foo => {}), needed? |
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 still have no idea what case this handles :-)
if member_expr.object().is_specific_id("Promise") | ||
&& matches!( | ||
prop_name, | ||
"resolve" | "reject" | "all" | "allSettled" | "race" | "any" | "withResolvers" |
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.
This should be moved to a utility, see previous rule which checks literally the same thing.
@@ -403,3 +403,34 @@ pub fn is_function_node(node: &AstNode) -> bool { | |||
_ => false, | |||
} | |||
} | |||
|
|||
pub fn is_promise(call_expr: &CallExpression) -> bool { |
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.
Move to utils::promise instead.
|
||
impl ParamNames { | ||
fn check_parameter_names(&self, params: &FormalParameters, ctx: &LintContext) { | ||
if params.items.len() < 1 { |
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_empty() instead?
Two rules need to be branch aware:
|
@jelly I'll save my review for when you've split this PR up. Feel free to request one when you're ready. |
Yes, we have a CFG. While it isn't documented, It's already used in some rules that you can study; Some of these rules are pretty similar to what you want for example To find all rules relying on CFG use the The graph itself uses petgraph and you can use its Since we don't have a CFG visualization on our website(yet) you can create a Then you can copy the content of the Keep in mind the output of this dotfile is really dirty and is meant to be used for deep debugging purposes. To get a more simple dot output you should use Since as of now I'm the only one who used our new CFG, I'm looking forward to your feedback and bug reports😅 |
44af4c5
to
c01a85d
Compare
Split off the easy part in #4293 |
…prefer-await-to-then` rule (#4318) Part of #4252 --------- Co-authored-by: wenzhe <[email protected]>
Seems there are only two rules not implemented(promise/no-promise-in-callback, promise/no-return-wrap), can we close this PR as a placeholder? |
Sure! |
One rule promise/param-names is part of the eslint-config-standard so would be useful for oxlint to support. But only supporting one rule seems a bit unreasonable so I looked at at least implementing a few of the rules which got out of hand fast....
So this PR implements 10 out of the 15 rules. Some rules lack the explanation why this is bad because such documentation does not exists, there are multiple issues about it eslint-community/eslint-plugin-promise#214 and eslint-community/eslint-plugin-promise#109
Some of the leftover rules are a bit debatable if they are useful such as no-native, disallowing native Promise implementations. And most folks seem to disable the rule.
Leftover rules:
I am happy to split up this PR into multiple smaller PR's if this is too big to review.