Skip to content

Commit 72ac1c6

Browse files
committed
Fixed lint warnings: unicorn/no-for-loop
Signed-off-by: Vitika9 <[email protected]>
1 parent 1ed2069 commit 72ac1c6

File tree

6 files changed

+29
-35
lines changed

6 files changed

+29
-35
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
],
7979
"no-unused-vars": "error",
8080
"prefer-destructuring": "warn",
81-
"unicorn/no-for-loop": "warn",
81+
"unicorn/no-for-loop": "error",
8282
"unicorn/prefer-includes": "warn",
8383
"unicorn/prefer-string-slice": "warn",
8484
"unicorn/filename-case": "warn",

src/main/zapHomeFiles/hud/display.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -736,10 +736,9 @@ Vue.component('site-tree-node', {
736736
channel.port1.addEventListener('message', event => {
737737
// Remove the ..loading.. child
738738
Vue.set(treeNode.model, 'children', []);
739-
for (let i = 0; i < event.data.childNodes.length; i++) {
740-
const child = event.data.childNodes[i];
739+
event.data.childNodes.forEach(child => {
741740
treeNode.addChild(child.name, child.method, child.isLeaf, child.hrefId);
742-
}
741+
});
743742
});
744743

745744
navigator.serviceWorker.controller.postMessage({

src/main/zapHomeFiles/hud/tools/break.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,11 @@ const Break = (function () {
140140
let r = false;
141141

142142
if (isFirefox) {
143-
for (let i = 0; i < clients.length; i++) {
144-
if (clients[i].visibilityState === 'visible') {
143+
clients.forEach(client => {
144+
if (client.visibilityState === 'visible') {
145145
r = true;
146146
}
147-
}
147+
});
148148
} else if (clients.length > 0) {
149149
r = true;
150150
}
@@ -202,11 +202,11 @@ const Break = (function () {
202202
let r = false;
203203

204204
if (isFirefox) {
205-
for (let i = 0; i < clients.length; i++) {
206-
if (clients[i].visibilityState === 'visible') {
205+
clients.forEach(client => {
206+
if (client.visibilityState === 'visible') {
207207
r = true;
208208
}
209-
}
209+
});
210210
} else if (clients.length > 0) {
211211
r = true;
212212
}

src/main/zapHomeFiles/hud/tools/commonAlerts.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,8 @@ const CommonAlerts = (function () {
145145
for (const alertName in pageAlerts[alertRisk]) {
146146
if (Object.prototype.hasOwnProperty.call(pageAlerts[alertRisk], alertName)) {
147147
const reportedParameters = new Set();
148-
for (let i = 0; i < pageAlerts[alertRisk][alertName].length; i++) {
149-
const alert = pageAlerts[alertRisk][alertName][i];
148+
149+
pageAlerts[alertRisk][alertName].forEach(alert => {
150150
if (alert.param.length > 0 && !reportedParameters.has(alert.param)) {
151151
reportedParameters.add(alert.param);
152152
utils.messageFrame(event.detail.tabId, 'management', {
@@ -156,7 +156,7 @@ const CommonAlerts = (function () {
156156
risk: alert.risk,
157157
param: alert.param});
158158
}
159-
}
159+
});
160160
}
161161
}
162162
}

src/main/zapHomeFiles/hud/tools/utils/alertUtils.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,14 @@ const alertUtils = (function () {
4040

4141
function flattenAlerts(alerts) {
4242
const json = {};
43-
for (let i = 0; i < alerts.length; i++) {
44-
const alert = alerts[i];
43+
44+
alerts.forEach(alert => {
4545
for (const key in alert) {
4646
if (Object.prototype.hasOwnProperty.call(alert, key)) {
4747
json[key] = alert[key];
4848
}
4949
}
50-
}
50+
});
5151

5252
return json;
5353
}

src/main/zapHomeFiles/hud/utils.js

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,8 @@ const utils = (function () {
195195
function setDefaultTools(leftTools, rightTools) {
196196
const promises = [];
197197

198-
for (let i = 0; i < leftTools.length; i++) {
199-
loadTool(leftTools[i])
198+
leftTools.forEach((leftTool, i) => {
199+
loadTool(leftTool)
200200
.then(tool => {
201201
if (!tool) {
202202
log(LOG_ERROR, 'utils.setDefaultTools', 'Failed to load tool.', tool.name);
@@ -210,10 +210,10 @@ const utils = (function () {
210210
return writeTool(tool);
211211
})
212212
.catch(errorHandler);
213-
}
213+
});
214214

215-
for (let i = 0; i < rightTools.length; i++) {
216-
loadTool(rightTools[i])
215+
rightTools.forEach((rightTool, i) => {
216+
loadTool(rightTool)
217217
.then(tool => {
218218
if (!tool) {
219219
log(LOG_ERROR, 'utils.setDefaultTools', 'Failed to load tool.', tool.name);
@@ -227,7 +227,7 @@ const utils = (function () {
227227
return writeTool(tool);
228228
})
229229
.catch(errorHandler);
230-
}
230+
});
231231

232232
return Promise.all(promises);
233233
}
@@ -430,8 +430,7 @@ const utils = (function () {
430430
function messageFrame(tabId, frameId, message) {
431431
return clients.matchAll({includeUncontrolled: true})
432432
.then(clients => {
433-
for (let i = 0; i < clients.length; i++) {
434-
const client = clients[i];
433+
clients.forEach(client => {
435434
const parameters = new URL(client.url).searchParams;
436435

437436
const tid = parameters.get('tabId');
@@ -440,7 +439,7 @@ const utils = (function () {
440439
if (tid === tabId && fid === frameId) {
441440
return client;
442441
}
443-
}
442+
});
444443

445444
throw new NoClientIdError('Could not find a ClientId for tabId: ' + tabId + ', frameId: ' + frameId);
446445
})
@@ -469,16 +468,15 @@ const utils = (function () {
469468
.then(clients => {
470469
const frameClients = [];
471470

472-
for (let i = 0; i < clients.length; i++) {
473-
const client = clients[i];
471+
clients.forEach(client => {
474472
const parameters = new URL(client.url).searchParams;
475473

476474
const fid = parameters.get('frameId');
477475

478476
if (fid === frameId) {
479477
frameClients.push(client);
480478
}
481-
}
479+
});
482480

483481
if (frameClients.length === 0) {
484482
log(LOG_DEBUG, 'utils.messageAllTabs', 'Could not find any clients for frameId: ' + frameId, message);
@@ -489,9 +487,7 @@ const utils = (function () {
489487
})
490488
.then(clients => {
491489
return new Promise(((resolve, reject) => {
492-
for (let i = 0; i < clients.length; i++) {
493-
const client = clients[i];
494-
490+
clients.forEach(client => {
495491
const channel = new MessageChannel();
496492
channel.port1.start();
497493
channel.port2.start();
@@ -505,7 +501,7 @@ const utils = (function () {
505501
});
506502

507503
client.postMessage(message, [channel.port2]);
508-
}
504+
});
509505
}));
510506
})
511507
.catch(errorHandler);
@@ -524,16 +520,15 @@ const utils = (function () {
524520
.then(clients => {
525521
const frameClients = [];
526522

527-
for (let i = 0; i < clients.length; i++) {
528-
const client = clients[i];
523+
clients.forEach(client => {
529524
const parameters = new URL(client.url).searchParams;
530525

531526
const fid = parameters.get('frameId');
532527

533528
if (fid === frameId) {
534529
frameClients.push(client);
535530
}
536-
}
531+
});
537532

538533
return frameClients;
539534
})

0 commit comments

Comments
 (0)