[epiphany] Add eslint file for JavaScript code



commit 8da86e65f51bbe607be1bc947a69a1fe7ec9e4a1
Author: Sonny Piers <sonny fastmail net>
Date:   Thu Jan 21 14:12:43 2021 +0100

    Add eslint file for JavaScript code

 .eslintrc                                           | 18 ++++++++++++++++++
 embed/web-process-extension/resources/js/ephy.js    | 21 +++++++++++----------
 .../web-process-extension/resources/js/overview.js  |  4 +++-
 .../resources/js/webextensions.js                   | 20 +++++++++++---------
 4 files changed, 43 insertions(+), 20 deletions(-)
---
diff --git a/.eslintrc b/.eslintrc
new file mode 100644
index 000000000..1400c0323
--- /dev/null
+++ b/.eslintrc
@@ -0,0 +1,18 @@
+{
+    "extends": [
+        "eslint:recommended"
+    ],
+    "rules": {
+        "semi": ["error"],
+        "no-unused-vars": ["error", { "args": "none" }],
+        "quotes": ["error", "single"],
+        "strict": ["error", "global"],
+        "eqeqeq": ["error"],
+        "no-var": ["error"]
+    },
+    "env": {
+        "browser": true,
+        "es2021": true
+    },
+    "ignorePatterns": ["/third-party"]
+}
\ No newline at end of file
diff --git a/embed/web-process-extension/resources/js/ephy.js 
b/embed/web-process-extension/resources/js/ephy.js
index f49a0fb57..1fb73d041 100644
--- a/embed/web-process-extension/resources/js/ephy.js
+++ b/embed/web-process-extension/resources/js/ephy.js
@@ -1,5 +1,6 @@
 'use strict';
 
+// eslint-disable-next-line no-var
 var Ephy = {};
 
 Ephy.getAppleMobileWebAppCapable = function()
@@ -15,7 +16,7 @@ Ephy.getAppleMobileWebAppCapable = function()
     }
 
     return false;
-}
+};
 
 Ephy.getWebAppTitle = function()
 {
@@ -52,7 +53,7 @@ Ephy.getWebAppTitle = function()
 
     // set_default_application_title will fallback to the formatted hostname
     return null;
-}
+};
 
 Ephy.getWebAppIcon = function(baseURL)
 {
@@ -129,7 +130,7 @@ Ephy.getWebAppIcon = function(baseURL)
 
     // Last ditch effort: just fallback to the default favicon location.
     return { 'url' : new URL('/favicon.ico', baseURL).href, 'color' : null };
-}
+};
 
 Ephy.PreFillUserMenu = class PreFillUserMenu
 {
@@ -287,7 +288,7 @@ Ephy.PreFillUserMenu = class PreFillUserMenu
         this._passwordElement.value = '';
         this._manager.preFill(this._formAuth);
     }
-}
+};
 
 Ephy.formControlsAssociated = function(pageID, frameID, forms, serializer)
 {
@@ -301,7 +302,7 @@ Ephy.formControlsAssociated = function(pageID, frameID, forms, serializer)
         formManager.preFillForms();
         Ephy.formManagers.push(formManager);
     }
-}
+};
 
 Ephy.handleFormSubmission = function(pageID, frameID, form)
 {
@@ -321,7 +322,7 @@ Ephy.handleFormSubmission = function(pageID, frameID, form)
     }
 
     formManager.handleFormSubmission();
-}
+};
 
 Ephy.hasModifiedForms = function()
 {
@@ -349,7 +350,7 @@ Ephy.hasModifiedForms = function()
             }
         }
     }
-}
+};
 
 Ephy.PasswordManager = class PasswordManager
 {
@@ -433,7 +434,7 @@ Ephy.PasswordManager = class PasswordManager
             this._pendingPromises.push({promiseID, resolver});
         });
     }
