[gjs/esm-local-imports] Resolve ESLint issues.



commit 9d4ebff11dcd4acc569f2ddf9024dd129bbc2a4c
Author: Evan Welsh <noreply evanwelsh com>
Date:   Mon Jun 15 11:49:01 2020 -0500

    Resolve ESLint issues.

 examples/dbus-client.js               |  6 ++--
 examples/dbus-service.js              |  6 ++--
 gjs/internal/module.js                | 53 ++++++++++++++++++-----------------
 gjs/internal/module/loaders/file.js   |  4 ++-
 installed-tests/esm/.eslintrc.yml     |  5 ++++
 installed-tests/esm/default-import.js |  2 +-
 installed-tests/esm/named-import.js   |  2 +-
 modules/esm/.eslintrc.yml             |  1 +
 modules/esm/gi.js                     | 10 +++----
 9 files changed, 49 insertions(+), 40 deletions(-)
---
diff --git a/examples/dbus-client.js b/examples/dbus-client.js
index 7cedf69c..00d3ec5a 100644
--- a/examples/dbus-client.js
+++ b/examples/dbus-client.js
@@ -46,7 +46,7 @@ function onNameAppeared(connection, name, _owner) {
         proxy = new TestProxy(
             Gio.DBus.session,
             'org.gnome.gjs.Test',
-            '/org/gnome/gjs/Test'
+            '/org/gnome/gjs/Test',
         );
     } catch (e) {
         logError(e);
@@ -123,7 +123,7 @@ let busWatchId = Gio.bus_watch_name(
     'org.gnome.gjs.Test',
     Gio.BusNameWatcherFlags.NONE,
     onNameAppeared,
-    onNameVanished
+    onNameVanished,
 );
 
 // Start an event loop
@@ -162,6 +162,6 @@ new TestProxy(
     // Optional Gio.Cancellable object. Pass `null` if you need to pass flags.
     null,
     // Optional flags passed to the Gio.DBusProxy constructor
-    Gio.DBusProxyFlags.NONE
+    Gio.DBusProxyFlags.NONE,
 );
 
diff --git a/examples/dbus-service.js b/examples/dbus-service.js
index 493ebe54..5e2bbb4e 100644
--- a/examples/dbus-service.js
+++ b/examples/dbus-service.js
@@ -51,7 +51,7 @@ class Service {
             // Emitting property changes over DBus
             this.dbus.emit_property_changed(
                 'ReadWriteProperty',
-                new GLib.Variant('b', value)
+                new GLib.Variant('b', value),
             );
         }
     }
@@ -71,7 +71,7 @@ class Service {
     emitTestSignal() {
         this.dbus.emit_signal(
             'TestSignal',
-            new GLib.Variant('(sb)', ['string', false])
+            new GLib.Variant('(sb)', ['string', false]),
         );
     }
 }
@@ -118,7 +118,7 @@ let ownerId = Gio.bus_own_name(
     Gio.BusNameOwnerFlags.NONE,
     onBusAcquired,
     onNameAcquired,
-    onNameLost
+    onNameLost,
 );
 
 
diff --git a/gjs/internal/module.js b/gjs/internal/module.js
index 3953cd99..287c5594 100644
--- a/gjs/internal/module.js
+++ b/gjs/internal/module.js
@@ -22,9 +22,9 @@
 
 /* global debug, Soup, ImportError */
 
-if (typeof ImportError !== 'function') {
+if (typeof ImportError !== 'function')
     throw new Error('ImportError is not defined in module loader.');
-}
+
 
 // NOTE: Gio, GLib, and GObject have no overrides.
 
@@ -33,7 +33,7 @@ function isRelativePath(id) {
     return id.startsWith('./') || id.startsWith('../');
 }
 
-const allowedRelatives = ["file", "resource"];
+const allowedRelatives = ['file', 'resource'];
 
 const relativeResolvers = new Map();
 const loaders = new Map();
