1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 01:39:44 +01:00

Enable default-case rule for ESLint (#7572)

* eslint: Enable default-case rule

* Fix missing default cases

* Fix tests failing due to incorrect assumptions
This commit is contained in:
Whymarrh Whitby 2019-11-27 12:38:35 -03:30 committed by GitHub
parent 629e5501a1
commit 926c8848f1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 25 additions and 14 deletions

View File

@ -44,6 +44,7 @@
},
"rules": {
"default-case": 2,
"import/no-unresolved": ["error", { "commonjs": true }],
"no-restricted-globals": ["error", "event"],
"accessor-pairs": 2,

View File

@ -32,8 +32,9 @@ function getBuyEthUrl ({ network, amount, address, service }) {
return 'https://github.com/kovan-testnet/faucet'
case 'goerli-faucet':
return 'https://goerli-faucet.slock.it/'
default:
throw new Error(`Unknown cryptocurrency exchange or faucet: "${service}"`)
}
throw new Error(`Unknown cryptocurrency exchange or faucet: "${service}"`)
}
function getDefaultServiceForNetwork (network) {
@ -48,6 +49,7 @@ function getDefaultServiceForNetwork (network) {
return 'kovan-faucet'
case '5':
return 'goerli-faucet'
default:
throw new Error(`No default cryptocurrency exchange or faucet for networkId: "${network}"`)
}
throw new Error(`No default cryptocurrency exchange or faucet for networkId: "${network}"`)
}

View File

@ -66,5 +66,7 @@ function getRegistryForChainId (chainId) {
// goerli
case 5:
return '0x112234455c3a32fd11230c42e7bccd4a84e02010'
default:
return null
}
}

View File

@ -163,6 +163,8 @@ module.exports = 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 params.version ${params.version}`)
}
}

View File

@ -23,6 +23,7 @@ module.exports = {
type: 'mainnet',
}
break
// No default
}
} catch (_) {}
return Promise.resolve(safeVersionedData)

View File

@ -40,6 +40,8 @@ function newVersionFrom (manifest, bumpType) {
case 'patch':
segments[2] += 1
break
default:
throw new Error(`invalid bumpType ${bumpType}`)
}
return segments.map(String).join('.')

View File

@ -123,6 +123,8 @@ async function loadExtension (driver, extensionId) {
await driver.get(`moz-extension://${extensionId}/home.html`)
break
}
default:
throw new Error('Unrecognized SELENIUM_BROWSER value')
}
}

View File

@ -30,12 +30,12 @@ describe('Typed Message Manager', () => {
'EIP712Domain': [
{'name': 'name', 'type': 'string' },
{'name': 'version', 'type': 'string' },
{'name': 'chainId', ' type': 'uint256' },
{'name': 'verifyingContract', ' type': 'address' },
{'name': 'chainId', 'type': 'uint256' },
{'name': 'verifyingContract', 'type': 'address' },
],
'Person': [
{'name': 'name', 'type': 'string' },
{'name': 'wallet', ' type': 'address' },
{'name': 'wallet', 'type': 'address' },
],
'Mail': [
{'name': 'from', 'type': 'Person' },
@ -64,7 +64,7 @@ describe('Typed Message Manager', () => {
}),
}
typedMessageManager.addUnapprovedMessage(msgParamsV3, 'V3')
typedMessageManager.addUnapprovedMessage(msgParamsV3, null, 'V3')
typedMsgs = typedMessageManager.getUnapprovedMsgs()
messages = typedMessageManager.messages
msgId = Object.keys(typedMsgs)[0]
@ -73,7 +73,7 @@ describe('Typed Message Manager', () => {
})
it('supports version 1 of signedTypedData', () => {
typedMessageManager.addUnapprovedMessage(msgParamsV1, 'V1')
typedMessageManager.addUnapprovedMessage(msgParamsV1, null, 'V1')
assert.equal(messages[messages.length - 1].msgParams.data, msgParamsV1.data)
})
@ -87,7 +87,7 @@ describe('Typed Message Manager', () => {
it('validates params', function () {
assert.doesNotThrow(() => {
typedMessageManager.validateParams(messages[0])
typedMessageManager.validateParams(messages[0].msgParams)
}, 'Does not throw with valid parameters')
})

View File

@ -755,7 +755,6 @@ describe('Actions', () => {
'domain': {
'name': 'Ether Mainl',
'version': '1',
'chainId': 1,
'verifyingContract': '0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC',
},
'message': {
@ -773,11 +772,12 @@ describe('Actions', () => {
}
beforeEach(() => {
metamaskController.newUnsignedTypedMessage(msgParamsV3, 'V3')
metamaskController.newUnsignedTypedMessage(msgParamsV3, null, 'V3')
messages = metamaskController.typedMessageManager.getUnapprovedMsgs()
typedMessages = metamaskController.typedMessageManager.messages
msgId = Object.keys(messages)[0]
typedMessages[0].msgParams.metamaskId = parseInt(msgId)
signTypedMsgSpy = sinon.stub(background, 'signTypedMessage')
})
afterEach(() => {
@ -786,7 +786,6 @@ describe('Actions', () => {
it('calls signTypedMsg in background with no error', () => {
const store = mockStore()
signTypedMsgSpy = sinon.stub(background, 'signTypedMessage')
store.dispatch(actions.signTypedMsg(msgParamsV3))
assert(signTypedMsgSpy.calledOnce)
@ -801,8 +800,6 @@ describe('Actions', () => {
{ type: 'DISPLAY_WARNING', value: 'error' },
]
signTypedMsgSpy = sinon.stub(background, 'signTypedMessage')
signTypedMsgSpy.callsFake((_, callback) => {
callback(new Error('error'))
})

View File

@ -156,9 +156,11 @@ export default class AccountMenu extends PureComponent {
case 'Simple Key Pair':
label = t('imported')
break
default:
return null
}
return label && (
return (
<div className="keyring-label allcaps">
{ label }
</div>