Skip to content

Commit

Permalink
Fix callback-return issues (#8996)
Browse files Browse the repository at this point in the history
See [`callback-return`](https://eslint.org/docs/rules/callback-return) for more information.

This change enables `callback-return` and fixes the resulting issues.
  • Loading branch information
whymarrh authored Jul 17, 2020
1 parent c0ff974 commit 68a64af
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 9 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ module.exports = {
rules: {
/* TODO: Remove these when upgrading to `@metamask/eslint-config@2` */
'array-callback-return': 'error',
'callback-return': 'error',
/* End v2 rules */
'arrow-parens': 'error',
'no-tabs': 'error',
Expand Down
1 change: 1 addition & 0 deletions app/scripts/controllers/permissions/methodMiddleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ export default function createMethodMiddleware ({
}

// when this promise resolves, the response is on its way back
// eslint-disable-next-line callback-return
await next()

if (responseHandler) {
Expand Down
8 changes: 5 additions & 3 deletions app/scripts/controllers/preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,13 +206,15 @@ export default class PreferencesController {
res.result = result
end()
}
break
return
default:
end(new Error(`Asset of type ${type} not supported`))
return
}
} else {
next()
}

next()
return
}

/**
Expand Down
23 changes: 23 additions & 0 deletions app/scripts/metamask-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -1119,6 +1119,7 @@ export default class MetamaskController extends EventEmitter {
messageManager.rejectMsg(msgId)
if (cb && typeof cb === 'function') {
cb(null, this.getState())
return
}
}

Expand Down Expand Up @@ -1177,6 +1178,7 @@ export default class MetamaskController extends EventEmitter {
messageManager.rejectMsg(msgId)
if (cb && typeof cb === 'function') {
cb(null, this.getState())
return
}
}

Expand Down Expand Up @@ -1261,6 +1263,7 @@ export default class MetamaskController extends EventEmitter {
messageManager.rejectMsg(msgId)
if (cb && typeof cb === 'function') {
cb(null, this.getState())
return
}
}

Expand Down Expand Up @@ -1318,6 +1321,7 @@ export default class MetamaskController extends EventEmitter {
messageManager.rejectMsg(msgId)
if (cb && typeof cb === 'function') {
cb(null, this.getState())
return
}
}

Expand Down Expand Up @@ -1377,6 +1381,7 @@ export default class MetamaskController extends EventEmitter {
messageManager.rejectMsg(msgId)
if (cb && typeof cb === 'function') {
cb(null, this.getState())
return
}
}

Expand Down Expand Up @@ -1843,8 +1848,10 @@ export default class MetamaskController extends EventEmitter {
this.currencyRateController.update(currencyState)
this.currencyRateController.configure(currencyState)
cb(null, this.currencyRateController.state)
return
} catch (err) {
cb(err)
return
}
}

Expand Down Expand Up @@ -1925,8 +1932,10 @@ export default class MetamaskController extends EventEmitter {
try {
this.preferencesController.setUseBlockie(val)
cb(null)
return
} catch (err) {
cb(err)
return
}
}

Expand All @@ -1939,8 +1948,10 @@ export default class MetamaskController extends EventEmitter {
try {
this.preferencesController.setUseNonceField(val)
cb(null)
return
} catch (err) {
cb(err)
return
}
}

Expand All @@ -1953,8 +1964,10 @@ export default class MetamaskController extends EventEmitter {
try {
this.preferencesController.setUsePhishDetect(val)
cb(null)
return
} catch (err) {
cb(err)
return
}
}

Expand All @@ -1967,8 +1980,10 @@ export default class MetamaskController extends EventEmitter {
try {
this.preferencesController.setIpfsGateway(val)
cb(null)
return
} catch (err) {
cb(err)
return
}
}

Expand All @@ -1981,17 +1996,21 @@ export default class MetamaskController extends EventEmitter {
try {
const metaMetricsId = this.preferencesController.setParticipateInMetaMetrics(bool)
cb(null, metaMetricsId)
return
} catch (err) {
cb(err)
return
}
}

setMetaMetricsSendCount (val, cb) {
try {
this.preferencesController.setMetaMetricsSendCount(val)
cb(null)
return
} catch (err) {
cb(err)
return
}
}

Expand All @@ -2004,8 +2023,10 @@ export default class MetamaskController extends EventEmitter {
try {
this.preferencesController.setFirstTimeFlowType(type)
cb(null)
return
} catch (err) {
cb(err)
return
}
}

Expand All @@ -2019,8 +2040,10 @@ export default class MetamaskController extends EventEmitter {
try {
const direction = this.preferencesController.setCurrentLocale(key)
cb(null, direction)
return
} catch (err) {
cb(err)
return
}
}

Expand Down
1 change: 1 addition & 0 deletions app/scripts/platforms/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ export default class ExtensionPlatform {
})
} catch (e) {
cb(e)
return
}
}

Expand Down
1 change: 1 addition & 0 deletions test/e2e/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ async function withFixtures (options, callback) {
const { driver } = await buildWebDriver(driverOptions)
webDriver = driver

// eslint-disable-next-line callback-return
await callback({
driver,
})
Expand Down
12 changes: 6 additions & 6 deletions test/unit/app/controllers/metamask-controller-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ const createLoggerMiddlewareMock = () => (req, res, next) => {
loggerMiddlewareMock.responses.push(res)
cb()
})
} else {
next()
return
}
next()
}

const MetaMaskController = proxyquire('../../../../app/scripts/metamask-controller', {
Expand Down Expand Up @@ -839,9 +839,9 @@ describe('MetaMaskController', function () {
const streamTest = createThoughStream((chunk, _, cb) => {
if (chunk.data && chunk.data.method) {
cb(null, chunk)
} else {
cb()
return
}
cb()
})

metamaskController.setupUntrustedCommunication(streamTest, messageSender)
Expand Down Expand Up @@ -877,9 +877,9 @@ describe('MetaMaskController', function () {
const streamTest = createThoughStream((chunk, _, cb) => {
if (chunk.data && chunk.data.method) {
cb(null, chunk)
} else {
cb()
return
}
cb()
})

metamaskController.setupUntrustedCommunication(streamTest, messageSender)
Expand Down

0 comments on commit 68a64af

Please sign in to comment.