Skip to content

Commit a23cd65

Browse files
committed
Fix some lint warnings
Fix lint warnings for the following rules: - no-unused-vars - prefer-destructuring - unicorn/no-for-loop - unicorn/prefer-includes - unicorn/prefer-string-slice - unicorn/prefer-query-selector - no-negated-condition Signed-off-by: VitikaSoni <[email protected]>
1 parent c3a4e6f commit a23cd65

32 files changed

+229
-235
lines changed

package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
"no-unsanitized"
5656
],
5757
"rules": {
58-
"no-negated-condition": "warn",
58+
"no-negated-condition": "error",
5959
"no-unsanitized/method": [
6060
"error",
6161
{
@@ -76,13 +76,13 @@
7676
}
7777
}
7878
],
79-
"no-unused-vars": "warn",
80-
"prefer-destructuring": "warn",
81-
"unicorn/no-for-loop": "warn",
82-
"unicorn/prefer-includes": "warn",
83-
"unicorn/prefer-string-slice": "warn",
79+
"no-unused-vars": "error",
80+
"prefer-destructuring": "error",
81+
"unicorn/no-for-loop": "error",
82+
"unicorn/prefer-includes": "error",
83+
"unicorn/prefer-string-slice": "error",
8484
"unicorn/filename-case": "warn",
85-
"unicorn/prefer-query-selector": "warn"
85+
"unicorn/prefer-query-selector": "error"
8686
}
8787
},
8888
"repository": {

src/main/zapHomeFiles/hud/display.js

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Vue.component('modal', {
2727
close() {
2828
this.$emit('close');
2929
},
30-
afterLeave(element) {
30+
afterLeave(_element) {
3131
if (!app.keepShowing) {
3232
app.backStack = [];
3333
hideDisplayFrame();
@@ -402,13 +402,13 @@ Vue.component('http-message-modal', {
402402
let header = '';
403403
let body = '';
404404

405-
if (!this.response.isReadonly) {
406-
header = this.response.header;
407-
body = this.response.body;
408-
} else {
405+
if (this.response.isReadonly) {
409406
method = this.request.method;
410407
header = this.request.header;
411408
body = this.request.body;
409+
} else {
410+
header = this.response.header;
411+
body = this.response.body;
412412
}
413413

414414
return {method, header, body};
@@ -529,7 +529,7 @@ Vue.component('history-message-modal', {
529529
}, [channel.port2]);
530530
},
531531
ascanRequest() {
532-
const request = this.request;
532+
const {request} = this;
533533
this.$emit('close');
534534
navigator.serviceWorker.controller.postMessage(
535535
{
@@ -582,7 +582,7 @@ Vue.component('ws-message-modal', {
582582
},
583583
computed: {
584584
currentMessage() {
585-
const payload = this.payload;
585+
const {payload} = this;
586586
return {payload};
587587
}
588588
}
@@ -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({
@@ -755,7 +754,7 @@ Vue.component('site-tree-node', {
755754
if ((name.match(/\//g) || []).length > 2) {
756755
// If there are more than 2 slashes just show last url element
757756
// The first 2 slashes will be http(s)://...
758-
name = name.substring(name.lastIndexOf('/') + 1);
757+
name = name.slice(name.lastIndexOf('/') + 1);
759758
}
760759

761760
if (isLeaf) {
@@ -921,8 +920,8 @@ document.addEventListener('DOMContentLoaded', () => {
921920
});
922921

923922
navigator.serviceWorker.addEventListener('message', event => {
924-
const action = event.data.action;
925-
const config = event.data.config;
923+
const {data: {action}} = event;
924+
const {data: {config}} = event;
926925
const port = event.ports[0];
927926
let show;
928927

src/main/zapHomeFiles/hud/drawer.js

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// App is the main Vue object controlling everything
2+
23
let app;
34
const eventBus = new Vue();
45
let frameId = '';
@@ -55,7 +56,7 @@ Vue.component('history', {
5556
return re.test(message.url);
5657
}
5758

58-
return message.url.indexOf(self.filter) >= 0;
59+
return message.url.includes(self.filter);
5960
});
6061
}
6162
},
@@ -72,12 +73,12 @@ Vue.component('history', {
7273
},
7374
watch: {
7475
regexEnabled() {
75-
this.isRegExError = !this.regexEnabled ? false : this.isRegExError;
76+
this.isRegExError = this.regexEnabled ? this.isRegExError : false;
7677
},
7778
filteredMessages() {
7879
this.$nextTick(function () {
7980
const visibleMessages = document.querySelectorAll('#history-messages .message-tr');
80-
this.hiddenMessageCount = (!this.messages) ? 0 : this.messages.length - visibleMessages.length;
81+
this.hiddenMessageCount = this.messages ? this.messages.length - visibleMessages.length : 0;
8182
this.historyItemsFiltered();
8283
});
8384
}
@@ -104,7 +105,7 @@ Vue.component('history', {
104105
if (this.messages.length > 0) {
105106
const lastMessage = this.messages[this.messages.length - 1];
106107
const lastid = 'message-tr-' + lastMessage.id;
107-
const lastIdElement = document.getElementById(lastid);
108+
const lastIdElement = document.querySelector('#' + lastid);
108109

109110
if (lastIdElement) {
110111
lastIdElement.scrollIntoView({block: 'end', behavior: 'smooth'});
@@ -169,7 +170,7 @@ Vue.component('websockets', {
169170
return re.test(message.messageSummary);
170171
}
171172

172-
return message.messageSummary.indexOf(self.filter) >= 0;
173+
return message.messageSummary.includes(self.filter);
173174
});
174175
}
175176
},
@@ -186,12 +187,12 @@ Vue.component('websockets', {
186187
},
187188
watch: {
188189
regexEnabled() {
189-
this.isRegExError = !this.regexEnabled ? false : this.isRegExError;
190+
this.isRegExError = this.regexEnabled ? this.isRegExError : false;
190191
},
191192
filteredMessages() {
192193
this.$nextTick(function () {
193194
const visibleMessages = document.querySelectorAll('#websockets-messages .message-tr');
194-
this.hiddenMessageCount = (!this.messages) ? 0 : this.messages.length - visibleMessages.length;
195+
this.hiddenMessageCount = this.messages ? this.messages.length - visibleMessages.length : 0;
195196
this.websocketsItemsFiltered();
196197
});
197198
}
@@ -315,10 +316,10 @@ Vue.component('tabs', {
315316
})
316317
.catch(utils.errorHandler);
317318

318-
eventBus.$on('showTabs', data => {
319+
eventBus.$on('showTabs', _data => {
319320
this.tabsVisible = true;
320321
});
321-
eventBus.$on('hideTabs', data => {
322+
eventBus.$on('hideTabs', _data => {
322323
this.tabsVisible = false;
323324
if (this.isOpen) {
324325
this.closeDrawer();
@@ -431,7 +432,7 @@ Vue.component('drawer-button-showhide', {
431432
showHud() {
432433
this.isHudVisible = true;
433434
localforage.setItem('settings.isHudVisible', true)
434-
.then(function (value) {
435+
.then(function (_value) {
435436
this.icon = utils.getZapImagePath('radar.png');
436437
parent.postMessage({tabId, frameId, action: 'showHudPanels'}, context.url);
437438
eventBus.$emit('showTabs', {});
@@ -441,7 +442,7 @@ Vue.component('drawer-button-showhide', {
441442
hideHud() {
442443
this.isHudVisible = false;
443444
localforage.setItem('settings.isHudVisible', false)
444-
.then(function (value) {
445+
.then(function (_value) {
445446
this.icon = utils.getZapImagePath('radar-grey.png');
446447
parent.postMessage({tabId, frameId, action: 'hideHudPanels'}, context.url);
447448
eventBus.$emit('hideTabs', {});
@@ -477,6 +478,7 @@ document.addEventListener('DOMContentLoaded', () => {
477478
tabId = parameters.get('tabId');
478479

479480
/* Vue app */
481+
// eslint-disable-next-line no-unused-vars
480482
app = new Vue({
481483
i18n: I18n.i18n,
482484
el: '#app',
@@ -485,7 +487,7 @@ document.addEventListener('DOMContentLoaded', () => {
485487
});
486488

487489
navigator.serviceWorker.addEventListener('message', event => {
488-
const action = event.data.action;
490+
const {data: {action}} = event;
489491
const port = event.ports[0];
490492

491493
switch (action) {

src/main/zapHomeFiles/hud/management.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ const ZAP_SHARED_SECRET = '<<ZAP_SHARED_SECRET>>';
1515

1616
let app;
1717
let tabId = '';
18-
let frameId = '';
1918
const urlParameter = utils.getParameter(document.location.href, 'url');
2019
const context = {
2120
url: urlParameter,
@@ -56,7 +55,6 @@ function showTutorial() {
5655
document.addEventListener('DOMContentLoaded', () => {
5756
const parameters = new URL(document.location).searchParams;
5857

59-
frameId = parameters.get('frameId');
6058
tabId = parameters.get('tabId');
6159

6260
app = new Vue({

src/main/zapHomeFiles/hud/panel.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ document.addEventListener('DOMContentLoaded', () => {
212212
window.name = panelKey;
213213

214214
// Initialize vue app
215+
// eslint-disable-next-line no-unused-vars
215216
app = new Vue({
216217
i18n: I18n.i18n,
217218
el: '#app',

src/main/zapHomeFiles/hud/serviceworker.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ function initWebSockets() {
9797
self.dispatchEvent(ev);
9898
} else if ('id' in jevent && 'response' in jevent) {
9999
const pFunctions = webSocketCallbacks[jevent.id];
100-
const response = jevent.response;
100+
const {response} = jevent;
101101
if ('code' in response && 'message' in response) {
102102
// These always indicate a failure
103103
const error = new Error(I18n.t('error_with_message', [response.message]));
@@ -234,6 +234,7 @@ self.addEventListener('error', utils.errorHandler);
234234
self.addEventListener('hud.log', logHandler);
235235
self.addEventListener('hud.backup', backupHandler);
236236

237+
// eslint-disable-next-line no-unused-vars
237238
function registerForZapEvents(publisher) {
238239
apiCall('event', 'register', publisher);
239240
}

0 commit comments

Comments
 (0)