From 885125ad0344202c28e7f602cde632d7e5d80162 Mon Sep 17 00:00:00 2001 From: Whymarrh Whitby Date: Wed, 12 Aug 2020 14:11:27 -0230 Subject: [PATCH] Fix no-case-declarations issues (#9191) See [`no-case-declarations`](https://eslint.org/docs/rules/no-case-declarations) for more information. This change enables `no-case-declarations` and fixes the issues raised by the rule. --- .eslintrc.js | 1 + .../permissions/permissionsMethodMiddleware.js | 12 ++++++++---- app/scripts/controllers/preferences.js | 3 ++- app/scripts/lib/createMethodMiddleware.js | 3 ++- app/scripts/lib/typed-message-manager.js | 3 ++- ui/app/ducks/app/app.js | 6 ++++-- .../confirm-transaction/confirm-transaction.duck.js | 12 ++++++++---- ui/app/ducks/metamask/metamask.js | 9 ++++++--- 8 files changed, 33 insertions(+), 16 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 8ea5865e8..c5dabe2e2 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -46,6 +46,7 @@ module.exports = { 'callback-return': 'error', 'global-require': 'error', 'guard-for-in': 'error', + 'no-case-declarations': 'error', /* End v2 rules */ 'arrow-parens': 'error', 'no-tabs': 'error', diff --git a/app/scripts/controllers/permissions/permissionsMethodMiddleware.js b/app/scripts/controllers/permissions/permissionsMethodMiddleware.js index 075f67cf8..ec5066b9c 100644 --- a/app/scripts/controllers/permissions/permissionsMethodMiddleware.js +++ b/app/scripts/controllers/permissions/permissionsMethodMiddleware.js @@ -24,12 +24,13 @@ export default function createPermissionsMethodMiddleware ({ // Intercepting eth_accounts requests for backwards compatibility: // The getAccounts call below wraps the rpc-cap middleware, and returns // an empty array in case of errors (such as 4100:unauthorized) - case 'eth_accounts': + case 'eth_accounts': { res.result = await getAccounts() return + } - case 'eth_requestAccounts': + case 'eth_requestAccounts': { if (isProcessingRequestAccounts) { res.error = ethErrors.rpc.resourceUnavailable( @@ -73,19 +74,21 @@ export default function createPermissionsMethodMiddleware ({ } return + } // custom method for getting metadata from the requesting domain, // sent automatically by the inpage provider when it's initialized - case 'wallet_sendDomainMetadata': + case 'wallet_sendDomainMetadata': { if (typeof req.domainMetadata?.name === 'string') { addDomainMetadata(req.origin, req.domainMetadata) } res.result = true return + } // register return handler to send accountsChanged notification - case 'wallet_requestPermissions': + case 'wallet_requestPermissions': { if ('eth_accounts' in req.params?.[0]) { @@ -101,6 +104,7 @@ export default function createPermissionsMethodMiddleware ({ } } break + } default: break diff --git a/app/scripts/controllers/preferences.js b/app/scripts/controllers/preferences.js index 47fa73746..4c0e97ceb 100644 --- a/app/scripts/controllers/preferences.js +++ b/app/scripts/controllers/preferences.js @@ -198,7 +198,7 @@ export default class PreferencesController { ) { const { type, options } = req.params switch (type) { - case 'ERC20': + case 'ERC20': { const result = await this._handleWatchAssetERC20(options) if (result instanceof Error) { end(result) @@ -207,6 +207,7 @@ export default class PreferencesController { end() } return + } default: end(new Error(`Asset of type ${type} not supported`)) return diff --git a/app/scripts/lib/createMethodMiddleware.js b/app/scripts/lib/createMethodMiddleware.js index 308cf0a99..8224dbf33 100644 --- a/app/scripts/lib/createMethodMiddleware.js +++ b/app/scripts/lib/createMethodMiddleware.js @@ -11,7 +11,7 @@ export default function createMethodMiddleware ({ origin, sendMetrics }) { return function methodMiddleware (req, res, next, end) { switch (req.method) { - case 'metamask_logInjectedWeb3Usage': + case 'metamask_logInjectedWeb3Usage': { const { action, name } = req.params[0] @@ -23,6 +23,7 @@ export default function createMethodMiddleware ({ origin, sendMetrics }) { res.result = true break + } default: return next() diff --git a/app/scripts/lib/typed-message-manager.js b/app/scripts/lib/typed-message-manager.js index 3f5da3db1..8d7bc6ad5 100644 --- a/app/scripts/lib/typed-message-manager.js +++ b/app/scripts/lib/typed-message-manager.js @@ -154,7 +154,7 @@ export default class TypedMessageManager extends EventEmitter { }, 'Signing data must be valid EIP-712 typed data.') break case 'V3': - case 'V4': + case 'V4': { assert.equal(typeof params.data, 'string', '"params.data" must be a string.') let data assert.doesNotThrow(() => { @@ -167,6 +167,7 @@ export default class TypedMessageManager extends EventEmitter { const activeChainId = parseInt(this.networkController.getNetworkState()) chainId && assert.equal(chainId, activeChainId, `Provided chainId "${chainId}" must match the active chainId "${activeChainId}"`) break + } default: assert.fail(`Unknown typed data version "${params.version}"`) } diff --git a/ui/app/ducks/app/app.js b/ui/app/ducks/app/app.js index 177ed812c..f45a4b294 100644 --- a/ui/app/ducks/app/app.js +++ b/ui/app/ducks/app/app.js @@ -110,7 +110,7 @@ export default function reduceApp (state = {}, action) { // modal methods: - case actionConstants.MODAL_OPEN: + case actionConstants.MODAL_OPEN: { const { name, ...modalProps } = action.payload return { @@ -124,6 +124,7 @@ export default function reduceApp (state = {}, action) { previousModalState: { ...appState.modal.modalState }, }, } + } case actionConstants.MODAL_CLOSE: return { @@ -232,7 +233,7 @@ export default function reduceApp (state = {}, action) { warning: '', } - case actionConstants.SET_HARDWARE_WALLET_DEFAULT_HD_PATH: + case actionConstants.SET_HARDWARE_WALLET_DEFAULT_HD_PATH: { const { device, path } = action.value const newDefaults = { ...appState.defaultHdPaths } newDefaults[device] = path @@ -241,6 +242,7 @@ export default function reduceApp (state = {}, action) { ...appState, defaultHdPaths: newDefaults, } + } case actionConstants.SHOW_LOADING: return { diff --git a/ui/app/ducks/confirm-transaction/confirm-transaction.duck.js b/ui/app/ducks/confirm-transaction/confirm-transaction.duck.js index 416407d5d..536307ac7 100644 --- a/ui/app/ducks/confirm-transaction/confirm-transaction.duck.js +++ b/ui/app/ducks/confirm-transaction/confirm-transaction.duck.js @@ -104,7 +104,7 @@ export default function reducer (state = initState, action = {}) { ...state, methodData: {}, } - case UPDATE_TRANSACTION_AMOUNTS: + case UPDATE_TRANSACTION_AMOUNTS: { const { fiatTransactionAmount, ethTransactionAmount, hexTransactionAmount } = action.payload return { ...state, @@ -112,7 +112,8 @@ export default function reducer (state = initState, action = {}) { ethTransactionAmount: ethTransactionAmount || state.ethTransactionAmount, hexTransactionAmount: hexTransactionAmount || state.hexTransactionAmount, } - case UPDATE_TRANSACTION_FEES: + } + case UPDATE_TRANSACTION_FEES: { const { fiatTransactionFee, ethTransactionFee, hexTransactionFee } = action.payload return { ...state, @@ -120,7 +121,8 @@ export default function reducer (state = initState, action = {}) { ethTransactionFee: ethTransactionFee || state.ethTransactionFee, hexTransactionFee: hexTransactionFee || state.hexTransactionFee, } - case UPDATE_TRANSACTION_TOTALS: + } + case UPDATE_TRANSACTION_TOTALS: { const { fiatTransactionTotal, ethTransactionTotal, hexTransactionTotal } = action.payload return { ...state, @@ -128,7 +130,8 @@ export default function reducer (state = initState, action = {}) { ethTransactionTotal: ethTransactionTotal || state.ethTransactionTotal, hexTransactionTotal: hexTransactionTotal || state.hexTransactionTotal, } - case UPDATE_TOKEN_PROPS: + } + case UPDATE_TOKEN_PROPS: { const { tokenSymbol = '', tokenDecimals = '' } = action.payload return { ...state, @@ -138,6 +141,7 @@ export default function reducer (state = initState, action = {}) { tokenDecimals, }, } + } case UPDATE_NONCE: return { ...state, diff --git a/ui/app/ducks/metamask/metamask.js b/ui/app/ducks/metamask/metamask.js index e3f35bf38..e6449a622 100644 --- a/ui/app/ducks/metamask/metamask.js +++ b/ui/app/ducks/metamask/metamask.js @@ -84,13 +84,14 @@ export default function reduceMetamask (state = {}, action) { selectedAddress: action.value, } - case actionConstants.SET_ACCOUNT_LABEL: + case actionConstants.SET_ACCOUNT_LABEL: { const account = action.value.account const name = action.value.label const id = {} id[account] = Object.assign({}, metamaskState.identities[account], { name }) const identities = Object.assign({}, metamaskState.identities, id) return Object.assign(metamaskState, { identities }) + } case actionConstants.SET_CURRENT_FIAT: return Object.assign(metamaskState, { @@ -197,7 +198,7 @@ export default function reduceMetamask (state = {}, action) { }, }) - case actionConstants.UPDATE_SEND_TOKEN: + case actionConstants.UPDATE_SEND_TOKEN: { const newSend = { ...metamaskState.send, token: action.value, @@ -225,6 +226,7 @@ export default function reduceMetamask (state = {}, action) { return Object.assign(metamaskState, { send: newSend, }) + } case actionConstants.UPDATE_SEND_ENS_RESOLUTION: return { @@ -265,7 +267,7 @@ export default function reduceMetamask (state = {}, action) { }, } - case actionConstants.UPDATE_TRANSACTION_PARAMS: + case actionConstants.UPDATE_TRANSACTION_PARAMS: { const { id: txId, value } = action let { currentNetworkTxList } = metamaskState currentNetworkTxList = currentNetworkTxList.map((tx) => { @@ -281,6 +283,7 @@ export default function reduceMetamask (state = {}, action) { ...metamaskState, currentNetworkTxList, } + } case actionConstants.SET_PARTICIPATE_IN_METAMETRICS: return {