@@ -45,7 +45,7 @@ function registerScheme(...schemes) {
 
     const schemeBuilder = {
         relativeResolver(handler) {
-            forEach((scheme) => {
+            forEach(scheme => {
                 allowedRelatives.push(scheme);
                 relativeResolvers.set(scheme, handler);
             });
@@ -58,7 +58,7 @@ function registerScheme(...schemes) {
             });
 
             return schemeBuilder;
-        }
+        },
     };
 
     return Object.freeze(schemeBuilder);
@@ -69,9 +69,9 @@ globalThis.registerScheme = registerScheme;
 function parseURI(uri) {
     const parsed = Soup.URI.new(uri);
 
-    if (!parsed) {
+    if (!parsed)
         return null;
-    }
+
 
     return {
         raw: uri,
@@ -81,14 +81,14 @@ function parseURI(uri) {
         host: parsed.host,
         port: parsed.port,
         path: parsed.path,
-        fragment: parsed.fragment
+        fragment: parsed.fragment,
     };
 
 }
 
-/** 
+/**
  * @type {Set<string>}
- * 
+ *
  * The set of "module" URIs (the module search path)
  */
 const moduleURIs = new Set();
@@ -102,7 +102,8 @@ registerModuleURI('resource:///org/gnome/gjs/modules/esm/');
 registerModuleURI('resource:///org/gnome/gjs/modules/core/');
 
 /**
- * @param {string} specifier
+ * @param {string} specifier the module specifier
+ * @returns {string[]} a list of potential internal URIs for the module
  */
 function buildInternalURIs(specifier) {
     const builtURIs = [];
@@ -115,14 +116,14 @@ function buildInternalURIs(specifier) {
         builtURIs.push(builtURI);
     }
 
-    return builtURIs
+    return builtURIs;
 }
 
 function resolveRelativePath(moduleURI, relativePath) {
     // If a module has a path, we'll have stored it in the host field
-    if (!moduleURI) {
+    if (!moduleURI)
         throw new ImportError('Cannot import from relative path when module path is unknown.');
-    }
+
 
     debug(`moduleURI: ${moduleURI}`);
 
@@ -137,7 +138,7 @@ function resolveRelativePath(moduleURI, relativePath) {
         } else {
             throw new ImportError(
                 `Relative imports can only occur from the following URI schemes: ${
-                Array.from(relativeResolvers.keys()).map(s => `${s}://`).join(', ')
+                    Array.from(relativeResolvers.keys()).map(s => `${s}://`).join(', ')
                 }`);
         }
     } else {
@@ -151,11 +152,11 @@ function loadURI(uri) {
     if (uri.scheme) {
         const loader = loaders.get(uri.scheme);
 
-        if (loader) {
+        if (loader)
             return loader(uri);
-        } else {
+        else
             throw new ImportError(`No resolver found for URI: ${uri.raw || uri}`);
-        }
+
     } else {
         throw new ImportError(`Unable to load module, module has invalid URI: ${uri.raw || uri}`);
     }
@@ -181,14 +182,14 @@ function resolveSpecifier(specifier, moduleURI = null) {
         }
     }
 
-    if (parsedURI) {
+    if (parsedURI)
         output = loadURI(parsedURI);
-    }
+
 
     if (!output)
         return null;
 
-    return { output, uri };
+    return {output, uri};
 }
 
 function resolveModule(specifier, moduleURI) {
@@ -215,7 +216,7 @@ function resolveModule(specifier, moduleURI) {
     const resolved = resolveSpecifier(specifier, moduleURI);
 
     if (resolved) {
-        const { output, uri } = resolved;
+        const {output, uri} = resolved;
 
         debug(`Full path found: ${uri}`);
 
@@ -236,8 +237,8 @@ function resolveModule(specifier, moduleURI) {
 
     // 2) Resolve internal imports.
 
-    const uri = buildInternalURIs(specifier).find((uri) => {
-        let file = Gio.File.new_for_uri(uri);
+    const uri = buildInternalURIs(specifier).find(u => {
+        let file = Gio.File.new_for_uri(u);
 
         return file && file.query_exists(null);
     });
@@ -257,9 +258,9 @@ setModuleResolveHook((referencingInfo, specifier) => {
     debug('Starting module import...');
     const uri = getModuleURI(referencingInfo);
 
-    if (uri) {
+    if (uri)
         debug(`Found base URI: ${uri}`);
-    }
+
 
     return resolveModule(specifier, uri);
 });
diff --git a/gjs/internal/module/loaders/file.js b/gjs/internal/module/loaders/file.js
index fc0f4f2f..9b0fdb50 100644
--- a/gjs/internal/module/loaders/file.js
+++ b/gjs/internal/module/loaders/file.js
@@ -1,3 +1,5 @@
+/* global registerScheme */
+
 function fromBytes(bytes) {
     return ByteUtils.toString(bytes, 'utf-8');
 }
@@ -11,7 +13,7 @@ function loadFileSync(output, full_path) {
     }
 }
 
-registerScheme("file", "resource")
+registerScheme('file', 'resource')
     .relativeResolver((moduleURI, relativePath) => {
         let module_file = Gio.File.new_for_uri(moduleURI.raw);
         let module_parent_file = module_file.get_parent();
diff --git a/installed-tests/esm/.eslintrc.yml b/installed-tests/esm/.eslintrc.yml
new file mode 100644
index 00000000..0b3bc0a2
--- /dev/null
+++ b/installed-tests/esm/.eslintrc.yml
@@ -0,0 +1,5 @@
+---
+extends: '../../.eslintrc.yml'
+parserOptions:
+  sourceType: 'module'
+  ecmaVersion: 2020
diff --git a/installed-tests/esm/default-import.js b/installed-tests/esm/default-import.js
index d070eda2..f572ab57 100644
--- a/installed-tests/esm/default-import.js
+++ b/installed-tests/esm/default-import.js
@@ -1,3 +1,3 @@
 import $ from './exports.js';
 
-print($);
\ No newline at end of file
+print($);
diff --git a/installed-tests/esm/named-import.js b/installed-tests/esm/named-import.js
index 0c4ef4e0..73e3ea0f 100644
--- a/installed-tests/esm/named-import.js
+++ b/installed-tests/esm/named-import.js
@@ -1,3 +1,3 @@
-import { NamedExport } from './exports.js';
+import {NamedExport} from './exports.js';
 
 print(NamedExport);
diff --git a/modules/esm/.eslintrc.yml b/modules/esm/.eslintrc.yml
index 610e5085..0b3bc0a2 100644
--- a/modules/esm/.eslintrc.yml
+++ b/modules/esm/.eslintrc.yml
@@ -1,4 +1,5 @@
 ---
 extends: '../../.eslintrc.yml'
 parserOptions:
+  sourceType: 'module'
   ecmaVersion: 2020
diff --git a/modules/esm/gi.js b/modules/esm/gi.js
index 274d3827..54afa4e4 100644
--- a/modules/esm/gi.js
+++ b/modules/esm/gi.js
@@ -2,13 +2,13 @@ const gi = import.meta.require('gi');
 
 const Gi = {
     require(name, version = null) {
-        if (version !== null) {
+        if (version !== null)
             gi.versions[name] = version;
-        }
 
         return gi[name];
-    }
-}
+    },
+};
+
 Object.freeze(Gi);
 
-export default Gi;
\ No newline at end of file
+export default Gi;


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