-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
[$500] Create an ESLint rule to detect multiple uses of withOnyx #27463
Comments
Triggered auto assignment to @mallenexpensify ( |
Job added to Upwork: https://www.upwork.com/jobs/~01f185d4f92edd4f6c |
Triggered auto assignment to @puneetlath ( |
Triggered auto assignment to Contributor-plus team member for initial proposal review - @mollfpr ( |
ProposalPlease re-state the problem that we are trying to solve in this issue.
What is the root cause of that problem?Sometimes developers do not notice that What changes do you think we should make in order to solve the problem?Create a new eslint rule in https://github.com/Expensify/eslint-config-expensify/blob/main/eslint-plugin-expensify/ called export default compose(
withOnyx({
isCheckingPublicRoom: {
key: ONYXKEYS.IS_CHECKING_PUBLIC_ROOM,
initWithStoredValues: false,
}
}),
withOnyx({
isSidebarLoaded: {
key: ONYXKEYS.IS_SIDEBAR_LOADED,
},
})
)(Component) What alternative solutions did you explore? (Optional)N/A |
ProposalPlease re-state the problem that we are trying to solve in this issue.Create an ESLint rule to detect multiple uses of withOnyx What is the root cause of that problem?Feature request What changes do you think we should make in order to solve the problem?We should add a new rule to https://github.com/Expensify/eslint-config-expensify/tree/main/eslint-plugin-expensify to check if We can achieve it with something like this: module.exports = {
create(context) {
const callStack = [];
return {
CallExpression: (node)=> {
if (node.callee.name === 'withOnyx') {
callStack.push(node);
}
if (callStack.length > 1) {
context.report({
node: callStack[callStack.length - 1],
message: "Multiple calls to 'withOnyx' function are not allowed in a file.",
});
}
},
};
},
}; Where we count how many times What alternative solutions did you explore? (Optional) |
ProposalPlease re-state the problem that we are trying to solve in this issue.Create an ESLint rule to detect multiple uses of What is the root cause of that problem?Feature request for Create an ESLint rule to detect multiple uses of What changes do you think we should make in order to solve the problem?We should add a new rule to https://github.com/Expensify/eslint-config-expensify/tree/main/eslint-plugin-expensify to check if
In the above example, the error is reported if there are multiple What alternative solutions did you explore? (Optional)If we want to show the error directly on any multiple
|
@tgolen To clarify the lint only detect multiple compose(
withOnyx({
A,
}),
withOnyx({
B
})
) Or also detect compose(
withPolicy,
withOnyx({
A,
})
) |
I was really only thinking of targeting multiple I didn't consider about the second example, but I am guessing we don't have very many HOCs that use |
@needpower Could you elaborate on your solution to show the error on multiple Onyx calls? @alitoshmatov Seems nice, but it will be great if we show the error on all other Onyx calls, not just on the first duplicate.
@ZhenjaHorbach Great idea, but I prefer to stick to the expectation above. Also, please don't leave the root cause section empty. @studentofcoding Could you explain why we need to add |
Hey @mollfpr, we can benefit from adding
But, if we want to only run the checking on specific files that opened, then the alternative approach will be sufficient (with also using and extending the pattern that we already have for other ESLint rule)
|
@mollfpr You are right we can achieve that by following code module.exports = {
create(context) {
const callStack = [];
return {
CallExpression: (node)=> {
if (node.callee.name === 'withOnyx') {
callStack.push(node);
}
if (callStack.length > 1) {
context.report({
node: callStack[callStack.length - 1],
message: "Multiple calls to 'withOnyx' function are not allowed in a file.",
});
}
},
};
},
}; Where we report an error on every last instance of |
Thanks @studentofcoding, for the explanation. I think our automatic action is to run @alitoshmatov Could you update that to your proposal? Thanks! |
Just for another context, the fix on @alitoshmatov above are already apart on my initial Alternative solution here 4 days before @mollfpr |
Updated my proposal - #27463 (comment) |
I believe @alitoshmatov is posting it first. A couple of proposals seem similar, just different in the logic of showing the error. I think there's no difference on which it's better, so I'll choose the first posted proposal that works. The proposal from @alitoshmatov looks good to me! 🎀 👀 🎀 C+ reviewed! |
Triggered auto assignment to @neil-marcellini, see https://stackoverflow.com/c/expensify/questions/7972 for more details. |
Although I understand that the order matters, I believe the correctness and thoroughness of details (in this case, using all modules we already used on another ESLint) will also add the point for choosing a proposal. But, if it's not, then I just want to speak my mind about this, cheers! |
@mollfpr I actually like @studentofcoding's proposal better because the program exit thing seems like a good idea, and more importantly he used the correct error message mentioned in the issue. In the interest of speed I'm going to hire him now, hopefully everyone feels good about this. |
📣 @mollfpr 🎉 An offer has been automatically sent to your Upwork account for the Reviewer role 🎉 Thanks for contributing to the Expensify app! |
📣 @studentofcoding 🎉 An offer has been automatically sent to your Upwork account for the Contributor role 🎉 Thanks for contributing to the Expensify app! Offer link |
Thanks, @neil-marcellini Upon Reading the Readme on https://github.com/Expensify/eslint-config-expensify it's said that the PR should be there, therefore it's ready to review on Expensify/eslint-config-expensify#73 @mollfpr @tgolen |
Hey @MelvinBot the PR is merged yesterday (takes 2 days) |
Hey @tgolen, as the PR is merged 6 days ago, and @MelvinBot didn't automatically report it. I believe the waiting time for payment is only 1 day left and tomorrow it should be released right? |
I believe so, but I am not involved in that part of the process too much. @mallenexpensify might know better since he is handling the payment side for this issue. |
Thanks for it @tgolen, This is also happening on another PR, in which we have to change the Title of the Issue. If I need to do anything, do let me know @mallenexpensify, thanks! |
Can we have a guide on this condition @mallenexpensify ? Thanks! |
Contributor: @studentofcoding paid $750 via Upwork, includes 50% urgency bonus |
confirming payment for @mollfpr internally |
@mallenexpensify I should be paid via Upwork since I already have the contract for this issue. |
Thanks @mollfpr , I agree, updated the above to reflect you've been paid via Upwork! |
Problem
When
withOnyx
is used multiple times while composing components, it adds overhead to what Onyx has to keep track of and also prevents optimizations like batched render updates from working to their full potential.Solution
Create a custom ESLint in https://github.com/Expensify/eslint-config-expensify/tree/main/eslint-plugin-expensify which detects when
withOnyx()
is used multiple times in the same file, and throws an error. The error should give instructions on the best practices which is something like:That should also link to the Onyx readme, and I'm going to write a specific section in there about the best practice that we can link to.
Upwork Automation - Do Not Edit
The text was updated successfully, but these errors were encountered: