diff --git a/.eslintrc.js b/.eslintrc.js index 98303eb24..8ea5865e8 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -45,6 +45,7 @@ module.exports = { 'array-callback-return': 'error', 'callback-return': 'error', 'global-require': 'error', + 'guard-for-in': 'error', /* End v2 rules */ 'arrow-parens': 'error', 'no-tabs': 'error', diff --git a/app/scripts/controllers/preferences.js b/app/scripts/controllers/preferences.js index 855a07c0c..47fa73746 100644 --- a/app/scripts/controllers/preferences.js +++ b/app/scripts/controllers/preferences.js @@ -337,9 +337,9 @@ export default class PreferencesController { } // store lost accounts - for (const key in newlyLost) { + Object.keys(newlyLost).forEach((key) => { lostIdentities[key] = newlyLost[key] - } + }) } this.store.updateState({ identities, lostIdentities }) diff --git a/app/scripts/lib/ComposableObservableStore.js b/app/scripts/lib/ComposableObservableStore.js index d8308465b..3f8b99af4 100644 --- a/app/scripts/lib/ComposableObservableStore.js +++ b/app/scripts/lib/ComposableObservableStore.js @@ -25,9 +25,11 @@ export default class ComposableObservableStore extends ObservableStore { this.config = config this.removeAllListeners() for (const key in config) { - config[key].subscribe((state) => { - this.updateState({ [key]: state }) - }) + if (config.hasOwnProperty(key)) { + config[key].subscribe((state) => { + this.updateState({ [key]: state }) + }) + } } } @@ -40,9 +42,11 @@ export default class ComposableObservableStore extends ObservableStore { getFlatState () { let flatState = {} for (const key in this.config) { - const controller = this.config[key] - const state = controller.getState ? controller.getState() : controller.state - flatState = { ...flatState, ...state } + if (this.config.hasOwnProperty(key)) { + const controller = this.config[key] + const state = controller.getState ? controller.getState() : controller.state + flatState = { ...flatState, ...state } + } } return flatState } diff --git a/app/scripts/lib/migrator/index.js b/app/scripts/lib/migrator/index.js index ebc70f73f..a82b93294 100644 --- a/app/scripts/lib/migrator/index.js +++ b/app/scripts/lib/migrator/index.js @@ -35,8 +35,7 @@ export default class Migrator extends EventEmitter { const pendingMigrations = this.migrations.filter(migrationIsPending) // perform each migration - for (const index in pendingMigrations) { - const migration = pendingMigrations[index] + for (const migration of pendingMigrations) { try { // attempt migration and validate const migratedData = await migration.migrate(versionedData) diff --git a/app/scripts/migrations/028.js b/app/scripts/migrations/028.js index 583f3299d..09fc18f11 100644 --- a/app/scripts/migrations/028.js +++ b/app/scripts/migrations/028.js @@ -29,9 +29,9 @@ function transformState (state) { const identities = newState.PreferencesController.identities const tokens = newState.PreferencesController.tokens newState.PreferencesController.accountTokens = {} - for (const identity in identities) { + Object.keys(identities).forEach((identity) => { newState.PreferencesController.accountTokens[identity] = { 'mainnet': tokens } - } + }) newState.PreferencesController.tokens = [] } } diff --git a/app/scripts/migrations/037.js b/app/scripts/migrations/037.js index 42287af4f..1d7f13810 100644 --- a/app/scripts/migrations/037.js +++ b/app/scripts/migrations/037.js @@ -27,9 +27,9 @@ function transformState (state) { const newAddressBook = {} // add all of the chainIds to a set - for (const item in ab) { - chainIds.add(ab[item].chainId) - } + Object.values(ab).forEach((v) => { + chainIds.add(v.chainId) + }) // fill the chainId object with the entries with the matching chainId for (const id of chainIds.values()) { diff --git a/test/unit/app/controllers/transactions/tx-state-manager-test.js b/test/unit/app/controllers/transactions/tx-state-manager-test.js index 5290bbd81..abd7a7098 100644 --- a/test/unit/app/controllers/transactions/tx-state-manager-test.js +++ b/test/unit/app/controllers/transactions/tx-state-manager-test.js @@ -323,7 +323,7 @@ describe('TransactionStateManager', function () { } const invalidValues = [1, true, {}, Symbol('1')] - for (const key in validTxParams) { + Object.keys(validTxParams).forEach((key) => { for (const value of invalidValues) { const tx = { id: 1, @@ -339,7 +339,7 @@ describe('TransactionStateManager', function () { assert.ok(Array.isArray(result), 'txList should be an array') assert.equal(result.length, 0, 'txList should be empty') } - } + }) }) it('does not override txs from other networks', function () { @@ -416,7 +416,7 @@ describe('TransactionStateManager', function () { txStateManager.addTx({ id: 1, status: 'unapproved', metamaskNetworkId: currentNetworkId, txParams: validTxParams }) - for (const key in validTxParams) { + Object.keys(validTxParams).forEach((key) => { for (const value of invalidValues) { const originalTx = txStateManager.getTx(1) const newTx = { @@ -430,7 +430,7 @@ describe('TransactionStateManager', function () { const result = txStateManager.getTx(1) assert.deepEqual(result, originalTx, 'tx should not be updated') } - } + }) }) it('updates gas price and adds history items', function () { diff --git a/ui/app/components/app/modals/fade-modal.js b/ui/app/components/app/modals/fade-modal.js index 873861e27..a59c8995b 100644 --- a/ui/app/components/app/modals/fade-modal.js +++ b/ui/app/components/app/modals/fade-modal.js @@ -25,16 +25,16 @@ const insertKeyframesRule = (keyframes) => { const name = 'anim_' + (++index) + (+new Date()) let css = '@' + 'keyframes ' + name + ' {' - for (const key in keyframes) { + Object.keys(keyframes).forEach((key) => { css += key + ' {' - for (const property in keyframes[key]) { + Object.keys(keyframes[key]).forEach((property) => { const part = ':' + keyframes[key][property] + ';' css += property + part - } + }) css += '}' - } + }) css += '}' diff --git a/ui/app/helpers/utils/util.js b/ui/app/helpers/utils/util.js index 37f852530..7643519a8 100644 --- a/ui/app/helpers/utils/util.js +++ b/ui/app/helpers/utils/util.js @@ -28,9 +28,9 @@ const valueTable = { tether: '0.000000000001', } const bnTable = {} -for (const currency in valueTable) { +Object.keys(valueTable).forEach((currency) => { bnTable[currency] = new ethUtil.BN(valueTable[currency], 10) -} +}) export function isEthNetwork (netId) { if (!netId || netId === '1' || netId === '3' || netId === '4' || netId === '42' || netId === '5777') { diff --git a/ui/app/helpers/utils/util.test.js b/ui/app/helpers/utils/util.test.js index 4be1713e9..ef1f5f153 100644 --- a/ui/app/helpers/utils/util.test.js +++ b/ui/app/helpers/utils/util.test.js @@ -230,11 +230,11 @@ describe('util', function () { } const oneEthBn = new ethUtil.BN(ethInWei, 10) - for (const currency in valueTable) { + Object.keys(valueTable).forEach((currency) => { const value = new ethUtil.BN(valueTable[currency], 10) const output = util.normalizeToWei(value, currency) assert.equal(output.toString(10), valueTable.wei, `value of ${output.toString(10)} ${currency} should convert to ${oneEthBn}`) - } + }) }) })