[epiphany] Enable eslint prefer-const rule
- From: Michael Catanzaro <mcatanzaro src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [epiphany] Enable eslint prefer-const rule
- Date: Thu, 21 Jan 2021 17:19:48 +0000 (UTC)
commit 89d7d2f2517e1c717d759183aac4349c423c1c6b
Author: Sonny Piers <sonny fastmail net>
Date: Thu Jan 21 14:13:40 2021 +0100
Enable eslint prefer-const rule
.eslintrc | 3 +-
embed/web-process-extension/resources/js/ephy.js | 64 +++++++++++-----------
.../web-process-extension/resources/js/overview.js | 58 ++++++++++----------
.../resources/js/webextensions.js | 44 +++++++--------
4 files changed, 85 insertions(+), 84 deletions(-)
---
diff --git a/.eslintrc b/.eslintrc
index 1400c0323..0a12a9671 100644
--- a/.eslintrc
+++ b/.eslintrc
@@ -8,7 +8,8 @@
"quotes": ["error", "single"],
"strict": ["error", "global"],
"eqeqeq": ["error"],
- "no-var": ["error"]
+ "no-var": ["error"],
+ "prefer-const": ["error"]
},
"env": {
"browser": true,
diff --git a/embed/web-process-extension/resources/js/ephy.js
b/embed/web-process-extension/resources/js/ephy.js
index 1fb73d041..5cc68a4be 100644
--- a/embed/web-process-extension/resources/js/ephy.js
+++ b/embed/web-process-extension/resources/js/ephy.js
@@ -5,10 +5,10 @@ var Ephy = {};
Ephy.getAppleMobileWebAppCapable = function()
{
- let metas = document.getElementsByTagName('meta');
+ const metas = document.getElementsByTagName('meta');
for (let i = 0; i < metas.length; i++) {
- let meta = metas[i];
+ const meta = metas[i];
//
https://developer.apple.com/library/archive/documentation/AppleApplications/Reference/SafariHTMLRef/Articles/MetaTags.html
if (meta.name === 'apple-mobile-web-app-capable' && meta.getAttribute('content') === 'yes')
@@ -181,7 +181,7 @@ Ephy.PreFillUserMenu = class PreFillUserMenu
if (event.key !== 'ArrowDown' && event.key !== 'ArrowUp')
return;
- let container = document.getElementById('ephy-user-choices-container');
+ const container = document.getElementById('ephy-user-choices-container');
if (!container) {
this._showMenu(!this._wasEdited);
return;
@@ -207,10 +207,10 @@ Ephy.PreFillUserMenu = class PreFillUserMenu
_showMenu(showAll)
{
- let mainDiv = document.createElement('div');
+ const mainDiv = document.createElement('div');
mainDiv.id = 'ephy-user-choices-container';
- let elementRect = this._userElement.getBoundingClientRect();
+ const elementRect = this._userElement.getBoundingClientRect();
// 2147483647 is the maximum value browsers will take for z-index.
// See http://stackoverflow.com/questions/8565821/css-max-z-index-value
@@ -227,18 +227,18 @@ Ephy.PreFillUserMenu = class PreFillUserMenu
mainDiv.style.left = elementRect.left + document.body.scrollLeft + 'px';
mainDiv.style.top = elementRect.top + elementRect.height + document.body.scrollTop + 'px';
- let ul = document.createElement('ul');
+ const ul = document.createElement('ul');
ul.style.cssText = 'margin: 0; padding: 0;';
ul.tabindex = -1;
mainDiv.appendChild(ul);
this._selected = null;
for (let i = 0; i < this._users.length; i++) {
- let user = this._users[i];
+ const user = this._users[i];
if (!showAll && !user.startsWith(this._userElement.value))
continue;
- let li = document.createElement('li');
+ const li = document.createElement('li');
li.style.cssText = 'list-style-type: none ! important;' +
'background-image: none ! important;' +
'padding: 3px 6px ! important;' +
@@ -251,7 +251,7 @@ Ephy.PreFillUserMenu = class PreFillUserMenu
if (user === this._userElement.value)
this._selected = li;
- let anchor = document.createElement('a');
+ const anchor = document.createElement('a');
anchor.style.cssText = 'font-weight: normal ! important;' +
'font-family: sans ! important;' +
'text-decoration: none ! important;' +
@@ -277,7 +277,7 @@ Ephy.PreFillUserMenu = class PreFillUserMenu
_removeMenu()
{
- let menu = document.getElementById('ephy-user-choices-container');
+ const menu = document.getElementById('ephy-user-choices-container');
if (menu)
menu.parentNode.removeChild(menu);
}
@@ -297,7 +297,7 @@ Ephy.formControlsAssociated = function(pageID, frameID, forms, serializer)
for (let i = 0; i < forms.length; i++) {
if (!(forms[i] instanceof HTMLFormElement))
continue;
- let formManager = new Ephy.FormManager(pageID, frameID, forms[i]);
+ const formManager = new Ephy.FormManager(pageID, frameID, forms[i]);
formManager.handlePasswordForms(serializer);
formManager.preFillForms();
Ephy.formManagers.push(formManager);
@@ -309,7 +309,7 @@ Ephy.handleFormSubmission = function(pageID, frameID, form)
// FIXME: Find out: is it really possible to have multiple frames with same window object???
let formManager = null;
for (let i = 0; i < Ephy.formManagers.length; i++) {
- let manager = Ephy.formManagers[i];
+ const manager = Ephy.formManagers[i];
if (manager.frameID() === frameID && manager.form() === form) {
formManager = manager;
break;
@@ -327,10 +327,10 @@ Ephy.handleFormSubmission = function(pageID, frameID, form)
Ephy.hasModifiedForms = function()
{
for (let i = 0; i < document.forms.length; i++) {
- let form = document.forms[i];
+ const form = document.forms[i];
let modifiedInputElement = false;
for (let j = 0; j < form.elements.length; j++) {
- let element = form.elements[j];
+ const element = form.elements[j];
if (!Ephy.isEdited(element))
continue;
@@ -364,7 +364,7 @@ Ephy.PasswordManager = class PasswordManager
_takePendingPromise(id)
{
- let element = this._pendingPromises.find(element => element.promiseID === id);
+ const element = this._pendingPromises.find(element => element.promiseID === id);
if (element)
this._pendingPromises = this._pendingPromises.filter(element => element.promiseID !== id);
return element;
@@ -374,7 +374,7 @@ Ephy.PasswordManager = class PasswordManager
{
Ephy.log(`Received password query response for username=${username}`);
- let element = this._takePendingPromise(id);
+ const element = this._takePendingPromise(id);
if (element) {
if (password)
element.resolver({username, password});
@@ -388,7 +388,7 @@ Ephy.PasswordManager = class PasswordManager
Ephy.log(`Querying passwords for origin=${origin}, targetOrigin=${targetOrigin},
username=${username}, usernameField=${usernameField}, passwordField=${passwordField}`);
return new Promise((resolver, reject) => {
- let promiseID = this._promiseCounter++;
+ const promiseID = this._promiseCounter++;
Ephy.queryPassword(origin, targetOrigin, username, usernameField, passwordField, promiseID,
this._pageID, this._frameID);
this._pendingPromises.push({promiseID, resolver});
});
@@ -419,7 +419,7 @@ Ephy.PasswordManager = class PasswordManager
{
Ephy.log(`Received query usernames response with users=${users}`);
- let element = this._takePendingPromise(id);
+ const element = this._takePendingPromise(id);
if (element)
element.resolver(users);
}
@@ -429,7 +429,7 @@ Ephy.PasswordManager = class PasswordManager
Ephy.log(`Requesting usernames for origin=${origin}`);
return new Promise((resolver, reject) => {
- let promiseID = this._promiseCounter++;
+ const promiseID = this._promiseCounter++;
Ephy.queryUsernames(origin, promiseID, this._pageID, this._frameID);
this._pendingPromises.push({promiseID, resolver});
});
@@ -480,7 +480,7 @@ Ephy.FormManager = class FormManager
if (!Ephy.shouldRememberPasswords())
return;
- let formAuth = this._generateFormAuth(true);
+ const formAuth = this._generateFormAuth(true);
if (!formAuth) {
Ephy.log('No pre-fillable/hookable form found');
return;
@@ -539,7 +539,7 @@ Ephy.FormManager = class FormManager
if (!Ephy.shouldRememberPasswords())
return;
- let formAuth = this._generateFormAuth(false);
+ const formAuth = this._generateFormAuth(false);
if (!formAuth || !formAuth.password)
return;
@@ -598,7 +598,7 @@ Ephy.FormManager = class FormManager
_containsPasswordElement()
{
for (let i = 0; i < this._form.elements.length; i++) {
- let element = this._form.elements[i];
+ const element = this._form.elements[i];
if (element instanceof HTMLInputElement) {
if (element.type === 'password' || element.type === 'adminpw')
return true;
@@ -611,12 +611,12 @@ Ephy.FormManager = class FormManager
{
let isFormActionInsecure = false;
if (this._form.action) {
- let url = new URL(this._form.action);
+ const url = new URL(this._form.action);
if (url.protocol === 'http:') {
// We trust localhost to be local since glib!616.
- let parts = url.hostname.split('.');
+ const parts = url.hostname.split('.');
if (parts.length > 0) {
- let tld = parts[parts.length - 1];
+ const tld = parts[parts.length - 1];
isFormActionInsecure = tld !== '127.0.0.1' && tld !== '::1' && tld !== 'localhost';
}
}
@@ -626,9 +626,9 @@ Ephy.FormManager = class FormManager
_findPasswordFields()
{
- let passwordFields = [];
+ const passwordFields = [];
for (let i = 0; i < this._form.elements.length; i++) {
- let element = this._form.elements[i];
+ const element = this._form.elements[i];
if (element instanceof HTMLInputElement && element.type === 'password') {
// We only want to process forms with 1-3 fields. A common
// case is to have a "change password" form with 3 fields:
@@ -645,16 +645,16 @@ Ephy.FormManager = class FormManager
_findFormAuthElements(forAutofill)
{
- let passwordNodes = this._findPasswordFields();
+ const passwordNodes = this._findPasswordFields();
if (!passwordNodes || !passwordNodes.length)
return null;
// Start at the first found password field and search backwards.
// Assume the first eligible field to contain username.
let usernameNode = null;
- let firstPasswordNodeData = passwordNodes[0];
+ const firstPasswordNodeData = passwordNodes[0];
for (let i = firstPasswordNodeData.index; i >= 0; i--) {
- let element = this._form.elements[i];
+ const element = this._form.elements[i];
if (element instanceof HTMLInputElement) {
if (element.type === 'text' || element.type === 'email' ||
element.type === 'tel' || element.type === 'url' ||
@@ -672,7 +672,7 @@ Ephy.FormManager = class FormManager
let passwordNodeIndex = 0;
if (!forAutofill && passwordNodes.length !== 1) {
// Get values of all password fields.
- let passwords = [];
+ const passwords = [];
for (let i = passwordNodes.length - 1; i >= 0; i--)
passwords[i] = passwordNodes[i].element.value;
@@ -725,7 +725,7 @@ Ephy.FormManager = class FormManager
}
_generateFormAuth(forAutofill) {
- let formAuth = this._findFormAuthElements(forAutofill);
+ const formAuth = this._findFormAuthElements(forAutofill);
if (formAuth === null)
return null;
diff --git a/embed/web-process-extension/resources/js/overview.js
b/embed/web-process-extension/resources/js/overview.js
index c60b03244..a15f69803 100644
--- a/embed/web-process-extension/resources/js/overview.js
+++ b/embed/web-process-extension/resources/js/overview.js
@@ -28,15 +28,15 @@ Ephy.Overview = class Overview
_initialize()
{
- let anchors = document.getElementsByTagName('a');
+ const anchors = document.getElementsByTagName('a');
for (let i = 0; i < anchors.length; i++) {
- let anchor = anchors[i];
+ const anchor = anchors[i];
if (anchor.className !== 'overview-item')
continue;
- let item = new Ephy.Overview.Item(anchor);
+ const item = new Ephy.Overview.Item(anchor);
- let closeButton = anchor.getElementsByClassName('overview-close-button')[0];
+ const closeButton = anchor.getElementsByClassName('overview-close-button')[0];
closeButton.onclick = (event) => {
this._removeItem(anchor);
event.preventDefault();
@@ -44,7 +44,7 @@ Ephy.Overview = class Overview
// URLs and titles are always sent from the UI process, but thumbnails
// aren't, so update the model with the thumbnail if there's one.
- let thumbnailPath = item.thumbnailPath();
+ const thumbnailPath = item.thumbnailPath();
if (thumbnailPath)
this._model.setThumbnail(item.url(), thumbnailPath);
else
@@ -53,15 +53,15 @@ Ephy.Overview = class Overview
this._items.push(item);
}
- let items = this._model.urls;
+ const items = this._model.urls;
if (items.length > this._items.length)
this._onURLsChanged(items);
- for (let thumbnailChange of this._pendingThumbnailChanges)
+ for (const thumbnailChange of this._pendingThumbnailChanges)
this._onThumbnailChanged(thumbnailChange.url, thumbnailChange.path);
this._pendingThumbnailChanges = [];
- for (let titleChange of this._pendingTitleChanges)
+ for (const titleChange of this._pendingTitleChanges)
this._onTitleChanged(titleChange.url, titleChange.title);
this._pendingTitleChanges = [];
this._addPlaceholders();
@@ -72,7 +72,7 @@ Ephy.Overview = class Overview
if (event.which !== 127)
return;
- let item = document.activeElement;
+ const item = document.activeElement;
if (item.classList.contains('overview-item')) {
this._removeItem(item);
event.preventDefault();
@@ -80,16 +80,16 @@ Ephy.Overview = class Overview
}
_addPlaceholders() {
- let parentNode = document.getElementById('most-visited-grid');
- let anchors = document.getElementsByTagName('a');
+ const parentNode = document.getElementById('most-visited-grid');
+ const anchors = document.getElementsByTagName('a');
for (let i = anchors.length; i < 9; i++) {
- let anchor = document.createElement('a');
+ const anchor = document.createElement('a');
anchor.className = 'overview-item';
- let span_thumbnail = document.createElement('span');
+ const span_thumbnail = document.createElement('span');
span_thumbnail.className = 'overview-thumbnail';
anchor.appendChild(span_thumbnail);
- let span_title = document.createElement('span');
+ const span_title = document.createElement('span');
span_title.className = 'overview-title';
anchor.appendChild(span_title);
@@ -98,9 +98,9 @@ Ephy.Overview = class Overview
}
_removePlaceholders() {
- let anchors = document.getElementsByTagName('a');
+ const anchors = document.getElementsByTagName('a');
- for (let anchor of anchors) {
+ for (const anchor of anchors) {
if (anchor.href === '')
document.removeChild(anchor);
}
@@ -125,8 +125,8 @@ Ephy.Overview = class Overview
_onURLsChanged(urls)
{
- let overview = document.getElementById('overview');
- let grid = document.getElementById('most-visited-grid');
+ const overview = document.getElementById('overview');
+ const grid = document.getElementById('most-visited-grid');
if (overview.classList.contains('overview-empty')) {
while (grid.lastChild)
grid.removeChild(grid.lastChild);
@@ -135,16 +135,16 @@ Ephy.Overview = class Overview
this._removePlaceholders();
for (let i = 0; i < urls.length; i++) {
- let url = urls[i];
+ const url = urls[i];
let item;
if (this._items[i]) {
item = this._items[i];
} else {
Ephy.log('create an item for the url ' + url.url);
- let anchor = document.createElement('a');
+ const anchor = document.createElement('a');
anchor.classList.add('overview-item');
- let closeButton = document.createElement('div');
+ const closeButton = document.createElement('div');
closeButton.title = Ephy._('Remove from overview');
closeButton.onclick = (event) => {
this._removeItem(anchor);
@@ -153,10 +153,10 @@ Ephy.Overview = class Overview
closeButton.innerHTML = '';
closeButton.classList.add('overview-close-button');
anchor.appendChild(closeButton);
- let thumbnailSpan = document.createElement('span');
+ const thumbnailSpan = document.createElement('span');
thumbnailSpan.classList.add('overview-thumbnail');
anchor.appendChild(thumbnailSpan);
- let titleSpan = document.createElement('span');
+ const titleSpan = document.createElement('span');
titleSpan.classList.add('overview-title');
anchor.appendChild(titleSpan);
document.getElementById('most-visited-grid').appendChild(anchor);
@@ -170,7 +170,7 @@ Ephy.Overview = class Overview
}
while (this._items.length > urls.length) {
- let item = this._items.pop();
+ const item = this._items.pop();
item.detachFromParent();
}
}
@@ -183,7 +183,7 @@ Ephy.Overview = class Overview
}
for (let i = 0; i < this._items.length; i++) {
- let item = this._items[i];
+ const item = this._items[i];
if (item.url() === url) {
item.setThumbnailPath(path);
return;
@@ -199,7 +199,7 @@ Ephy.Overview = class Overview
}
for (let i = 0; i < this._items.length; i++) {
- let item = this._items[i];
+ const item = this._items[i];
if (item.url() === url) {
item.setTitle(title);
return;
@@ -217,7 +217,7 @@ Ephy.Overview.Item = class OverviewItem
this._thumbnail = null;
for (let i = 0; i < this._item.childNodes.length; i++) {
- let child = this._item.childNodes[i];
+ const child = this._item.childNodes[i];
if (!(child instanceof Element))
continue;
@@ -253,11 +253,11 @@ Ephy.Overview.Item = class OverviewItem
thumbnailPath()
{
- let style = this._thumbnail.style;
+ const style = this._thumbnail.style;
if (style.isPropertyImplicit('background'))
return null;
- let background = style.getPropertyValue('background');
+ const background = style.getPropertyValue('background');
if (!background)
return null;
diff --git a/embed/web-process-extension/resources/js/webextensions.js
b/embed/web-process-extension/resources/js/webextensions.js
index b59f3898f..a9cdf481d 100644
--- a/embed/web-process-extension/resources/js/webextensions.js
+++ b/embed/web-process-extension/resources/js/webextensions.js
@@ -2,48 +2,48 @@
/* exported pageActionOnClicked, browserActionClicked, browserActionClicked, tabsOnUpdated,
runtimeSendMessage, runtimeOnConnect */
-let promises = [];
+const promises = [];
let last_promise = 0;
-let tabs_listeners = [];
-let page_listeners = [];
-let browser_listeners = [];
-let runtime_listeners = [];
-let runtime_onmessage_listeners = [];
-let runtime_onmessageexternal_listeners = [];
-let runtime_onconnect_listeners = [];
-let windows_onremoved_listeners = [];
-
-let ephy_message = function (fn, args, cb) {
- let promise = new Promise (function (resolve, reject) {
+const tabs_listeners = [];
+const page_listeners = [];
+const browser_listeners = [];
+const runtime_listeners = [];
+const runtime_onmessage_listeners = [];
+const runtime_onmessageexternal_listeners = [];
+const runtime_onconnect_listeners = [];
+const windows_onremoved_listeners = [];
+
+const ephy_message = function (fn, args, cb) {
+ const promise = new Promise (function (resolve, reject) {
window.webkit.messageHandlers.epiphany.postMessage ({fn: fn, args: args, promise: last_promise});
last_promise = promises.push({resolve: resolve, reject: reject});
});
return promise;
};
-let pageActionOnClicked = function(x) {
- for (let listener of page_listeners)
+const pageActionOnClicked = function(x) {
+ for (const listener of page_listeners)
listener.callback(x);
};
-let browserActionClicked = function(x) {
- for (let listener of browser_listeners)
+const browserActionClicked = function(x) {
+ for (const listener of browser_listeners)
listener.callback(x);
};
-let tabsOnUpdated = function(x) {
- for (let listener of tabs_listeners)
+const tabsOnUpdated = function(x) {
+ for (const listener of tabs_listeners)
listener.callback(x);
};
-let runtimeSendMessage = function(x) {
- for (let listener of runtime_onmessage_listeners)
+const runtimeSendMessage = function(x) {
+ for (const listener of runtime_onmessage_listeners)
listener.callback(x);
};
-let runtimeOnConnect = function(x) {
- for (let listener of runtime_onconnect_listeners)
+const runtimeOnConnect = function(x) {
+ for (const listener of runtime_onconnect_listeners)
listener.callback(x);
};
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]