mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Fix no-empty issues (#9202)
See [`no-empty`](https://eslint.org/docs/rules/no-empty) for more information. This change enables `no-empty` and fixes the issues raised by the rule.
This commit is contained in:
parent
3346c2fc07
commit
88f54e29fb
@ -48,6 +48,7 @@ module.exports = {
|
|||||||
'global-require': 'error',
|
'global-require': 'error',
|
||||||
'guard-for-in': 'error',
|
'guard-for-in': 'error',
|
||||||
'no-case-declarations': 'error',
|
'no-case-declarations': 'error',
|
||||||
|
'no-empty': 'error',
|
||||||
'no-loop-func': 'error',
|
'no-loop-func': 'error',
|
||||||
'no-useless-catch': 'error',
|
'no-useless-catch': 'error',
|
||||||
'no-useless-concat': 'error',
|
'no-useless-concat': 'error',
|
||||||
|
@ -14,7 +14,9 @@ export default {
|
|||||||
versionedData.data.config.provider.type = 'rpc'
|
versionedData.data.config.provider.type = 'rpc'
|
||||||
versionedData.data.config.provider.rpcTarget = 'https://rpc.metamask.io/'
|
versionedData.data.config.provider.rpcTarget = 'https://rpc.metamask.io/'
|
||||||
}
|
}
|
||||||
} catch (e) {}
|
} catch (_) {
|
||||||
|
// empty
|
||||||
|
}
|
||||||
return Promise.resolve(versionedData)
|
return Promise.resolve(versionedData)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,9 @@ export default {
|
|||||||
if (versionedData.data.config.provider.rpcTarget === oldTestRpc) {
|
if (versionedData.data.config.provider.rpcTarget === oldTestRpc) {
|
||||||
versionedData.data.config.provider.rpcTarget = newTestRpc
|
versionedData.data.config.provider.rpcTarget = newTestRpc
|
||||||
}
|
}
|
||||||
} catch (e) {}
|
} catch (_) {
|
||||||
|
// empty
|
||||||
|
}
|
||||||
return Promise.resolve(versionedData)
|
return Promise.resolve(versionedData)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,9 @@ export default {
|
|||||||
break
|
break
|
||||||
// No default
|
// No default
|
||||||
}
|
}
|
||||||
} catch (_) {}
|
} catch (_) {
|
||||||
|
// empty
|
||||||
|
}
|
||||||
return Promise.resolve(safeVersionedData)
|
return Promise.resolve(safeVersionedData)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -49,7 +49,9 @@ async function validateSourcemapForFile ({ buildName }) {
|
|||||||
try {
|
try {
|
||||||
const filePath = path.join(__dirname, `/../dist/${platform}/`, `${buildName}`)
|
const filePath = path.join(__dirname, `/../dist/${platform}/`, `${buildName}`)
|
||||||
rawBuild = await fsAsync.readFile(filePath, 'utf8')
|
rawBuild = await fsAsync.readFile(filePath, 'utf8')
|
||||||
} catch (err) {}
|
} catch (_) {
|
||||||
|
// empty
|
||||||
|
}
|
||||||
if (!rawBuild) {
|
if (!rawBuild) {
|
||||||
throw new Error(`SourcemapValidator - failed to load source file for "${buildName}"`)
|
throw new Error(`SourcemapValidator - failed to load source file for "${buildName}"`)
|
||||||
}
|
}
|
||||||
@ -58,12 +60,16 @@ async function validateSourcemapForFile ({ buildName }) {
|
|||||||
try {
|
try {
|
||||||
const filePath = path.join(__dirname, `/../dist/sourcemaps/`, `${buildName}.map`)
|
const filePath = path.join(__dirname, `/../dist/sourcemaps/`, `${buildName}.map`)
|
||||||
rawSourceMap = await fsAsync.readFile(filePath, 'utf8')
|
rawSourceMap = await fsAsync.readFile(filePath, 'utf8')
|
||||||
} catch (err) {}
|
} catch (_) {
|
||||||
|
// empty
|
||||||
|
}
|
||||||
// attempt to load in dev mode
|
// attempt to load in dev mode
|
||||||
try {
|
try {
|
||||||
const filePath = path.join(__dirname, `/../dist/${platform}/`, `${buildName}.map`)
|
const filePath = path.join(__dirname, `/../dist/${platform}/`, `${buildName}.map`)
|
||||||
rawSourceMap = await fsAsync.readFile(filePath, 'utf8')
|
rawSourceMap = await fsAsync.readFile(filePath, 'utf8')
|
||||||
} catch (err) {}
|
} catch (_) {
|
||||||
|
// empty
|
||||||
|
}
|
||||||
if (!rawSourceMap) {
|
if (!rawSourceMap) {
|
||||||
throw new Error(`SourcemapValidator - failed to load sourcemaps for "${buildName}"`)
|
throw new Error(`SourcemapValidator - failed to load sourcemaps for "${buildName}"`)
|
||||||
}
|
}
|
||||||
|
@ -478,46 +478,16 @@ describe('preferences controller', function () {
|
|||||||
assert.ok(assetImages[address], `set image correctly`)
|
assert.ok(assetImages[address], `set image correctly`)
|
||||||
})
|
})
|
||||||
it('should validate ERC20 asset correctly', async function () {
|
it('should validate ERC20 asset correctly', async function () {
|
||||||
const validateSpy = sandbox.spy(preferencesController._validateERC20AssetParams)
|
const validate = preferencesController._validateERC20AssetParams
|
||||||
try {
|
|
||||||
validateSpy({ rawAddress: '0xd26114cd6EE289AccF82350c8d8487fedB8A0C07', symbol: 'ABC', decimals: 0 })
|
assert.doesNotThrow(() => validate({ rawAddress: '0xd26114cd6EE289AccF82350c8d8487fedB8A0C07', symbol: 'ABC', decimals: 0 }))
|
||||||
} catch (e) {}
|
assert.throws(() => validate({ symbol: 'ABC', decimals: 0 }), 'missing address should fail')
|
||||||
assert.equal(validateSpy.threw(), false, 'correct options object')
|
assert.throws(() => validate({ rawAddress: '0xd26114cd6EE289AccF82350c8d8487fedB8A0C07', decimals: 0 }), 'missing symbol should fail')
|
||||||
const validateSpyAddress = sandbox.spy(preferencesController._validateERC20AssetParams)
|
assert.throws(() => validate({ rawAddress: '0xd26114cd6EE289AccF82350c8d8487fedB8A0C07', symbol: 'ABC' }), 'missing decimals should fail')
|
||||||
try {
|
assert.throws(() => validate({ rawAddress: '0xd26114cd6EE289AccF82350c8d8487fedB8A0C07', symbol: 'ABCDEFGHI', decimals: 0 }), 'invalid symbol should fail')
|
||||||
validateSpyAddress({ symbol: 'ABC', decimals: 0 })
|
assert.throws(() => validate({ rawAddress: '0xd26114cd6EE289AccF82350c8d8487fedB8A0C07', symbol: 'ABCDEFGHI', decimals: -1 }), 'decimals < 0 should fail')
|
||||||
} catch (e) {}
|
assert.throws(() => validate({ rawAddress: '0xd26114cd6EE289AccF82350c8d8487fedB8A0C07', symbol: 'ABCDEFGHI', decimals: 38 }), 'decimals > 36 should fail')
|
||||||
assert.equal(validateSpyAddress.threw(), true, 'options object with no address')
|
assert.throws(() => validate({ rawAddress: '0x123', symbol: 'ABC', decimals: 0 }), 'invalid address should fail')
|
||||||
const validateSpySymbol = sandbox.spy(preferencesController._validateERC20AssetParams)
|
|
||||||
try {
|
|
||||||
validateSpySymbol({ rawAddress: '0xd26114cd6EE289AccF82350c8d8487fedB8A0C07', decimals: 0 })
|
|
||||||
} catch (e) {}
|
|
||||||
assert.equal(validateSpySymbol.threw(), true, 'options object with no symbol')
|
|
||||||
const validateSpyDecimals = sandbox.spy(preferencesController._validateERC20AssetParams)
|
|
||||||
try {
|
|
||||||
validateSpyDecimals({ rawAddress: '0xd26114cd6EE289AccF82350c8d8487fedB8A0C07', symbol: 'ABC' })
|
|
||||||
} catch (e) {}
|
|
||||||
assert.equal(validateSpyDecimals.threw(), true, 'options object with no decimals')
|
|
||||||
const validateSpyInvalidSymbol = sandbox.spy(preferencesController._validateERC20AssetParams)
|
|
||||||
try {
|
|
||||||
validateSpyInvalidSymbol({ rawAddress: '0xd26114cd6EE289AccF82350c8d8487fedB8A0C07', symbol: 'ABCDEFGHI', decimals: 0 })
|
|
||||||
} catch (e) {}
|
|
||||||
assert.equal(validateSpyInvalidSymbol.threw(), true, 'options object with invalid symbol')
|
|
||||||
const validateSpyInvalidDecimals1 = sandbox.spy(preferencesController._validateERC20AssetParams)
|
|
||||||
try {
|
|
||||||
validateSpyInvalidDecimals1({ rawAddress: '0xd26114cd6EE289AccF82350c8d8487fedB8A0C07', symbol: 'ABCDEFGHI', decimals: -1 })
|
|
||||||
} catch (e) {}
|
|
||||||
assert.equal(validateSpyInvalidDecimals1.threw(), true, 'options object with decimals less than zero')
|
|
||||||
const validateSpyInvalidDecimals2 = sandbox.spy(preferencesController._validateERC20AssetParams)
|
|
||||||
try {
|
|
||||||
validateSpyInvalidDecimals2({ rawAddress: '0xd26114cd6EE289AccF82350c8d8487fedB8A0C07', symbol: 'ABCDEFGHI', decimals: 38 })
|
|
||||||
} catch (e) {}
|
|
||||||
assert.equal(validateSpyInvalidDecimals2.threw(), true, 'options object with decimals more than 36')
|
|
||||||
const validateSpyInvalidAddress = sandbox.spy(preferencesController._validateERC20AssetParams)
|
|
||||||
try {
|
|
||||||
validateSpyInvalidAddress({ rawAddress: '0x123', symbol: 'ABC', decimals: 0 })
|
|
||||||
} catch (e) {}
|
|
||||||
assert.equal(validateSpyInvalidAddress.threw(), true, 'options object with address invalid')
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -189,8 +189,9 @@ export function shortenBalance (balance, decimalsToKeep = 1) {
|
|||||||
export function normalizeToWei (amount, currency) {
|
export function normalizeToWei (amount, currency) {
|
||||||
try {
|
try {
|
||||||
return amount.mul(bnTable.wei).div(bnTable[currency])
|
return amount.mul(bnTable.wei).div(bnTable[currency])
|
||||||
} catch (e) {}
|
} catch (e) {
|
||||||
return amount
|
return amount
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function normalizeEthStringToWei (str) {
|
export function normalizeEthStringToWei (str) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user