1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00

Enable guard-for-in rule (#9000)

This commit is contained in:
Whymarrh Whitby 2020-07-21 18:40:45 -02:30 committed by GitHub
parent 35a6ad98b3
commit bf6578c6b8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 31 additions and 27 deletions

View File

@ -45,6 +45,7 @@ module.exports = {
'array-callback-return': 'error', 'array-callback-return': 'error',
'callback-return': 'error', 'callback-return': 'error',
'global-require': 'error', 'global-require': 'error',
'guard-for-in': 'error',
/* End v2 rules */ /* End v2 rules */
'arrow-parens': 'error', 'arrow-parens': 'error',
'no-tabs': 'error', 'no-tabs': 'error',

View File

@ -337,9 +337,9 @@ export default class PreferencesController {
} }
// store lost accounts // store lost accounts
for (const key in newlyLost) { Object.keys(newlyLost).forEach((key) => {
lostIdentities[key] = newlyLost[key] lostIdentities[key] = newlyLost[key]
} })
} }
this.store.updateState({ identities, lostIdentities }) this.store.updateState({ identities, lostIdentities })

View File

@ -25,11 +25,13 @@ export default class ComposableObservableStore extends ObservableStore {
this.config = config this.config = config
this.removeAllListeners() this.removeAllListeners()
for (const key in config) { for (const key in config) {
if (config.hasOwnProperty(key)) {
config[key].subscribe((state) => { config[key].subscribe((state) => {
this.updateState({ [key]: state }) this.updateState({ [key]: state })
}) })
} }
} }
}
/** /**
* Merges all child store state into a single object rather than * Merges all child store state into a single object rather than
@ -40,10 +42,12 @@ export default class ComposableObservableStore extends ObservableStore {
getFlatState () { getFlatState () {
let flatState = {} let flatState = {}
for (const key in this.config) { for (const key in this.config) {
if (this.config.hasOwnProperty(key)) {
const controller = this.config[key] const controller = this.config[key]
const state = controller.getState ? controller.getState() : controller.state const state = controller.getState ? controller.getState() : controller.state
flatState = { ...flatState, ...state } flatState = { ...flatState, ...state }
} }
}
return flatState return flatState
} }
} }

View File

@ -35,8 +35,7 @@ export default class Migrator extends EventEmitter {
const pendingMigrations = this.migrations.filter(migrationIsPending) const pendingMigrations = this.migrations.filter(migrationIsPending)
// perform each migration // perform each migration
for (const index in pendingMigrations) { for (const migration of pendingMigrations) {
const migration = pendingMigrations[index]
try { try {
// attempt migration and validate // attempt migration and validate
const migratedData = await migration.migrate(versionedData) const migratedData = await migration.migrate(versionedData)

View File

@ -29,9 +29,9 @@ function transformState (state) {
const identities = newState.PreferencesController.identities const identities = newState.PreferencesController.identities
const tokens = newState.PreferencesController.tokens const tokens = newState.PreferencesController.tokens
newState.PreferencesController.accountTokens = {} newState.PreferencesController.accountTokens = {}
for (const identity in identities) { Object.keys(identities).forEach((identity) => {
newState.PreferencesController.accountTokens[identity] = { 'mainnet': tokens } newState.PreferencesController.accountTokens[identity] = { 'mainnet': tokens }
} })
newState.PreferencesController.tokens = [] newState.PreferencesController.tokens = []
} }
} }

View File

@ -27,9 +27,9 @@ function transformState (state) {
const newAddressBook = {} const newAddressBook = {}
// add all of the chainIds to a set // add all of the chainIds to a set
for (const item in ab) { Object.values(ab).forEach((v) => {
chainIds.add(ab[item].chainId) chainIds.add(v.chainId)
} })
// fill the chainId object with the entries with the matching chainId // fill the chainId object with the entries with the matching chainId
for (const id of chainIds.values()) { for (const id of chainIds.values()) {

View File

@ -323,7 +323,7 @@ describe('TransactionStateManager', function () {
} }
const invalidValues = [1, true, {}, Symbol('1')] const invalidValues = [1, true, {}, Symbol('1')]
for (const key in validTxParams) { Object.keys(validTxParams).forEach((key) => {
for (const value of invalidValues) { for (const value of invalidValues) {
const tx = { const tx = {
id: 1, id: 1,
@ -339,7 +339,7 @@ describe('TransactionStateManager', function () {
assert.ok(Array.isArray(result), 'txList should be an array') assert.ok(Array.isArray(result), 'txList should be an array')
assert.equal(result.length, 0, 'txList should be empty') assert.equal(result.length, 0, 'txList should be empty')
} }
} })
}) })
it('does not override txs from other networks', function () { 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 }) 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) { for (const value of invalidValues) {
const originalTx = txStateManager.getTx(1) const originalTx = txStateManager.getTx(1)
const newTx = { const newTx = {
@ -430,7 +430,7 @@ describe('TransactionStateManager', function () {
const result = txStateManager.getTx(1) const result = txStateManager.getTx(1)
assert.deepEqual(result, originalTx, 'tx should not be updated') assert.deepEqual(result, originalTx, 'tx should not be updated')
} }
} })
}) })
it('updates gas price and adds history items', function () { it('updates gas price and adds history items', function () {

View File

@ -25,16 +25,16 @@ const insertKeyframesRule = (keyframes) => {
const name = 'anim_' + (++index) + (+new Date()) const name = 'anim_' + (++index) + (+new Date())
let css = '@' + 'keyframes ' + name + ' {' let css = '@' + 'keyframes ' + name + ' {'
for (const key in keyframes) { Object.keys(keyframes).forEach((key) => {
css += key + ' {' css += key + ' {'
for (const property in keyframes[key]) { Object.keys(keyframes[key]).forEach((property) => {
const part = ':' + keyframes[key][property] + ';' const part = ':' + keyframes[key][property] + ';'
css += property + part css += property + part
} })
css += '}' css += '}'
} })
css += '}' css += '}'

View File

@ -28,9 +28,9 @@ const valueTable = {
tether: '0.000000000001', tether: '0.000000000001',
} }
const bnTable = {} const bnTable = {}
for (const currency in valueTable) { Object.keys(valueTable).forEach((currency) => {
bnTable[currency] = new ethUtil.BN(valueTable[currency], 10) bnTable[currency] = new ethUtil.BN(valueTable[currency], 10)
} })
export function isEthNetwork (netId) { export function isEthNetwork (netId) {
if (!netId || netId === '1' || netId === '3' || netId === '4' || netId === '42' || netId === '5777') { if (!netId || netId === '1' || netId === '3' || netId === '4' || netId === '42' || netId === '5777') {

View File

@ -230,11 +230,11 @@ describe('util', function () {
} }
const oneEthBn = new ethUtil.BN(ethInWei, 10) 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 value = new ethUtil.BN(valueTable[currency], 10)
const output = util.normalizeToWei(value, currency) const output = util.normalizeToWei(value, currency)
assert.equal(output.toString(10), valueTable.wei, `value of ${output.toString(10)} ${currency} should convert to ${oneEthBn}`) assert.equal(output.toString(10), valueTable.wei, `value of ${output.toString(10)} ${currency} should convert to ${oneEthBn}`)
} })
}) })
}) })