-}
+};
 
 Ephy.FormManager = class FormManager
 {
@@ -616,7 +617,7 @@ Ephy.FormManager = class FormManager
                 let parts = url.hostname.split('.');
                 if (parts.length > 0) {
                     let tld = parts[parts.length - 1];
-                    isFormActionInsecure = tld !== "127.0.0.1" && tld !== "::1" && tld !== "localhost";
+                    isFormActionInsecure = tld !== '127.0.0.1' && tld !== '::1' && tld !== 'localhost';
                 }
             }
         }
@@ -762,4 +763,4 @@ Ephy.FormManager = class FormManager
 
         return formAuth;
     }
-}
+};
diff --git a/embed/web-process-extension/resources/js/overview.js 
b/embed/web-process-extension/resources/js/overview.js
index 43d612346..c60b03244 100644
--- a/embed/web-process-extension/resources/js/overview.js
+++ b/embed/web-process-extension/resources/js/overview.js
@@ -1,5 +1,7 @@
 'use strict';
 
+/* global Ephy */
+
 Ephy.Overview = class Overview
 {
     constructor(model)
@@ -143,7 +145,7 @@ Ephy.Overview = class Overview
                 let anchor = document.createElement('a');
                 anchor.classList.add('overview-item');
                 let closeButton = document.createElement('div');
-                closeButton.title = Ephy._("Remove from overview");
+                closeButton.title = Ephy._('Remove from overview');
                 closeButton.onclick = (event) => {
                     this._removeItem(anchor);
                     event.preventDefault();
diff --git a/embed/web-process-extension/resources/js/webextensions.js 
b/embed/web-process-extension/resources/js/webextensions.js
index 1ed0ff801..b59f3898f 100644
--- a/embed/web-process-extension/resources/js/webextensions.js
+++ b/embed/web-process-extension/resources/js/webextensions.js
@@ -1,5 +1,7 @@
 'use strict';
 
+/* exported pageActionOnClicked, browserActionClicked, browserActionClicked, tabsOnUpdated, 
runtimeSendMessage, runtimeOnConnect */
+
 let promises = [];
 let last_promise = 0;
 
@@ -18,32 +20,32 @@ let ephy_message = function (fn, args, cb) {
         last_promise = promises.push({resolve: resolve, reject: reject});
     });
     return promise;
-}
+};
 
 let pageActionOnClicked = function(x) {
   for (let listener of page_listeners)
     listener.callback(x);
-}
+};
 
 let browserActionClicked = function(x) {
   for (let listener of browser_listeners)
     listener.callback(x);
-}
+};
 
 let tabsOnUpdated = function(x) {
   for (let listener of tabs_listeners)
     listener.callback(x);
-}
+};
 
 let runtimeSendMessage = function(x) {
   for (let listener of runtime_onmessage_listeners)
     listener.callback(x);
-}
+};
 
 let runtimeOnConnect = function(x) {
   for (let listener of runtime_onconnect_listeners)
     listener.callback(x);
-}
+};
 
 // Browser async API
 window.browser.alarms = {
@@ -52,7 +54,7 @@ window.browser.alarms = {
 
 window.browser.windows = {
     onRemoved: {
-      addListener: function (cb) { windows_onremoved_listeners.push({callback: cb}) }
+      addListener: function (cb) { windows_onremoved_listeners.push({callback: cb}); }
     }
 };
 
@@ -64,7 +66,7 @@ window.browser.tabs = {
     insertCSS: function (args, cb) { return ephy_message ('tabs.insertCSS', args, cb); },
     removeCSS: function (args, cb) { return ephy_message ('tabs.removeCSS', args, cb); },
     onUpdated: {
-      addListener: function (cb) { tabs_listeners.push({callback: cb}) }
+      addListener: function (cb) { tabs_listeners.push({callback: cb}); }
     }
 };
 
@@ -73,7 +75,7 @@ window.browser.notifications = {
 };
 
 window.browser.runtime = {
-    getManifest: function (args, cb) { return "[]"; },
+    getManifest: function (args, cb) { return '[]'; },
     getBrowserInfo: function (args, cb) { return ephy_message ('runtime.getBrowserInfo', args, cb); },
     onInstalled: {
       addListener: function (cb) { runtime_listeners.push({callback: cb}); }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]