fix: remove bad usages of for-in and guard against it (#22616)
* fix: remove bad usages of for-in and guard against it * Apply suggestions from code review Co-Authored-By: Samuel Maddock <samuel.maddock@gmail.com> * Apply suggestions from code review Co-Authored-By: Jeremy Apthorp <jeremya@chromium.org> * Update remote.js Co-authored-by: Samuel Maddock <samuel.maddock@gmail.com> Co-authored-by: Jeremy Apthorp <jeremya@chromium.org>
This commit is contained in:
parent
f4868c9a28
commit
5e4e50c5eb
7 changed files with 11 additions and 11 deletions
|
@ -9,6 +9,7 @@
|
||||||
"no-var": "error",
|
"no-var": "error",
|
||||||
"no-unused-vars": 0,
|
"no-unused-vars": 0,
|
||||||
"no-global-assign": 0,
|
"no-global-assign": 0,
|
||||||
|
"guard-for-in": 2,
|
||||||
"@typescript-eslint/no-unused-vars": ["error", {
|
"@typescript-eslint/no-unused-vars": ["error", {
|
||||||
"vars": "all",
|
"vars": "all",
|
||||||
"args": "after-used",
|
"args": "after-used",
|
||||||
|
|
|
@ -33,7 +33,7 @@ const delegate = {
|
||||||
},
|
},
|
||||||
menuWillShow: (menu) => {
|
menuWillShow: (menu) => {
|
||||||
// Ensure radio groups have at least one menu item selected
|
// Ensure radio groups have at least one menu item selected
|
||||||
for (const id in menu.groupsMap) {
|
for (const id of Object.keys(menu.groupsMap)) {
|
||||||
const found = menu.groupsMap[id].find(item => item.checked) || null
|
const found = menu.groupsMap[id].find(item => item.checked) || null
|
||||||
if (!found) v8Util.setHiddenValue(menu.groupsMap[id][0], 'checked', true)
|
if (!found) v8Util.setHiddenValue(menu.groupsMap[id][0], 'checked', true)
|
||||||
}
|
}
|
||||||
|
@ -201,8 +201,7 @@ function areValidTemplateItems (template) {
|
||||||
|
|
||||||
function sortTemplate (template) {
|
function sortTemplate (template) {
|
||||||
const sorted = sortMenuItems(template)
|
const sorted = sortMenuItems(template)
|
||||||
for (const id in sorted) {
|
for (const item of sorted) {
|
||||||
const item = sorted[id]
|
|
||||||
if (Array.isArray(item.submenu)) {
|
if (Array.isArray(item.submenu)) {
|
||||||
item.submenu = sortTemplate(item.submenu)
|
item.submenu = sortTemplate(item.submenu)
|
||||||
}
|
}
|
||||||
|
|
|
@ -365,7 +365,7 @@ class ClientRequest extends Writable {
|
||||||
this._started = true
|
this._started = true
|
||||||
const stringifyValues = (obj) => {
|
const stringifyValues = (obj) => {
|
||||||
const ret = {}
|
const ret = {}
|
||||||
for (const k in obj) {
|
for (const k of Object.keys(obj)) {
|
||||||
ret[k] = obj[k].toString()
|
ret[k] = obj[k].toString()
|
||||||
}
|
}
|
||||||
return ret
|
return ret
|
||||||
|
|
|
@ -74,7 +74,7 @@ const createGuest = function (embedder, params) {
|
||||||
|
|
||||||
// Clear the guest from map when it is destroyed.
|
// Clear the guest from map when it is destroyed.
|
||||||
guest.once('destroyed', () => {
|
guest.once('destroyed', () => {
|
||||||
if (guestInstanceId in guestInstances) {
|
if (Object.prototype.hasOwnProperty.call(guestInstances, guestInstanceId)) {
|
||||||
detachGuest(embedder, guestInstanceId)
|
detachGuest(embedder, guestInstanceId)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -288,7 +288,7 @@ const watchEmbedder = function (embedder) {
|
||||||
|
|
||||||
// Forward embedder window visiblity change events to guest
|
// Forward embedder window visiblity change events to guest
|
||||||
const onVisibilityChange = function (visibilityState) {
|
const onVisibilityChange = function (visibilityState) {
|
||||||
for (const guestInstanceId in guestInstances) {
|
for (const guestInstanceId of Object.keys(guestInstances)) {
|
||||||
const guestInstance = guestInstances[guestInstanceId]
|
const guestInstance = guestInstances[guestInstanceId]
|
||||||
guestInstance.visibilityState = visibilityState
|
guestInstance.visibilityState = visibilityState
|
||||||
if (guestInstance.embedder === embedder) {
|
if (guestInstance.embedder === embedder) {
|
||||||
|
@ -302,7 +302,7 @@ const watchEmbedder = function (embedder) {
|
||||||
// Usually the guestInstances is cleared when guest is destroyed, but it
|
// Usually the guestInstances is cleared when guest is destroyed, but it
|
||||||
// may happen that the embedder gets manually destroyed earlier than guest,
|
// may happen that the embedder gets manually destroyed earlier than guest,
|
||||||
// and the embedder will be invalid in the usual code path.
|
// and the embedder will be invalid in the usual code path.
|
||||||
for (const guestInstanceId in guestInstances) {
|
for (const guestInstanceId of Object.keys(guestInstances)) {
|
||||||
const guestInstance = guestInstances[guestInstanceId]
|
const guestInstance = guestInstances[guestInstanceId]
|
||||||
if (guestInstance.embedder === embedder) {
|
if (guestInstance.embedder === embedder) {
|
||||||
detachGuest(embedder, parseInt(guestInstanceId))
|
detachGuest(embedder, parseInt(guestInstanceId))
|
||||||
|
|
|
@ -18,7 +18,7 @@ export function createLazyInstance (
|
||||||
) {
|
) {
|
||||||
let lazyModule: Object
|
let lazyModule: Object
|
||||||
const module: any = {}
|
const module: any = {}
|
||||||
for (const method in (holder as any).prototype) {
|
for (const method in (holder as any).prototype) { // eslint-disable-line guard-for-in
|
||||||
module[method] = (...args: any) => {
|
module[method] = (...args: any) => {
|
||||||
// create new instance of module at runtime if none exists
|
// create new instance of module at runtime if none exists
|
||||||
if (!lazyModule) {
|
if (!lazyModule) {
|
||||||
|
|
|
@ -72,7 +72,7 @@ function wrapArgs (args, visited = new Set()) {
|
||||||
members: []
|
members: []
|
||||||
}
|
}
|
||||||
visited.add(value)
|
visited.add(value)
|
||||||
for (const prop in value) {
|
for (const prop in value) { // eslint-disable-line guard-for-in
|
||||||
meta.members.push({
|
meta.members.push({
|
||||||
name: prop,
|
name: prop,
|
||||||
value: valueToMeta(value[prop])
|
value: valueToMeta(value[prop])
|
||||||
|
@ -219,7 +219,7 @@ function metaToValue (meta) {
|
||||||
exception: () => { throw metaToError(meta.value) }
|
exception: () => { throw metaToError(meta.value) }
|
||||||
}
|
}
|
||||||
|
|
||||||
if (meta.type in types) {
|
if (Object.prototype.hasOwnProperty.call(types, meta.type)) {
|
||||||
return types[meta.type]()
|
return types[meta.type]()
|
||||||
} else {
|
} else {
|
||||||
let ret
|
let ret
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
function resolveSingleObjectGetters (object) {
|
function resolveSingleObjectGetters (object) {
|
||||||
if (object && typeof object === 'object') {
|
if (object && typeof object === 'object') {
|
||||||
const newObject = {}
|
const newObject = {}
|
||||||
for (const key in object) {
|
for (const key in object) { // eslint-disable-line guard-for-in
|
||||||
newObject[key] = resolveGetters(object[key])[0]
|
newObject[key] = resolveGetters(object[key])[0]
|
||||||
}
|
}
|
||||||
return newObject
|
return newObject
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue