-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
misc: use codemod for optional chaining #13503
Conversation
any interest in an eslint rule too? |
A quick scan of this doesn't appear to have anything I wouldn't write myself, but for all these Node version bumps I'm always more in favor of letting code update in its own time. Unless there's a big benefit or it came up in an eng sync and everyone's generally excited about it for whatever reason, it ends up in but_why.gif land for me. It takes someone's review time and the author's time to make really sure there weren't any mistakes, and all the code being replaced honestly looks just fine. Maybe in a year or two it'll be anathema to be so liberal with our But again, there's nothing here I think I wouldn't prefer and is definitely a nice cleanup in a few places. If @adamraine's excited about it that seems fine. |
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.
If @adamraine's excited about it that seems fine.
I am actually excited about this. I remember the long &&
conditions made some of these files confusing when I first started working on Lighthouse. I think these changes will help anyone in that same situation.
speedIndexTs: speedIndex && speedIndex.timestamp, | ||
totalBlockingTime: totalBlockingTime && totalBlockingTime.timing, | ||
maxPotentialFID: maxPotentialFID && maxPotentialFID.timing, | ||
firstContentfulPaint: firstContentfulPaint?.timing, |
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.
👍
@@ -65,35 +65,31 @@ class TraceElements extends FRGatherer { | |||
* @return {number | undefined} | |||
*/ | |||
static getNodeIDFromTraceEvent(event) { | |||
return event && event.args && | |||
event.args.data && event.args.data.nodeId; | |||
return event?.args?.data?.nodeId; |
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.
These functions seem kinda obsolete now.
SG. I actually dislike the &&-existence-check pattern because it mixes control flow into types (typescript helps prevent errors with them but you still end up into these unnecessary type superpositions). |
thinking about this since, this seems like it might be a good idea just to avoid having to suggest it in code reviews. I can't think of a good reason for it ever to be a toss-up between the old Is there a good rule anywhere? There's |
Here is the output from that lint plugin on this PR.
I only checked a few, but they were all real, just for some reason missed by the codemod. We can followup in a new PR. |
I used this tool: https://github.com/villesau/optional-chaining-codemod
First commit is just running the tool on our code, no manual changes except reverting changes to compiled test files. Subsequent commits may be done for some touchups.
Misses a few files, because of villesau/optional-chaining-codemod#48