[gjs: 16/43] CI: Add func-style to eslint rules



commit a7954ac92eece34ace702b397f3e981933e7e346
Author: Philip Chimento <philip chimento gmail com>
Date:   Sat Aug 3 20:50:04 2019 -0700

    CI: Add func-style to eslint rules
    
    function foo() { ... } is shorter than var foo = function() { ... };,
    and there's also less chance to have a discrepancy between the names of
    the function and the variable holding it.

 .eslintrc.yml                   |  4 ++++
 examples/http-server.js         | 48 ++++++++++++++++++++++++++++-------------
 installed-tests/js/testGDBus.js |  4 ++--
 modules/_bootstrap/debugger.js  |  4 ++--
 modules/_legacy.js              |  4 ++--
 modules/gettext.js              |  5 ++---
 6 files changed, 45 insertions(+), 24 deletions(-)
---
diff --git a/.eslintrc.yml b/.eslintrc.yml
index 97408a95..384a71a3 100644
--- a/.eslintrc.yml
+++ b/.eslintrc.yml
@@ -37,6 +37,10 @@ rules:
   eol-last: error
   eqeqeq: error
   func-call-spacing: error
+  func-style:
+    - error
+    - declaration
+    - allowArrowFunctions: true
   indent:
     - error
     - 4
diff --git a/examples/http-server.js b/examples/http-server.js
index cbc6a75a..0e8aede2 100644
--- a/examples/http-server.js
+++ b/examples/http-server.js
@@ -2,23 +2,41 @@
 
 const Soup = imports.gi.Soup;
 
-function main() {
-    let handler = function(server, msg, path, query, client) {
-        msg.status_code = 200;
-        msg.response_headers.set_content_type('text/html', {});
-        msg.response_body.append(`<html><body>Greetings, visitor from ${client.get_host()}<br>What is your 
name?<form action="/hello"><input name="myname"></form></body></html>\n`);
-    };
-    let helloHandler = function(server, msg, path, query) {
-        if (!query) {
-            msg.set_redirect(302, '/');
-            return;
-        }
+function handler(server, msg, path, query, client) {
+    msg.status_code = 200;
+    msg.response_headers.set_content_type('text/html', {});
+    msg.response_body.append(`
+        <html>
+        <body>
+            Greetings, visitor from ${client.get_host()}<br>
+            What is your name?
+            <form action="/hello">
+                <input name="myname">
+            </form>
+        </body>
+        </html>
+    `);
+}
 
-        msg.status_code = 200;
-        msg.response_headers.set_content_type('text/html', {charset: 'UTF-8'});
-        msg.response_body.append(`<html><body>Hello, ${query.myname}! ☺<br><a href="/">Go 
back</a></body></html>`);
-    };
+function helloHandler(server, msg, path, query) {
+    if (!query) {
+        msg.set_redirect(302, '/');
+        return;
+    }
 
+    msg.status_code = 200;
+    msg.response_headers.set_content_type('text/html', {charset: 'UTF-8'});
+    msg.response_body.append(`
+        <html>
+        <body>
+            Hello, ${query.myname}! ☺<br>
+            <a href="/">Go back</a>
+        </body>
+        </html>
+    `);
+}
+
+function main() {
     let server = new Soup.Server({port: 1080});
     server.add_handler('/', handler);
     server.add_handler('/hello', helloHandler);
diff --git a/installed-tests/js/testGDBus.js b/installed-tests/js/testGDBus.js
index 85c21634..805435fa 100644
--- a/installed-tests/js/testGDBus.js
+++ b/installed-tests/js/testGDBus.js
@@ -261,7 +261,7 @@ describe('Exported DBus object', function () {
     var proxy;
     let loop;
 
-    let waitForServerProperty = function (property, value = undefined, timeout = 500) {
+    function waitForServerProperty(property, value = undefined, timeout = 500) {
         let waitId = GLib.timeout_add(GLib.PRIORITY_DEFAULT, timeout, () => {
             waitId = 0;
             throw new Error(`Timeout waiting for property ${property} expired`);
@@ -276,7 +276,7 @@ describe('Exported DBus object', function () {
 
         expect(waitId).not.toBe(0);
         return test[property];
-    };
+    }
 
     beforeAll(function () {
         loop = new GLib.MainLoop(null, false);
diff --git a/modules/_bootstrap/debugger.js b/modules/_bootstrap/debugger.js
index 758df59e..12e265f8 100644
--- a/modules/_bootstrap/debugger.js
+++ b/modules/_bootstrap/debugger.js
@@ -677,9 +677,9 @@ for (var i = 0; i < commandArray.length; i++) {
 function _printCommandsList() {
     print('Available commands:');
 
-    var printcmd = function (cmd) {
+    function printcmd(cmd) {
         print(`  ${cmd.aliases.join(', ')} -- ${cmd.summary}`);
-    };
+    }
 
     var cmdGroups = _groupCommands();
 
diff --git a/modules/_legacy.js b/modules/_legacy.js
index 43416b73..6d758a0a 100644
--- a/modules/_legacy.js
+++ b/modules/_legacy.js
@@ -105,14 +105,14 @@ Class.prototype._construct = function(params) {
     if (!parent)
         parent = _Base;
 
-    let newClass = function() {
+    function newClass() {
         if (params.Abstract && new.target.name === name)
             throw new TypeError(`Cannot instantiate abstract class ${name}`);
 
         this.__caller__ = null;
 
         return this._construct(...arguments);
-    };
+    }
 
     // Since it's not possible to create a constructor with
     // a custom [[Prototype]], we have to do this to make
diff --git a/modules/gettext.js b/modules/gettext.js
index fd87d9a1..d1b92678 100644
--- a/modules/gettext.js
+++ b/modules/gettext.js
@@ -84,7 +84,7 @@ function dpgettext(domain, context, msgid) {
  * @returns: an object with gettext bindings
  * @type: function
  */
-var domain = function(domainName) {
+function domain(domainName) {
     return {
         gettext: function(msgid) {
             return GLib.dgettext(domainName, msgid);
@@ -98,5 +98,4 @@ var domain = function(domainName) {
             return GLib.dpgettext2(domainName, context, msgid);
         },
     };
-};
-
+}


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