Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix no-param-reassign issues #9235

Merged
merged 1 commit into from
Aug 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
3 changes: 1 addition & 2 deletions app/scripts/controllers/network/network.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down
1 change: 1 addition & 0 deletions app/scripts/controllers/preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions app/scripts/controllers/transactions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions app/scripts/controllers/transactions/tx-state-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions app/scripts/lib/buy-eth-url.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
1 change: 1 addition & 0 deletions app/scripts/lib/migrator/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions app/scripts/lib/setupSentry.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
}

Expand Down
23 changes: 12 additions & 11 deletions app/scripts/migrations/038.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
9 changes: 5 additions & 4 deletions test/e2e/benchmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
Expand Down
5 changes: 2 additions & 3 deletions test/e2e/ganache.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
6 changes: 3 additions & 3 deletions test/e2e/webdriver/driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions test/unit/app/controllers/permissions/mocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
1 change: 1 addition & 0 deletions ui/app/components/ui/check-box/check-box.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
},
}

Expand Down
8 changes: 5 additions & 3 deletions ui/app/ducks/gas/gas.duck.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
3 changes: 2 additions & 1 deletion ui/app/helpers/utils/switch-direction.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 1 addition & 0 deletions ui/app/helpers/utils/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions ui/app/pages/send/send.utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ async function estimateGas ({

// if not, fall back to block gasLimit
if (!blockGasLimit) {
whymarrh marked this conversation as resolved.
Show resolved Hide resolved
// eslint-disable-next-line no-param-reassign
blockGasLimit = MIN_GAS_LIMIT_HEX
}

Expand Down
7 changes: 4 additions & 3 deletions ui/app/pages/send/tests/send-utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
3 changes: 1 addition & 2 deletions ui/app/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -511,8 +511,7 @@ export function decryptMsgInline (decryptedMsgData) {
}

dispatch(updateMetamaskState(newState))
decryptedMsgData = newState.unapprovedDecryptMsgs[decryptedMsgData.metamaskId]
return decryptedMsgData
return newState.unapprovedDecryptMsgs[decryptedMsgData.metamaskId]
}
}

Expand Down