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

Fix consistent-return issues #9192

Merged
merged 2 commits into from
Aug 12, 2020

Conversation

whymarrh
Copy link
Contributor

Refs #8982

See consistent-return for more information.

This change enables consistent-return and fixes the issues raised by the rule.

See [`consistent-return`](https://eslint.org/docs/rules/consistent-return) for more information.

This change enables `consistent-return` and fixes the issues raised by the rule.
@whymarrh whymarrh force-pushed the enable-consistent-return branch from 7087edd to 912ef2a Compare August 12, 2020 17:10
@whymarrh whymarrh marked this pull request as ready for review August 12, 2020 17:35
@whymarrh whymarrh requested review from kumavis and a team as code owners August 12, 2020 17:35
@whymarrh whymarrh requested a review from danjm August 12, 2020 17:35
@@ -327,7 +327,7 @@ function setupController (initState, initLangCode) {
const isMetaMaskInternalProcess = metamaskInternalProcessHash[processName]

if (metamaskBlockedPorts.includes(remotePort.name)) {
return false
return
Copy link
Contributor

Choose a reason for hiding this comment

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

This is potentially functionally different. Why is this the correct way to fix this lint error?

Copy link
Member

@Gudahtt Gudahtt Aug 12, 2020

Choose a reason for hiding this comment

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

I suspect it's because the return value is not used by any caller.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because this function is only used as a listener for extension.runtime.onConnect:

extension.runtime.onConnect.addListener(connectRemote)

And the return value from the event listener isn't conventionally important. It's also not documented as being used.[1]

@@ -256,7 +256,8 @@ export default class AccountTracker {
ethContract.balances(addresses, ethBalance, (error, result) => {
if (error) {
log.warn(`MetaMask - Account Tracker single call balance fetch failed`, error)
return Promise.all(addresses.map(this._updateAccount.bind(this)))
Promise.all(addresses.map(this._updateAccount.bind(this)))
Copy link
Contributor

Choose a reason for hiding this comment

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

should there be an await here? the place where this function is called awaits, but without return a promise, doesn't this function call become non-blocking?

or maybe I don't know something about async await...

Copy link
Contributor Author

@whymarrh whymarrh Aug 12, 2020

Choose a reason for hiding this comment

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

There should but that's a functional change for a different PR. This works no worse/better than before.

(Also this is a common problem in the codebase and we should audit all uses of promises and async/await systematically.)

Copy link
Contributor

@danjm danjm Aug 12, 2020

Choose a reason for hiding this comment

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

but I mean, isn't
return Promise.all(addresses.map(this._updateAccount.bind(this)))
functionally different from

Promise.all(addresses.map(this._updateAccount.bind(this)))
return

?

Copy link
Member

Choose a reason for hiding this comment

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

It's equivalent if the return value is unused. Since the function in question here is the callback being passed to ethContract.balances, the return value is not used. Nothing is await-ing this Promise.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If the return value were used, yes, but it is not.

Copy link
Contributor Author

@whymarrh whymarrh Aug 12, 2020

Choose a reason for hiding this comment

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

But this is an easier change than ensuring the function continues to work when the timing semantics have changed. If we wait for the updates to happen that would be more different.

Copy link
Contributor

Choose a reason for hiding this comment

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

" the function in question here is the callback being passed to"

doh, right, I should have realized that

Copy link
Contributor

@danjm danjm 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, Thanks for answering my questions.

Copy link
Member

@Gudahtt Gudahtt left a comment

Choose a reason for hiding this comment

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

LGTM!

@whymarrh whymarrh merged commit a8863a3 into MetaMask:develop Aug 12, 2020
@whymarrh whymarrh deleted the enable-consistent-return branch August 12, 2020 19:07
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