Skip to content

Commit dd0f67f

Browse files
committed
Fix linter errors in lib
1 parent 8d56da4 commit dd0f67f

7 files changed

+41
-37
lines changed

lib/chrome_api_stubs.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -49,19 +49,19 @@ if (shouldInstallStubs) {
4949
storage: {
5050
local: {
5151
async get() {
52-
return {};
52+
return await {};
5353
},
5454
async set() {},
5555
},
5656
sync: {
5757
async get() {
58-
return {};
58+
return await {};
5959
},
6060
async set() {},
6161
},
6262
session: {
6363
async get() {
64-
return {};
64+
return await {};
6565
},
6666
async set() {},
6767
},

lib/dom_utils.js

+21-18
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
var DomUtils = {
1+
const DomUtils = {
22
//
33
// Runs :callback if the DOM has loaded, otherwise runs it on load
44
//
@@ -14,12 +14,12 @@ var DomUtils = {
1414
let callbacks = [];
1515
if (!isReady) {
1616
let onDOMContentLoaded;
17-
window.addEventListener(
17+
globalThis.addEventListener(
1818
"DOMContentLoaded",
1919
onDOMContentLoaded = forTrusted(function () {
20-
window.removeEventListener("DOMContentLoaded", onDOMContentLoaded, true);
20+
globalThis.removeEventListener("DOMContentLoaded", onDOMContentLoaded, true);
2121
isReady = true;
22-
for (let callback of callbacks) callback();
22+
for (const callback of callbacks) callback();
2323
callbacks = null;
2424
}),
2525
true,
@@ -40,15 +40,15 @@ var DomUtils = {
4040
let callbacks = [];
4141
if (!isComplete) {
4242
let onLoad;
43-
window.addEventListener(
43+
globalThis.addEventListener(
4444
"load",
4545
onLoad = forTrusted(function (event) {
4646
// The target is ensured to be on document. See
4747
// https://w3c.github.io/uievents/#event-type-load
4848
if (event.target !== document) return;
49-
window.removeEventListener("load", onLoad, true);
49+
globalThis.removeEventListener("load", onLoad, true);
5050
isComplete = true;
51-
for (let callback of callbacks) callback();
51+
for (const callback of callbacks) callback();
5252
callbacks = null;
5353
}),
5454
true,
@@ -105,7 +105,7 @@ var DomUtils = {
105105
// Test whether the current frame is the top/main frame.
106106
//
107107
isTopFrame() {
108-
return window.top === window.self;
108+
return globalThis.top === globalThis.self;
109109
},
110110

111111
//
@@ -115,7 +115,7 @@ var DomUtils = {
115115
//
116116
makeXPath(elementArray) {
117117
const xpath = [];
118-
for (let element of elementArray) {
118+
for (const element of elementArray) {
119119
xpath.push(".//" + element, ".//xhtml:" + element);
120120
}
121121
return xpath.join(" | ");
@@ -155,7 +155,7 @@ var DomUtils = {
155155

156156
// Inline elements with font-size: 0px; will declare a height of zero, even if a child with
157157
// non-zero font-size contains text.
158-
var isInlineZeroHeight = function () {
158+
let isInlineZeroHeight = function () {
159159
const elementComputedStyle = window.getComputedStyle(element, null);
160160
const isInlineZeroFontSize =
161161
(0 === elementComputedStyle.getPropertyValue("display").indexOf("inline")) &&
@@ -168,10 +168,9 @@ var DomUtils = {
168168
for (clientRect of clientRects) {
169169
// If the link has zero dimensions, it may be wrapping visible but floated elements. Check for
170170
// this.
171-
var computedStyle;
171+
let computedStyle;
172172
if (((clientRect.width === 0) || (clientRect.height === 0)) && testChildren) {
173-
for (let child of Array.from(element.children)) {
174-
var needle;
173+
for (const child of Array.from(element.children)) {
175174
computedStyle = window.getComputedStyle(child, null);
176175
// Ignore child elements which are not floated and not absolutely positioned for parent
177176
// elements with zero width/height, as long as the case described at isInlineZeroHeight
@@ -237,7 +236,7 @@ var DomUtils = {
237236
getClientRectsForAreas(imgClientRect, areas) {
238237
const rects = [];
239238
for (const area of areas) {
240-
var x1, x2, y1, y2;
239+
let x1, x2, y1, y2;
241240
const coords = area.coords.split(",").map((coord) => parseInt(coord, 10));
242241
const shape = area.shape.toLowerCase();
243242
if (["rect", "rectangle"].includes(shape)) { // "rectangle" is an IE non-standard.
@@ -302,7 +301,7 @@ var DomUtils = {
302301

303302
// Embedded elements like Flash and quicktime players can obtain focus.
304303
isEmbed(element) {
305-
let nodeName = element.nodeName != null ? element.nodeName.toLowerCase() : null;
304+
const nodeName = element.nodeName != null ? element.nodeName.toLowerCase() : null;
306305
return ["embed", "object"].includes(nodeName);
307306
},
308307

@@ -361,7 +360,9 @@ var DomUtils = {
361360
if ((element.selectionStart === 0) && (element.selectionEnd === 0)) {
362361
return element.setSelectionRange(element.value.length, element.value.length);
363362
}
364-
} catch (error) {}
363+
} catch {
364+
// Swallow
365+
}
365366
}
366367
}
367368
},
@@ -370,7 +371,7 @@ var DomUtils = {
370371
if (modifiers == null) modifiers = {};
371372
const eventSequence = ["mouseover", "mousedown", "mouseup", "click"];
372373
const result = [];
373-
for (let event of eventSequence) {
374+
for (const event of eventSequence) {
374375
// In firefox prior to 96, simulating a click on an element would be blocked under some
375376
// conditions (#2602, #2960).
376377
// In 96+, extensions can trigger native click listeners on elements (#3985).
@@ -643,7 +644,9 @@ var DomUtils = {
643644
text = text.slice(11).trim();
644645
try {
645646
text = decodeURIComponent(text);
646-
} catch (error) {}
647+
} catch {
648+
// Swallow
649+
}
647650
}
648651
const script = document.createElement("script");
649652
script.textContent = text;

lib/find_mode_history.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const FindModeHistory = {
2424
}
2525
}
2626

27-
chrome.storage.onChanged.addListener((changes, area) => {
27+
chrome.storage.onChanged.addListener((changes, _area) => {
2828
if (changes[this.key]) {
2929
this.rawQueryList = changes[this.key].newValue;
3030
}

lib/handler_stack.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class HandlerStack {
5151
const {
5252
eventNumber,
5353
} = this;
54-
for (let handler of this.stack.slice().reverse()) {
54+
for (const handler of this.stack.slice().reverse()) {
5555
// A handler might have been removed (handler.id == null), so check; or there might just be no
5656
// handler for this type of event.
5757
if (!(handler != null ? handler.id : undefined) || !handler[type]) {
@@ -159,7 +159,7 @@ class HandlerStack {
159159

160160
show() {
161161
console.log(`${this.eventNumber}:`);
162-
for (let handler of this.stack.slice().reverse()) {
162+
for (const handler of this.stack.slice().reverse()) {
163163
console.log(" ", handler._name);
164164
}
165165
}

lib/rect.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Commands for manipulating rects.
2-
var Rect = {
2+
const Rect = {
33
// Create a rect given the top left and bottom right corners.
44
create(x1, y1, x2, y2) {
55
return {
@@ -94,7 +94,7 @@ var Rect = {
9494
},
9595

9696
equals(rect1, rect2) {
97-
for (let property of ["top", "bottom", "left", "right", "width", "height"]) {
97+
for (const property of ["top", "bottom", "left", "right", "width", "height"]) {
9898
if (rect1[property] !== rect2[property]) return false;
9999
}
100100
return true;

lib/settings.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ const Settings = {
8686
}
8787
},
8888

89-
async chromeStorageOnChanged(changes, area) {
89+
async chromeStorageOnChanged(_changes, area) {
9090
// We store data with keys [settings-v1, ...] into the local storage. Only broadcast an event if
9191
// the object stored with the settings key has changed.
9292
// We only store settings in the sync area, so storage.sync changes must be settings changes.

lib/utils.js

+11-10
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ const Utils = {
101101
return uri.split(/(?=%)/).map(function (uriComponent) {
102102
try {
103103
return decodeURIComponent(uriComponent);
104-
} catch (error) {
104+
} catch {
105105
return uriComponent;
106106
}
107107
}).join("");
@@ -209,15 +209,15 @@ const Utils = {
209209
// We require the URL to start with the search URL.
210210
if (!url.startsWith(searchUrl)) return null;
211211
// We require any remaining terms in the search URL to also be present in the URL.
212-
for (let suffix of suffixTerms) {
212+
for (const suffix of suffixTerms) {
213213
if (!(0 <= url.indexOf(suffix))) return null;
214214
}
215215
// We use try/catch because decodeURIComponent can throw an exception.
216216
try {
217217
return url.slice(searchUrl.length).split(queryTerminator)[0].split("+").map(
218218
decodeURIComponent,
219219
).join(" ");
220-
} catch (error) {
220+
} catch {
221221
return null;
222222
}
223223
};
@@ -280,7 +280,7 @@ const Utils = {
280280
pick(object, propertyList) {
281281
const result = {};
282282
for (const property of propertyList) {
283-
if (object.hasOwnProperty(property)) {
283+
if (Object.prototype.hasOwnProperty.call(object, property)) {
284284
result[property] = object[property];
285285
}
286286
}
@@ -294,7 +294,7 @@ const Utils = {
294294

295295
// Does string match any of these regexps?
296296
matchesAnyRegexp(regexps, string) {
297-
for (let re of regexps) {
297+
for (const re of regexps) {
298298
if (re.test(string)) return true;
299299
}
300300
return false;
@@ -311,7 +311,7 @@ const Utils = {
311311
},
312312

313313
promiseWithTimeout(promise, ms) {
314-
const timeoutPromise = new Promise((resolve, reject) => {
314+
const timeoutPromise = new Promise((_resolve, reject) => {
315315
setTimeout(() => reject(new Error(`Promise timed out after ${ms}ms.`)), ms);
316316
});
317317
return Promise.race([promise, timeoutPromise]);
@@ -320,8 +320,9 @@ const Utils = {
320320
// Make an idempotent function.
321321
makeIdempotent(func) {
322322
return function (...args) {
323-
let previousFunc, ref;
324-
const result = ([previousFunc, func] = Array.from(ref = [func, null]), ref)[0];
323+
// TODO(philc): Clean up this transpiled code.
324+
let _, ref;
325+
const result = ([_, func] = Array.from(ref = [func, null]), ref)[0];
325326
if (result) {
326327
return result(...Array.from(args || []));
327328
}
@@ -331,7 +332,7 @@ const Utils = {
331332
monitorChromeSessionStorage(key, setter) {
332333
return chrome.storage.session.get(key, (obj) => {
333334
if (obj[key] != null) setter(obj[key]);
334-
return chrome.storage.onChanged.addListener((changes, area) => {
335+
return chrome.storage.onChanged.addListener((changes, _area) => {
335336
if (changes[key] && (changes[key].newValue !== undefined)) {
336337
return setter(changes[key].newValue);
337338
}
@@ -481,7 +482,7 @@ class AsyncDataFetcher {
481482
Utils.nextTick(() => {
482483
fetch((data) => {
483484
this.data = data;
484-
for (let callback of this.queue) callback(this.data);
485+
for (const callback of this.queue) callback(this.data);
485486
return this.queue = null;
486487
});
487488
});

0 commit comments

Comments
 (0)