1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-22 01:47:00 +01:00

Fix no-empty-function issues (#9216)

See [`no-empty-function`](https://eslint.org/docs/rules/no-empty-function) for more information.

This change enables `no-empty-function` and fixes the issues raised by the rule.
This commit is contained in:
Whymarrh Whitby 2020-08-14 09:17:02 -02:30 committed by GitHub
parent 9b78d3ab07
commit c11888f287
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
40 changed files with 79 additions and 84 deletions

View File

@ -53,6 +53,7 @@ module.exports = {
'no-constant-condition': 'error',
'no-dupe-else-if': 'error',
'no-empty': 'error',
'no-empty-function': 'error',
'no-eq-null': 'error',
'no-global-assign': 'error',
'no-loop-func': 'error',

View File

@ -19,7 +19,7 @@ export default class AppStateController extends EventEmitter {
super()
this.onInactiveTimeout = onInactiveTimeout || (() => {})
this.onInactiveTimeout = onInactiveTimeout || (() => undefined)
this.store = new ObservableStore(Object.assign({
timeoutMinutes: 0,
connectedStatusPopoverHasBeenShown: true,

View File

@ -132,7 +132,7 @@ export class PermissionsController {
const req = { method: 'eth_accounts' }
const res = {}
this.permissions.providerMiddlewareFunction(
{ origin }, req, res, () => {}, _end,
{ origin }, req, res, () => undefined, _end,
)
function _end () {
@ -187,7 +187,7 @@ export class PermissionsController {
const res = {}
this.permissions.providerMiddlewareFunction(
domain, req, res, () => {}, _end,
domain, req, res, () => undefined, _end,
)
function _end (_err) {

View File

@ -50,7 +50,7 @@ class Mock3Box {
},
}
},
logout: () => {},
logout: () => undefined,
})
}

View File

@ -80,7 +80,7 @@ require('abortcontroller-polyfill/dist/polyfill-patch-fetch')
window.localStorage = {}
// override metamask-logo
window.requestAnimationFrame = () => {}
window.requestAnimationFrame = () => undefined
// crypto.getRandomValues
if (!window.crypto) {

View File

@ -27,7 +27,7 @@ export function mountWithRouter (component, store = {}, pathname = '/') {
context: {
router,
t: (str) => str,
metricsEvent: () => {},
metricsEvent: () => undefined,
store,
},
childContextTypes: {

View File

@ -25,7 +25,7 @@ describe('Promise global is immutable', function () {
it('throws when mutating existing Promise property', function () {
try {
Promise.all = () => {}
Promise.all = () => undefined
assert.fail('did not throw error')
} catch (err) {
assert.ok(err, 'did throw error')

View File

@ -9,7 +9,7 @@ describe('CachedBalancesController', function () {
getNetwork: () => Promise.resolve(17),
accountTracker: {
store: {
subscribe: () => {},
subscribe: () => undefined,
},
},
initState: {
@ -32,7 +32,7 @@ describe('CachedBalancesController', function () {
const controller = new CachedBalancesController({
accountTracker: {
store: {
subscribe: () => {},
subscribe: () => undefined,
},
},
initState: {
@ -75,7 +75,7 @@ describe('CachedBalancesController', function () {
const controller = new CachedBalancesController({
accountTracker: {
store: {
subscribe: () => {},
subscribe: () => undefined,
},
},
initState: {

View File

@ -14,7 +14,7 @@ describe('DetectTokensController', function () {
const sandbox = sinon.createSandbox()
let keyringMemStore, network, preferences
const noop = () => {}
const noop = () => undefined
const networkControllerProviderConfig = {
getAccounts: noop,

View File

@ -19,7 +19,7 @@ import proxyquire from 'proxyquire'
class ThreeBoxControllerMock {
constructor () {
this.store = {
subscribe: () => {},
subscribe: () => undefined,
getState: () => ({}),
}
this.init = threeBoxSpies.init
@ -78,7 +78,7 @@ const CUSTOM_RPC_URL = 'http://localhost:8545'
describe('MetaMaskController', function () {
let metamaskController
const sandbox = sinon.createSandbox()
const noop = () => {}
const noop = () => undefined
beforeEach(function () {
@ -113,7 +113,7 @@ describe('MetaMaskController', function () {
},
},
initState: cloneDeep(firstTimeState),
platform: { showTransactionNotification: () => {} },
platform: { showTransactionNotification: () => undefined },
})
// disable diagnostics
metamaskController.diagnostics = null

View File

@ -6,7 +6,7 @@ import { getNetworkDisplayName } from '../../../../../app/scripts/controllers/ne
describe('NetworkController', function () {
describe('controller', function () {
let networkController
const noop = () => {}
const noop = () => undefined
const networkControllerProviderConfig = {
getAccounts: noop,
}

View File

@ -20,7 +20,7 @@ import {
* - Immutable mock values like Ethereum accounts and expected states
*/
export const noop = () => {}
export const noop = () => undefined
/**
* Mock Permissions Controller and Middleware

View File

@ -372,7 +372,7 @@ describe('preferences controller', function () {
beforeEach(function () {
req = { params: {} }
res = {}
asy = { next: () => {}, end: () => {} }
asy = { next: () => undefined, end: () => undefined }
stubNext = sandbox.stub(asy, 'next')
stubEnd = sandbox.stub(asy, 'end').returns(0)
stubHandleWatchAssetERC20 = sandbox.stub(preferencesController, '_handleWatchAssetERC20')
@ -382,7 +382,7 @@ describe('preferences controller', function () {
})
it('shouldn not do anything if method not corresponds', async function () {
const asy = { next: () => {}, end: () => {} }
const asy = { next: () => undefined, end: () => undefined }
const stubNext = sandbox.stub(asy, 'next')
const stubEnd = sandbox.stub(asy, 'end').returns(0)
req.method = 'metamask'
@ -391,7 +391,7 @@ describe('preferences controller', function () {
sandbox.assert.called(stubNext)
})
it('should do something if method is supported', async function () {
const asy = { next: () => {}, end: () => {} }
const asy = { next: () => undefined, end: () => undefined }
const stubNext = sandbox.stub(asy, 'next')
const stubEnd = sandbox.stub(asy, 'end').returns(0)
req.method = 'metamask_watchAsset'
@ -415,7 +415,7 @@ describe('preferences controller', function () {
assert.deepEqual(res, {})
})
it('should trigger handle add asset if type supported', async function () {
const asy = { next: () => {}, end: () => {} }
const asy = { next: () => undefined, end: () => undefined }
req.method = 'metamask_watchAsset'
req.params.type = 'ERC20'
await preferencesController.requestWatchAsset(req, res, asy.next, asy.end)
@ -442,7 +442,7 @@ describe('preferences controller', function () {
req.params.options = { address, symbol, decimals, image }
sandbox.stub(preferencesController, '_validateERC20AssetParams').returns(true)
preferencesController.openPopup = async () => {}
preferencesController.openPopup = async () => undefined
await preferencesController._handleWatchAssetERC20(req.params.options)
const suggested = preferencesController.getSuggestedTokens()

View File

@ -147,15 +147,15 @@ describe('PendingTransactionTracker', function () {
},
nonceTracker: {
getGlobalLock: async () => {
return { releaseLock: () => {} }
return { releaseLock: () => undefined }
},
},
getPendingTransactions: () => txList,
getCompletedTransactions: () => {
return []
},
publishTransaction: () => {},
confirmTransaction: () => {},
publishTransaction: () => undefined,
confirmTransaction: () => undefined,
})
const checkPendingTxStub = sinon.stub(pendingTxTracker, '_checkPendingTx').resolves()

View File

@ -47,7 +47,7 @@ describe('Transaction Controller', function () {
ethTx.sign(fromAccount.key)
resolve()
}),
getPermittedAccounts: () => {},
getPermittedAccounts: () => undefined,
})
txController.nonceTracker.getNonceLock = () => Promise.resolve({ nextNonce: 0, releaseLock: noop })
})

View File

@ -9,7 +9,7 @@ describe('txUtils', function () {
before(function () {
txUtils = new TxUtils(new Proxy({}, {
get: () => {
return () => {}
return () => undefined
},
}))
})

View File

@ -14,9 +14,6 @@ describe('Message Manager', function () {
assert.ok(Array.isArray(result))
assert.equal(result.length, 0)
})
it('should also return transactions from local storage if any', function () {
})
})
describe('#addMsg', function () {

View File

@ -14,9 +14,6 @@ describe('Personal Message Manager', function () {
assert.ok(Array.isArray(result))
assert.equal(result.length, 0)
})
it('should also return transactions from local storage if any', function () {
})
})
describe('#addMsg', function () {

View File

@ -19,7 +19,7 @@ const mockStore = (state = defaultState) => configureStore(middleware)(state)
describe('Actions', function () {
const noop = () => {}
const noop = () => undefined
const currentNetworkId = '42'

View File

@ -30,7 +30,7 @@ describe('App Header', function () {
<AppHeader.WrappedComponent {...props} />, {
context: {
t: (str) => str,
metricsEvent: () => {},
metricsEvent: () => undefined,
},
},
)
@ -54,8 +54,8 @@ describe('App Header', function () {
const network = wrapper.find({ network: 'test' })
network.simulate('click', {
preventDefault: () => {},
stopPropagation: () => {},
preventDefault: () => undefined,
stopPropagation: () => undefined,
})
assert(props.showNetworkDropdown.calledOnce)
@ -66,8 +66,8 @@ describe('App Header', function () {
const network = wrapper.find({ network: 'test' })
network.simulate('click', {
preventDefault: () => {},
stopPropagation: () => {},
preventDefault: () => undefined,
stopPropagation: () => undefined,
})
assert(props.hideNetworkDropdown.calledOnce)

View File

@ -48,10 +48,10 @@ describe('Modal Component', function () {
it('should render a modal with different button types', function () {
const wrapper = shallow(
<Modal
onCancel={() => {}}
onCancel={() => undefined}
cancelText="Cancel"
cancelType="secondary"
onSubmit={() => {}}
onSubmit={() => undefined}
submitText="Submit"
submitType="confirm"
/>,
@ -66,9 +66,9 @@ describe('Modal Component', function () {
it('should render a modal with children', function () {
const wrapper = shallow(
<Modal
onCancel={() => {}}
onCancel={() => undefined}
cancelText="Cancel"
onSubmit={() => {}}
onSubmit={() => undefined}
submitText="Submit"
>
<div className="test-child" />

View File

@ -34,7 +34,7 @@ describe('CancelTransaction Component', function () {
defaultNewGasPrice="0x3b9aca00"
createCancelTransaction={createCancelTransactionSpy}
hideModal={hideModalSpy}
showTransactionConfirmedModal={() => {}}
showTransactionConfirmedModal={() => undefined}
/>,
{ context: { t } },
)

View File

@ -134,8 +134,8 @@ class FadeModal extends Component {
}
static defaultProps = {
onShow: function () {},
onHide: function () {},
onShow: () => undefined,
onHide: () => undefined,
keyboard: true,
backdrop: true,
closeOnClick: true,

View File

@ -17,7 +17,7 @@ describe('MetaMetrics Opt In', function () {
wrapper = mount(
<MetaMetricsOptIn.WrappedComponent {...props} />, {
context: {
metricsEvent: () => {},
metricsEvent: () => undefined,
},
},
)

View File

@ -9,7 +9,7 @@ describe('SelectedAccount Component', function () {
<SelectedAccount
selectedIdentity={{ name: 'testName', address: '0x1b82543566f41a7db9a9a75fc933c340ffb55c9d' }}
/>
), { context: { t: () => {} } })
), { context: { t: () => undefined } })
// Checksummed version of address is displayed
assert.equal(wrapper.find('.selected-account__address').text(), '0x1B82...5C9D')
assert.equal(wrapper.find('.selected-account__name').text(), 'testName')

View File

@ -10,9 +10,9 @@ describe('Signature Request Component', function () {
it('should render a div with one child', function () {
const wrapper = shallow((
<SignatureRequest
clearConfirmTransaction={() => {}}
cancel={() => {}}
sign={() => {}}
clearConfirmTransaction={() => undefined}
cancel={() => undefined}
sign={() => undefined}
txData={{
msgParams: {
data: '{"message": {"from": {"name": "hello"}}}',

View File

@ -40,8 +40,8 @@ describe('TransactionActivityLog Component', function () {
inlineRetryIndex={-1}
inlineCancelIndex={-1}
nativeCurrency="ETH"
onCancel={() => {}}
onRetry={() => {}}
onCancel={() => undefined}
onRetry={() => undefined}
primaryTransactionStatus="confirmed"
/>,
{ context: { t: (str1, str2) => (str2 ? str1 + str2 : str1) } },
@ -87,8 +87,8 @@ describe('TransactionActivityLog Component', function () {
inlineRetryIndex={2}
inlineCancelIndex={3}
nativeCurrency="ETH"
onCancel={() => {}}
onRetry={() => {}}
onCancel={() => undefined}
onRetry={() => undefined}
primaryTransactionStatus="pending"
isEarliestNonce
/>,
@ -136,8 +136,8 @@ describe('TransactionActivityLog Component', function () {
inlineRetryIndex={2}
inlineCancelIndex={3}
nativeCurrency="ETH"
onCancel={() => {}}
onRetry={() => {}}
onCancel={() => undefined}
onRetry={() => undefined}
primaryTransactionStatus="pending"
isEarliestNonce={false}
/>,

View File

@ -27,7 +27,7 @@ describe('TransactionBreakdownRow Component', function () {
title="test"
className="test-class"
>
<Button onClick={() => {}} >Button</Button>
<Button onClick={() => undefined} >Button</Button>
</TransactionBreakdownRow>,
{ context: { t: (str1, str2) => (str2 ? str1 + str2 : str1) } },
)

View File

@ -34,7 +34,7 @@ describe('TransactionListItemDetails Component', function () {
title="Test Transaction Details"
recipientAddress="0x1"
senderAddress="0x2"
tryReverseResolveAddress={() => {}}
tryReverseResolveAddress={() => undefined}
transactionGroup={transactionGroup}
senderNickname="sender-nickname"
recipientNickname="recipient-nickname"
@ -77,7 +77,7 @@ describe('TransactionListItemDetails Component', function () {
<TransactionListItemDetails
recipientAddress="0x1"
senderAddress="0x2"
tryReverseResolveAddress={() => {}}
tryReverseResolveAddress={() => undefined}
transactionGroup={transactionGroup}
showSpeedUp
senderNickname="sender-nickname"
@ -117,7 +117,7 @@ describe('TransactionListItemDetails Component', function () {
<TransactionListItemDetails
recipientAddress="0x1"
senderAddress="0x2"
tryReverseResolveAddress={() => {}}
tryReverseResolveAddress={() => undefined}
transactionGroup={transactionGroup}
senderNickname="sender-nickname"
recipientNickname="recipient-nickname"
@ -159,7 +159,7 @@ describe('TransactionListItemDetails Component', function () {
<TransactionListItemDetails
recipientAddress="0x1"
senderAddress="0x2"
tryReverseResolveAddress={() => {}}
tryReverseResolveAddress={() => undefined}
transactionGroup={transactionGroup}
senderNickname="sender-nickname"
recipientNickname="recipient-nickname"

View File

@ -46,7 +46,7 @@ describe('useCancelTransaction', function () {
it(`should return a function that kicks off cancellation for id ${transactionId}`, function () {
const { result } = renderHook(() => useCancelTransaction(transactionGroup))
assert.equal(typeof result.current[1], 'function')
result.current[1]({ preventDefault: () => {}, stopPropagation: () => {} })
result.current[1]({ preventDefault: () => undefined, stopPropagation: () => undefined })
assert.equal(
dispatch.calledWith(
showModal({
@ -90,7 +90,7 @@ describe('useCancelTransaction', function () {
it(`should return a function that kicks off cancellation for id ${transactionId}`, function () {
const { result } = renderHook(() => useCancelTransaction(transactionGroup))
assert.equal(typeof result.current[1], 'function')
result.current[1]({ preventDefault: () => {}, stopPropagation: () => {} })
result.current[1]({ preventDefault: () => undefined, stopPropagation: () => undefined })
assert.equal(
dispatch.calledWith(
showModal({

View File

@ -12,7 +12,7 @@ describe('useRetryTransaction', function () {
describe('when transaction meets retry enabled criteria', function () {
const dispatch = sinon.spy(() => Promise.resolve({ blockTime: 0 }))
const trackEvent = sinon.spy()
const event = { preventDefault: () => {}, stopPropagation: () => {} }
const event = { preventDefault: () => undefined, stopPropagation: () => undefined }
before(function () {
sinon.stub(reactRedux, 'useDispatch').returns(dispatch)

View File

@ -19,7 +19,7 @@ describe('Add Token', function () {
const props = {
history: {
push: sinon.stub().callsFake(() => {}),
push: sinon.stub().callsFake(() => undefined),
},
setPendingTokens: sinon.spy(),
clearPendingTokens: sinon.spy(),

View File

@ -23,7 +23,7 @@ describe('Reveal Seed Phrase', function () {
<RevealSeedPhrase.WrappedComponent {...props} />, {
context: {
t: (str) => str,
metricsEvent: () => {},
metricsEvent: () => undefined,
},
},
)

View File

@ -13,7 +13,7 @@ describe('AmountMaxButton Component', function () {
setMaxModeTo: sinon.spy(),
}
const MOCK_EVENT = { preventDefault: () => {} }
const MOCK_EVENT = { preventDefault: () => undefined }
before(function () {
sinon.spy(AmountMaxButton.prototype, 'setMaxAmount')
@ -33,7 +33,7 @@ describe('AmountMaxButton Component', function () {
), {
context: {
t: (str) => str + '_t',
metricsEvent: () => {},
metricsEvent: () => undefined,
},
})
instance = wrapper.instance()

View File

@ -158,7 +158,7 @@ function shallowRenderSendAmountRow () {
updateGasFeeError={updateGasFeeError}
updateSendAmount={updateSendAmount}
updateSendAmountError={updateSendAmountError}
updateGas={() => {}}
updateGas={() => undefined}
/>
), { context: { t: (str) => str + '_t' } })
const instance = wrapper.instance()

View File

@ -18,7 +18,7 @@ describe('SendFooter Component', function () {
const historySpies = {
push: sinon.spy(),
}
const MOCK_EVENT = { preventDefault: () => {} }
const MOCK_EVENT = { preventDefault: () => undefined }
before(function () {
sinon.spy(SendFooter.prototype, 'onCancel')

View File

@ -63,12 +63,12 @@ describe('Send Component', function () {
tokenBalance="mockTokenBalance"
tokenContract={{ method: 'mockTokenMethod' }}
updateAndSetGasLimit={propsMethodSpies.updateAndSetGasLimit}
qrCodeDetected={() => {}}
scanQrCode={() => {}}
updateSendEnsResolution={() => {}}
updateSendEnsResolutionError={() => {}}
qrCodeDetected={() => undefined}
scanQrCode={() => undefined}
updateSendEnsResolution={() => undefined}
updateSendEnsResolutionError={() => undefined}
updateSendErrors={propsMethodSpies.updateSendErrors}
updateSendTo={() => {}}
updateSendTo={() => undefined}
updateSendTokenBalance={propsMethodSpies.updateSendTokenBalance}
resetSendState={propsMethodSpies.resetSendState}
updateToNicknameIfNecessary={propsMethodSpies.updateToNicknameIfNecessary}

View File

@ -21,7 +21,7 @@ proxyquire('../send.container.js', {
return () => ({})
},
},
'react-router-dom': { withRouter: () => {} },
'react-router-dom': { withRouter: () => undefined },
'redux': { compose: (_, arg2) => () => arg2() },
'../../store/actions': actionSpies,
'../../ducks/send/send.duck': duckActionSpies,

View File

@ -10,10 +10,10 @@ describe('AdvancedTab Component', function () {
const root = shallow(
<AdvancedTab
ipfsGateway=""
setAutoLockTimeLimit={() => {}}
setIpfsGateway={() => {}}
setShowFiatConversionOnTestnetsPreference={() => {}}
setThreeBoxSyncingPermission={() => {}}
setAutoLockTimeLimit={() => undefined}
setIpfsGateway={() => undefined}
setShowFiatConversionOnTestnetsPreference={() => undefined}
setThreeBoxSyncingPermission={() => undefined}
threeBoxDisabled
threeBoxSyncingAllowed={false}
/>,
@ -33,9 +33,9 @@ describe('AdvancedTab Component', function () {
<AdvancedTab
ipfsGateway=""
setAutoLockTimeLimit={setAutoLockTimeLimitSpy}
setIpfsGateway={() => {}}
setShowFiatConversionOnTestnetsPreference={() => {}}
setThreeBoxSyncingPermission={() => {}}
setIpfsGateway={() => undefined}
setShowFiatConversionOnTestnetsPreference={() => undefined}
setThreeBoxSyncingPermission={() => undefined}
threeBoxDisabled
threeBoxSyncingAllowed={false}
/>,

View File

@ -28,7 +28,7 @@ describe('Security Tab', function () {
<SecurityTab.WrappedComponent {...props} />, {
context: {
t: (str) => str,
metricsEvent: () => {},
metricsEvent: () => undefined,
},
},
)