mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Fix no-param-reassign issues (#9235)
See [`no-param-reassign`](https://eslint.org/docs/rules/no-param-reassign) for more information. This change enables `no-param-reassign` and fixes the issues raised by the rule.
This commit is contained in:
parent
60e261b52c
commit
e803807dd9
@ -61,6 +61,7 @@ module.exports = {
|
||||
'no-loop-func': 'error',
|
||||
'no-negated-condition': 'error',
|
||||
'no-nested-ternary': 'error',
|
||||
'no-param-reassign': 'error',
|
||||
'no-plusplus': ['error', { 'allowForLoopAfterthoughts': true }],
|
||||
'no-process-exit': 'error',
|
||||
'no-prototype-builtins': 'error',
|
||||
|
@ -101,8 +101,7 @@ export default class NetworkController extends EventEmitter {
|
||||
if (!type) {
|
||||
return
|
||||
}
|
||||
network = networks.networkList[type]?.chainId || network
|
||||
this.networkStore.putState(network)
|
||||
this.networkStore.putState(networks.networkList[type]?.chainId || network)
|
||||
}
|
||||
|
||||
isNetworkLoading () {
|
||||
|
@ -689,6 +689,7 @@ export default class PreferencesController {
|
||||
_getTokenRelatedStates (selectedAddress) {
|
||||
const accountTokens = this.store.getState().accountTokens
|
||||
if (!selectedAddress) {
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
selectedAddress = this.store.getState().selectedAddress
|
||||
}
|
||||
const providerType = this.network.providerStore.getState().type
|
||||
|
@ -271,6 +271,7 @@ export default class TransactionController extends EventEmitter {
|
||||
const defaultGasPrice = await this._getDefaultGasPrice(txMeta)
|
||||
const { gasLimit: defaultGasLimit, simulationFails } = await this._getDefaultGasLimit(txMeta, getCodeResponse)
|
||||
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
txMeta = this.txStateManager.getTx(txMeta.id)
|
||||
if (simulationFails) {
|
||||
txMeta.simulationFails = simulationFails
|
||||
|
@ -262,6 +262,7 @@ export default class TransactionStateManager extends EventEmitter {
|
||||
if (typeof txParams.data === 'undefined') {
|
||||
delete txParams.data
|
||||
}
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
txParams = normalizeTxParams(txParams, false)
|
||||
this.validateTxParams(txParams)
|
||||
return txParams
|
||||
|
@ -11,6 +11,7 @@
|
||||
export default function getBuyEthUrl ({ network, address, service }) {
|
||||
// default service by network if not specified
|
||||
if (!service) {
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
service = getDefaultServiceForNetwork(network)
|
||||
}
|
||||
|
||||
|
@ -46,6 +46,7 @@ export default class Migrator extends EventEmitter {
|
||||
throw new Error('Migrator - Migration did not update version number correctly')
|
||||
}
|
||||
// accept the migration as good
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
versionedData = migratedData
|
||||
} catch (err) {
|
||||
// rewrite error message to add context without clobbering stack
|
||||
|
@ -122,13 +122,13 @@ export default function setupSentry ({ release, getState }) {
|
||||
function simplifyErrorMessages (report) {
|
||||
rewriteErrorMessages(report, (errorMessage) => {
|
||||
// simplify ethjs error messages
|
||||
errorMessage = extractEthjsErrorMessage(errorMessage)
|
||||
let simplifiedErrorMessage = extractEthjsErrorMessage(errorMessage)
|
||||
// simplify 'Transaction Failed: known transaction'
|
||||
if (errorMessage.indexOf('Transaction Failed: known transaction') === 0) {
|
||||
if (simplifiedErrorMessage.indexOf('Transaction Failed: known transaction') === 0) {
|
||||
// cut the hash from the error message
|
||||
errorMessage = 'Transaction Failed: known transaction'
|
||||
simplifiedErrorMessage = 'Transaction Failed: known transaction'
|
||||
}
|
||||
return errorMessage
|
||||
return simplifiedErrorMessage
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -19,17 +19,18 @@ function transformState (state) {
|
||||
const { ABTestController: ABTestControllerState = {} } = state
|
||||
const { abTests = {} } = ABTestControllerState
|
||||
|
||||
if (!abTests.fullScreenVsPopup) {
|
||||
state = {
|
||||
...state,
|
||||
ABTestController: {
|
||||
...ABTestControllerState,
|
||||
abTests: {
|
||||
...abTests,
|
||||
fullScreenVsPopup: 'control',
|
||||
},
|
||||
},
|
||||
}
|
||||
if (abTests.fullScreenVsPopup) {
|
||||
return state
|
||||
}
|
||||
|
||||
return {
|
||||
...state,
|
||||
ABTestController: {
|
||||
...ABTestControllerState,
|
||||
abTests: {
|
||||
...abTests,
|
||||
fullScreenVsPopup: 'control',
|
||||
},
|
||||
},
|
||||
}
|
||||
return state
|
||||
}
|
||||
|
@ -92,17 +92,18 @@ async function isWritable (directory) {
|
||||
}
|
||||
|
||||
async function getFirstParentDirectoryThatExists (directory) {
|
||||
let nextDirectory = directory
|
||||
for (;;) {
|
||||
try {
|
||||
await fs.access(directory, fsConstants.F_OK)
|
||||
return directory
|
||||
await fs.access(nextDirectory, fsConstants.F_OK)
|
||||
return nextDirectory
|
||||
} catch (error) {
|
||||
if (error.code !== 'ENOENT') {
|
||||
throw error
|
||||
} else if (directory === path.dirname(directory)) {
|
||||
} else if (nextDirectory === path.dirname(nextDirectory)) {
|
||||
throw new Error('Failed to find parent directory that exists')
|
||||
}
|
||||
directory = path.dirname(directory)
|
||||
nextDirectory = path.dirname(nextDirectory)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -10,9 +10,8 @@ const defaultOptions = {
|
||||
}
|
||||
|
||||
class Ganache {
|
||||
async start (options) {
|
||||
options = Object.assign({}, defaultOptions, options)
|
||||
|
||||
async start (opts) {
|
||||
const options = { ...defaultOptions, ...opts }
|
||||
const port = options.port
|
||||
this._server = ganache.server(options)
|
||||
|
||||
|
@ -136,9 +136,8 @@ class Driver {
|
||||
}
|
||||
|
||||
async switchToWindowWithTitle (title, windowHandles) {
|
||||
if (!windowHandles) {
|
||||
windowHandles = await this.driver.getAllWindowHandles()
|
||||
}
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
windowHandles = windowHandles || await this.driver.getAllWindowHandles()
|
||||
|
||||
for (const handle of windowHandles) {
|
||||
await this.driver.switchTo().window(handle)
|
||||
@ -158,6 +157,7 @@ class Driver {
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
async closeAllWindowHandlesExcept (exceptions, windowHandles) {
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
windowHandles = windowHandles || await this.driver.getAllWindowHandles()
|
||||
|
||||
for (const handle of windowHandles) {
|
||||
|
@ -108,6 +108,7 @@ export function getPermissionsMiddleware (permController, origin, extensionId) {
|
||||
return (req, res = {}, next = noop, end) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
end = end || _end
|
||||
|
||||
middleware(req, res, next, end)
|
||||
|
@ -247,6 +247,7 @@ export default class SignatureRequestOriginal extends Component {
|
||||
{
|
||||
rows.map(({ name, value }, index) => {
|
||||
if (typeof value === 'boolean') {
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
value = value.toString()
|
||||
}
|
||||
return (
|
||||
|
@ -12,6 +12,7 @@ export const { CHECKED, INDETERMINATE, UNCHECKED } = CHECKBOX_STATE
|
||||
|
||||
const CheckBox = ({ className, disabled, id, onClick, checked, title }) => {
|
||||
if (typeof checked === 'boolean') {
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
checked = checked
|
||||
? CHECKBOX_STATE.CHECKED
|
||||
: CHECKBOX_STATE.UNCHECKED
|
||||
|
@ -258,16 +258,14 @@ export function setFetchingData (isFetching) {
|
||||
}
|
||||
|
||||
export function updateGasAndCalculate ({ gasLimit, gasPrice }) {
|
||||
gasLimit = addHexPrefix(gasLimit)
|
||||
gasPrice = addHexPrefix(gasPrice)
|
||||
return (dispatch, getState) => {
|
||||
const { confirmTransaction: { txData } } = getState()
|
||||
const newTxData = {
|
||||
...txData,
|
||||
txParams: {
|
||||
...txData.txParams,
|
||||
gas: gasLimit,
|
||||
gasPrice,
|
||||
gas: addHexPrefix(gasLimit),
|
||||
gasPrice: addHexPrefix(gasPrice),
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -323,20 +323,22 @@ async function fetchExternalBasicGasAndTimeEstimates (dispatch) {
|
||||
}
|
||||
|
||||
function extrapolateY ({ higherY, lowerY, higherX, lowerX, xForExtrapolation }) {
|
||||
/* eslint-disable no-param-reassign */
|
||||
higherY = new BigNumber(higherY, 10)
|
||||
lowerY = new BigNumber(lowerY, 10)
|
||||
higherX = new BigNumber(higherX, 10)
|
||||
lowerX = new BigNumber(lowerX, 10)
|
||||
xForExtrapolation = new BigNumber(xForExtrapolation, 10)
|
||||
/* eslint-enable no-param-reassign */
|
||||
const slope = (higherY.minus(lowerY)).div(higherX.minus(lowerX))
|
||||
const newTimeEstimate = slope.times(higherX.minus(xForExtrapolation)).minus(higherY).negated()
|
||||
|
||||
return Number(newTimeEstimate.toPrecision(10))
|
||||
}
|
||||
|
||||
function getRandomArbitrary (min, max) {
|
||||
min = new BigNumber(min, 10)
|
||||
max = new BigNumber(max, 10)
|
||||
function getRandomArbitrary (minStr, maxStr) {
|
||||
const min = new BigNumber(minStr, 10)
|
||||
const max = new BigNumber(maxStr, 10)
|
||||
const random = new BigNumber(String(Math.random()), 10)
|
||||
return new BigNumber(random.times(max.minus(min)).plus(min)).toPrecision(10)
|
||||
}
|
||||
|
@ -1,10 +1,11 @@
|
||||
/**
|
||||
* Switch the CSS stylesheet used between 'rtl' and 'ltr'
|
||||
* @param {('ltr' | 'rtl')} direction - Text direction, either left-to-right (ltr) or right-to-left (rtl)
|
||||
* @param {('ltr' | 'rtl' | 'auto')} direction - Text direction, either left-to-right (ltr) or right-to-left (rtl)
|
||||
* @return {Promise<void>}
|
||||
*/
|
||||
const switchDirection = async (direction) => {
|
||||
if (direction === 'auto') {
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
direction = 'ltr'
|
||||
}
|
||||
let updatedLink
|
||||
|
@ -241,6 +241,7 @@ export function getRandomFileName () {
|
||||
}
|
||||
|
||||
export function exportAsFile (filename, data, type = 'text/csv') {
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
filename = filename || getRandomFileName()
|
||||
// source: https://stackoverflow.com/a/33542499 by Ludovic Feltz
|
||||
const blob = new window.Blob([data], { type })
|
||||
|
@ -78,8 +78,8 @@ export default class EnsInput extends Component {
|
||||
updateEnsResolutionError('')
|
||||
}
|
||||
|
||||
lookupEnsName = (recipient) => {
|
||||
recipient = recipient.trim()
|
||||
lookupEnsName = (ensName) => {
|
||||
const recipient = ensName.trim()
|
||||
|
||||
log.info(`ENS attempting to resolve name: ${recipient}`)
|
||||
this.ens.lookup(recipient)
|
||||
|
@ -238,6 +238,7 @@ async function estimateGas ({
|
||||
|
||||
// if not, fall back to block gasLimit
|
||||
if (!blockGasLimit) {
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
blockGasLimit = MIN_GAS_LIMIT_HEX
|
||||
}
|
||||
|
||||
|
@ -10,13 +10,14 @@ import {
|
||||
|
||||
const stubs = {
|
||||
addCurrencies: sinon.stub().callsFake((a, b) => {
|
||||
let [a1, b1] = [a, b]
|
||||
if (String(a).match(/^0x.+/u)) {
|
||||
a = Number(String(a).slice(2))
|
||||
a1 = Number(String(a).slice(2))
|
||||
}
|
||||
if (String(b).match(/^0x.+/u)) {
|
||||
b = Number(String(b).slice(2))
|
||||
b1 = Number(String(b).slice(2))
|
||||
}
|
||||
return a + b
|
||||
return a1 + b1
|
||||
}),
|
||||
conversionUtil: sinon.stub().callsFake((val) => parseInt(val, 16)),
|
||||
conversionGTE: sinon.stub().callsFake((obj1, obj2) => obj1.value >= obj2.value),
|
||||
|
@ -511,8 +511,7 @@ export function decryptMsgInline (decryptedMsgData) {
|
||||
}
|
||||
|
||||
dispatch(updateMetamaskState(newState))
|
||||
decryptedMsgData = newState.unapprovedDecryptMsgs[decryptedMsgData.metamaskId]
|
||||
return decryptedMsgData
|
||||
return newState.unapprovedDecryptMsgs[decryptedMsgData.metamaskId]
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user