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