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

[No QA] Fix all optional chains and nullish coalescing operator + update style guide #5988

Merged
merged 5 commits into from
Oct 22, 2021

Conversation

marcaaron
Copy link
Contributor

@marcaaron marcaaron commented Oct 21, 2021

Details

This banishes optional chains and nullish coalescing operator from the codebase (for now). We have not explicitly said not to use this so I've added it to the style guide with alternatives that should be used instead. It is far more common to use lodashGet for property access and a || short circuit to default to a value where undefined or null is found.

Fixed Issues

$ #5985
$ #5986

Tests / QA Steps

All of these changes should be syntax and shouldn't have any bearing on the app behavior.
Therefore, we just need to run regular regressions.

Tested On

  • Web
  • Mobile Web
  • Desktop
  • iOS
  • Android

Screenshots

Web

Mobile Web

Desktop

iOS

Android

@marcaaron marcaaron requested a review from a team as a code owner October 21, 2021 23:23
@marcaaron marcaaron self-assigned this Oct 21, 2021
@MelvinBot MelvinBot requested review from aldo-expensify and removed request for a team October 21, 2021 23:23
STYLE.md Outdated
@@ -175,6 +175,23 @@ Empty functions (noop) should be declare as arrow functions with no whitespace i
}
```

## Accessing Object Properties and Default Values

Use `lodashGet()` to safely access object properties and `||` to short circuit null or undefined values that are not guaranteed to exist in a consistent way throughout the codebase. In the rare case that you want to consider a falsy value as usable and the `||` operator prevents this then be explicit about this in your code and check for the type using an underscore method e.g. (`_.isBoolean(value)` or `_.isEqual(0)`).
Copy link
Contributor

@aldo-expensify aldo-expensify Oct 22, 2021

Choose a reason for hiding this comment

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

Minimal detail... I think you are not supposed to have parenthesis after "e.g.", or another option could be:

...the type using an underscore method (e.g. _.isBoolean(value) or _.isEqual(0))

@marcaaron
Copy link
Contributor Author

Updated

@aldo-expensify
Copy link
Contributor

Updated

I just read that we are deprecating lodashGet, are you planning to replaced the lodashGet for _.get in this PR?

@marcaaron
Copy link
Contributor Author

Ah no, I'm just changing the readme here. I have another PR that will accomplish this.

@@ -292,7 +309,8 @@ So, if a new language feature isn't something we have agreed to support it's off
Here are a couple of things we would ask that you *avoid* to help maintain consistency in our codebase:

- **Async/Await** - Use the native `Promise` instead
- **Optional Chaining** - Use `lodash/get` to fetch a nested value instead
- **Optional Chaining** - Use `_.get()` to fetch a nested value instead
Copy link
Contributor

@aldo-expensify aldo-expensify Oct 22, 2021

Choose a reason for hiding this comment

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

Is _ underscore? or lodash? maybe we should clarify since we have both libraries or... we asume _ is underscore because that is how we normally import underscore?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's underscore since whenever we use lodash we prefix with lodash*

Copy link
Contributor

@aldo-expensify aldo-expensify left a comment

Choose a reason for hiding this comment

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

Looks good to me! waiting for E2E to merge.

@marcaaron marcaaron merged commit 5be6076 into main Oct 22, 2021
@marcaaron marcaaron deleted the marcaaron-nullCoales branch October 22, 2021 20:47
@OSBotify
Copy link
Contributor

✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release.

@OSBotify
Copy link
Contributor

🚀 Deployed to staging by @marcaaron in version: 1.1.8-10 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅

@roryabraham roryabraham changed the title Fix all optional chains and nullish coalescing operator + update style guide [No QA] Fix all optional chains and nullish coalescing operator + update style guide Oct 25, 2021
@OSBotify
Copy link
Contributor

🚀 Deployed to production by @roryabraham in version: 1.1.10-2 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅

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.

3 participants