Enable default-case rule for ESLint (#7572)

* eslint: Enable default-case rule

* Fix missing default cases

* Fix tests failing due to incorrect assumptions
feature/default_network_editable
Whymarrh Whitby 5 years ago committed by GitHub
parent 629e5501a1
commit 926c8848f1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      .eslintrc
  2. 6
      app/scripts/lib/buy-eth-url.js
  3. 2
      app/scripts/lib/ens-ipfs/resolver.js
  4. 2
      app/scripts/lib/typed-message-manager.js
  5. 1
      app/scripts/migrations/004.js
  6. 2
      development/version-bump.js
  7. 2
      test/e2e/helpers.js
  8. 12
      test/unit/app/typed-message-manager.spec.js
  9. 7
      test/unit/ui/app/actions.spec.js
  10. 4
      ui/app/components/app/account-menu/account-menu.component.js

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

@ -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}"`)
}

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

@ -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}`)
}
}

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

@ -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('.')

@ -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')
}
}

@ -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')
})

@ -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'))
})

@ -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>

Loading…
Cancel
Save