Skip to content
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

Change operator || to ?? where reading environmental valuable [Fixes #12057] #12058

Merged
merged 2 commits into from
May 7, 2024

Conversation

HiroyukiNaito
Copy link
Contributor

Change operator || to ?? where reading environmental valuable [Fixes #12057]

Description

When reading environmental valuables, it is safer to use '??' operator.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Nullish_coalescing

Related Issue

#12057

Copy link

netlify bot commented Jan 30, 2024

Deploy Preview for ethereumorg ready!

Name Link
🔨 Latest commit 113e81b
🔍 Latest deploy log https://app.netlify.com/sites/ethereumorg/deploys/65bb29925729690008bdccfa
😎 Deploy Preview https://deploy-preview-12058--ethereumorg.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link
Member

@wackerow wackerow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, thanks for the PR @HiroyukiNaito

I agree with the const LIMIT_CPUS = Number(process.env.LIMIT_CPUS ?? 2) change, since notably the nullish coalescing operator ?? will allow 0 to be passed without it being treated as falsy (which we want).

Oddly, I have my LIMIT_CPUS env var set to 0 locally and this is still working (using 0 instead of 2)... not totally sure why, but I'm in favor of updating this to the more appropriate operand.


The other two I don't think we need/want.

?? false is redundant... In either case, this value will either be undefined (if env var not declared) or an empty string "" (if env var declared but left blank), both of which will be treated as "falsy" in the ternary expression beneath it. This is the desired outcome, as both of these should fall back to using all locales.

In the case of the siteUrl, we would NOT want to accept an empty string here...

image

Similar to how 0 is accepted with ??, an empty string is also accepted, and will not fall back to the right-hand of the expression. Using || will treat "" or 0 as falsy and move to the right side or the operand to use the hard-coded fallback.


Let me know if that makes sense, or if I'm missing something. cc @pettinarip curious if you have thoughts

@HiroyukiNaito
Copy link
Contributor Author

@wackerow Thank you for the deep insight.
I would change the code according to your description.

@HiroyukiNaito
Copy link
Contributor Author

@wackerow
I changed codes according to your advice.

Copy link
Member

@wackerow wackerow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thanks @HiroyukiNaito! Lgtm =)

@wackerow wackerow merged commit 65357cb into ethereum:dev May 7, 2024
6 checks passed
This was referenced May 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug report: Refactoring by using The Nullish Coalescing Operator (??) in settings files
2 participants