-
Notifications
You must be signed in to change notification settings - Fork 5k
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
Conversation
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.
7087edd
to
912ef2a
Compare
@@ -327,7 +327,7 @@ function setupController (initState, initLangCode) { | |||
const isMetaMaskInternalProcess = metamaskInternalProcessHash[processName] | |||
|
|||
if (metamaskBlockedPorts.includes(remotePort.name)) { | |||
return false | |||
return |
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.
This is potentially functionally different. Why is this the correct way to fix this lint error?
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.
I suspect it's because the return value is not used by any caller.
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.
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))) |
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.
should there be an await
here? the place where this function is called await
s, but without return a promise, doesn't this function call become non-blocking?
or maybe I don't know something about async await...
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.
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.)
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.
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
?
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.
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
.
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 the return value were used, yes, but it is not.
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.
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.
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.
" the function in question here is the callback being passed to"
doh, right, I should have realized that
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.
Looks good, Thanks for answering my questions.
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.
LGTM!
Refs #8982
See
consistent-return
for more information.This change enables
consistent-return
and fixes the issues raised by the rule.