Enable guard-for-in rule (#9000)

feature/default_network_editable
Whymarrh Whitby 4 years ago committed by GitHub
parent 35a6ad98b3
commit bf6578c6b8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      .eslintrc.js
  2. 4
      app/scripts/controllers/preferences.js
  3. 16
      app/scripts/lib/ComposableObservableStore.js
  4. 3
      app/scripts/lib/migrator/index.js
  5. 4
      app/scripts/migrations/028.js
  6. 6
      app/scripts/migrations/037.js
  7. 8
      test/unit/app/controllers/transactions/tx-state-manager-test.js
  8. 8
      ui/app/components/app/modals/fade-modal.js
  9. 4
      ui/app/helpers/utils/util.js
  10. 4
      ui/app/helpers/utils/util.test.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',

@ -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 })

@ -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
}

@ -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)

@ -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 = []
}
}

@ -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()) {

@ -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 () {

@ -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 += '}'

@ -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') {

@ -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}`)
}
})
})
})

Loading…
Cancel
Save