[gjs: 25/43] CI: Add no-shadow to eslint rules



commit 4bb57aec88a73f7cd2f4cb3f8010cb5fa653c0d7
Author: Philip Chimento <philip chimento gmail com>
Date:   Sun Aug 4 17:46:14 2019 -0700

    CI: Add no-shadow to eslint rules
    
    We have this compiler warning enabled for the C++ code, so we may as
    well have it for the JS code too. This one actually did catch a sort-of
    bug.
    
    Like some other rules where the fix isn't straightforward, we disable it
    for tweener.js.

 .eslintrc.yml                                    |  1 +
 examples/gio-cat.js                              |  4 ++--
 installed-tests/js/testEverythingEncapsulated.js |  2 +-
 installed-tests/js/testGDBus.js                  |  2 --
 installed-tests/js/testLegacyClass.js            |  2 +-
 installed-tests/js/testLegacyGObject.js          |  2 +-
 modules/_bootstrap/debugger.js                   |  4 ++--
 modules/_legacy.js                               |  8 ++++----
 modules/format.js                                |  8 +++-----
 modules/gettext.js                               | 24 ++++++++++++------------
 modules/overrides/GObject.js                     | 10 +++++-----
 modules/overrides/Gio.js                         | 12 ++++++------
 modules/package.js                               | 20 ++++++++++----------
 modules/tweener/tweener.js                       |  2 +-
 14 files changed, 49 insertions(+), 52 deletions(-)
---
diff --git a/.eslintrc.yml b/.eslintrc.yml
index 5236bd0a..2e20540a 100644
--- a/.eslintrc.yml
+++ b/.eslintrc.yml
@@ -94,6 +94,7 @@ rules:
       property: mainloop
       message: Use GLib main loops and timeouts
   no-return-assign: error
+  no-shadow: error
   no-tabs: error
   no-unused-vars:
     - error
diff --git a/examples/gio-cat.js b/examples/gio-cat.js
index 640df637..b6178947 100644
--- a/examples/gio-cat.js
+++ b/examples/gio-cat.js
@@ -7,10 +7,10 @@ let loop = GLib.MainLoop.new(null, false);
 
 function cat(filename) {
     let f = Gio.file_new_for_path(filename);
-    f.load_contents_async(null, function(f, res) {
+    f.load_contents_async(null, function(obj, res) {
         let contents;
         try {
-            contents = f.load_contents_finish(res)[1];
+            contents = obj.load_contents_finish(res)[1];
         } catch (e) {
             logError(e);
             loop.quit();
diff --git a/installed-tests/js/testEverythingEncapsulated.js 
b/installed-tests/js/testEverythingEncapsulated.js
index a0bee48f..2e6a993c 100644
--- a/installed-tests/js/testEverythingEncapsulated.js
+++ b/installed-tests/js/testEverythingEncapsulated.js
@@ -79,7 +79,7 @@ describe('Introspected structs', function () {
     });
 
     it('containing fixed array', function () {
-        let struct = new Regress.TestStructFixedArray();
+        struct = new Regress.TestStructFixedArray();
         struct.frob();
         expect(struct.just_int).toEqual(7);
         expect(struct.array).toEqual([42, 43, 44, 45, 46, 47, 48, 49, 50, 51]);
diff --git a/installed-tests/js/testGDBus.js b/installed-tests/js/testGDBus.js
index 127f4217..e94a9908 100644
--- a/installed-tests/js/testGDBus.js
+++ b/installed-tests/js/testGDBus.js
@@ -503,8 +503,6 @@ describe('Exported DBus object', function () {
     });
 
     it('can send and receive bytes from a remote method', function () {
-        let loop = GLib.MainLoop.new(null, false);
-
         let someBytes = [0, 63, 234];
         someBytes.forEach(b => {
             proxy.byteEchoRemote(b, ([result], excp) => {
diff --git a/installed-tests/js/testLegacyClass.js b/installed-tests/js/testLegacyClass.js
index 493b34c3..a2245972 100644
--- a/installed-tests/js/testLegacyClass.js
+++ b/installed-tests/js/testLegacyClass.js
@@ -708,7 +708,7 @@ describe('ES6 class inheriting from Lang.Class', function () {
         spyOn(Legacy.prototype, 'chainUpToMe');
         spyOn(Legacy.prototype, 'overrideMe');
 
-        Shiny = class Shiny extends Legacy {
+        Shiny = class extends Legacy {
             constructor(someval) {
                 super(someval);
             }
diff --git a/installed-tests/js/testLegacyGObject.js b/installed-tests/js/testLegacyGObject.js
index f7baae3b..ac637bbf 100644
--- a/installed-tests/js/testLegacyGObject.js
+++ b/installed-tests/js/testLegacyGObject.js
@@ -870,7 +870,7 @@ describe('ES6 GObject class inheriting from GObject.Class', function () {
     });
 
     it("passes arguments to the parent class's constructor", function () {
-        let instance = new Shiny(42);
+        instance = new Shiny(42);
         expect(instance.constructorCalledWith).toEqual(42);
     });
 
diff --git a/modules/_bootstrap/debugger.js b/modules/_bootstrap/debugger.js
index 7f197dcf..24ced579 100644
--- a/modules/_bootstrap/debugger.js
+++ b/modules/_bootstrap/debugger.js
@@ -567,7 +567,7 @@ function findBreakpointOffsets(line, currentScript) {
 
     return scripts
         .map(script => ({script, offsets: script.getLineOffsets(line)}))
-        .filter(({offsets}) => offsets.length !== 0);
+        .filter(({offsets: o}) => o.length !== 0);
 }
 
 class BreakpointHandler {
@@ -666,7 +666,7 @@ var commandArray = [
 // clang-format on
 var currentCmd = null;
 for (var i = 0; i < commandArray.length; i++) {
-    var cmd = commandArray[i];
+    let cmd = commandArray[i];
     if (typeof cmd === 'string')
         commands[cmd] = currentCmd;
     else
diff --git a/modules/_legacy.js b/modules/_legacy.js
index b6fb0c4b..f7d59c87 100644
--- a/modules/_legacy.js
+++ b/modules/_legacy.js
@@ -189,7 +189,7 @@ Class.prototype._copyPropertyDescriptor = function(params, propertyObj, key) {
 };
 
 Class.prototype._init = function(params) {
-    let name = params.Name;
+    let className = params.Name;
 
     let propertyObj = { };
 
@@ -219,7 +219,7 @@ Class.prototype._init = function(params) {
             writable: false,
             configurable: false,
             enumerable: false,
-            value: name,
+            value: className,
         },
         'parent': {
             writable: false,
@@ -367,7 +367,7 @@ Interface.prototype.toString = function () {
 };
 
 Interface.prototype._init = function (params) {
-    let name = params.Name;
+    let ifaceName = params.Name;
 
     let propertyObj = {};
     Object.getOwnPropertyNames(params)
@@ -398,7 +398,7 @@ Interface.prototype._init = function (params) {
             writable: false,
             configurable: false,
             enumerable: false,
-            value: name,
+            value: ifaceName,
         },
         '__requires__': {
             writable: false,
diff --git a/modules/format.js b/modules/format.js
index 27c7b3e9..f57713d6 100644
--- a/modules/format.js
+++ b/modules/format.js
@@ -4,10 +4,10 @@
 
 const GjsPrivate = imports.gi.GjsPrivate;
 
-function vprintf(str, args) {
+function vprintf(string, args) {
     let i = 0;
     let usePos = false;
-    return str.replace(/%(?:([1-9][0-9]*)\$)?(I+)?([0-9]+)?(?:\.([0-9]+))?(.)/g, function (str, posGroup, 
flagsGroup, widthGroup, precisionGroup, genericGroup) {
+    return string.replace(/%(?:([1-9][0-9]*)\$)?(I+)?([0-9]+)?(?:\.([0-9]+))?(.)/g, function (str, posGroup, 
flagsGroup, widthGroup, precisionGroup, genericGroup) {
         if (precisionGroup !== '' && precisionGroup !== undefined &&
             genericGroup !== 'f')
             throw new Error("Precision can only be specified for 'f'");
@@ -27,9 +27,7 @@ function vprintf(str, args) {
         let width = parseInt(widthGroup, 10) || 0;
 
         function fillWidth(s, c, w) {
-            let fill = '';
-            for (let i = 0; i < w; i++)
-                fill += c;
+            let fill = c.repeat(w);
             return fill.substr(s.length) + s;
         }
 
diff --git a/modules/gettext.js b/modules/gettext.js
index d1b92678..13b0f49e 100644
--- a/modules/gettext.js
+++ b/modules/gettext.js
@@ -44,36 +44,36 @@ function setlocale(category, locale) {
     return GjsPrivate.setlocale(category, locale);
 }
 
-function textdomain(domain) {
-    return GjsPrivate.textdomain(domain);
+function textdomain(dom) {
+    return GjsPrivate.textdomain(dom);
 }
-function bindtextdomain(domain, location) {
-    return GjsPrivate.bindtextdomain(domain, location);
+function bindtextdomain(dom, location) {
+    return GjsPrivate.bindtextdomain(dom, location);
 }
 
 function gettext(msgid) {
     return GLib.dgettext(null, msgid);
 }
-function dgettext(domain, msgid) {
-    return GLib.dgettext(domain, msgid);
+function dgettext(dom, msgid) {
+    return GLib.dgettext(dom, msgid);
 }
-function dcgettext(domain, msgid, category) {
-    return GLib.dcgettext(domain, msgid, category);
+function dcgettext(dom, msgid, category) {
+    return GLib.dcgettext(dom, msgid, category);
 }
 
 function ngettext(msgid1, msgid2, n) {
     return GLib.dngettext(null, msgid1, msgid2, n);
 }
-function dngettext(domain, msgid1, msgid2, n) {
-    return GLib.dngettext(domain, msgid1, msgid2, n);
+function dngettext(dom, msgid1, msgid2, n) {
+    return GLib.dngettext(dom, msgid1, msgid2, n);
 }
 // FIXME: missing dcngettext ?
 
 function pgettext(context, msgid) {
     return GLib.dpgettext2(null, context, msgid);
 }
-function dpgettext(domain, context, msgid) {
-    return GLib.dpgettext2(domain, context, msgid);
+function dpgettext(dom, context, msgid) {
+    return GLib.dpgettext2(dom, context, msgid);
 }
 
 /**
diff --git a/modules/overrides/GObject.js b/modules/overrides/GObject.js
index edb461e4..1cd6d1ca 100644
--- a/modules/overrides/GObject.js
+++ b/modules/overrides/GObject.js
@@ -95,9 +95,9 @@ function registerClass(klass) {
 
 // Some common functions between GObject.Class and GObject.Interface
 
-function _createSignals(gtype, signals) {
-    for (let signalName in signals) {
-        let obj = signals[signalName];
+function _createSignals(gtype, sigs) {
+    for (let signalName in sigs) {
+        let obj = sigs[signalName];
         let flags = obj.flags !== undefined ? obj.flags : GObject.SignalFlags.RUN_FIRST;
         let accumulator = obj.accumulator !== undefined ? obj.accumulator : GObject.AccumulatorType.NONE;
         let rtype = obj.return_type !== undefined ? obj.return_type : GObject.TYPE_NONE;
@@ -438,12 +438,12 @@ function _init() {
         let gtypename = _createGTypeName(klass);
         let gobjectInterfaces = klass.hasOwnProperty(requires) ?
             klass[requires] : [];
-        let properties = _propertiesAsArray(klass);
+        let props = _propertiesAsArray(klass);
         let gobjectSignals = klass.hasOwnProperty(signals) ?
             klass[signals] : [];
 
         let newInterface = Gi.register_interface(gtypename, gobjectInterfaces,
-            properties);
+            props);
 
         _createSignals(newInterface.$gtype, gobjectSignals);
 
diff --git a/modules/overrides/Gio.js b/modules/overrides/Gio.js
index 1d9ed1e3..21d42285 100644
--- a/modules/overrides/Gio.js
+++ b/modules/overrides/Gio.js
@@ -401,14 +401,14 @@ function _wrapJSObject(interfaceInfo, jsObj) {
     info.cache_build();
 
     var impl = new GjsPrivate.DBusImplementation({g_interface_info: info});
-    impl.connect('handle-method-call', function(impl, methodName, parameters, invocation) {
-        return _handleMethodCall.call(jsObj, info, impl, methodName, parameters, invocation);
+    impl.connect('handle-method-call', function(self, methodName, parameters, invocation) {
+        return _handleMethodCall.call(jsObj, info, self, methodName, parameters, invocation);
     });
-    impl.connect('handle-property-get', function(impl, propertyName) {
-        return _handlePropertyGet.call(jsObj, info, impl, propertyName);
+    impl.connect('handle-property-get', function(self, propertyName) {
+        return _handlePropertyGet.call(jsObj, info, self, propertyName);
     });
-    impl.connect('handle-property-set', function(impl, propertyName, value) {
-        return _handlePropertySet.call(jsObj, info, impl, propertyName, value);
+    impl.connect('handle-property-set', function(self, propertyName, value) {
+        return _handlePropertySet.call(jsObj, info, self, propertyName, value);
     });
 
     return impl;
diff --git a/modules/package.js b/modules/package.js
index 0010b789..e40a2461 100644
--- a/modules/package.js
+++ b/modules/package.js
@@ -70,8 +70,8 @@ function _runningFromMesonSource() {
            GLib.getenv('MESON_SOURCE_ROOT');
 }
 
-function _makeNamePath(name) {
-    return `/${name.replace(/\./g, '/')}`;
+function _makeNamePath(n) {
+    return `/${n.replace(/\./g, '/')}`;
 }
 
 /**
@@ -246,8 +246,8 @@ function require(libs) {
  * As checkSymbol(), but exit with an error if the
  * dependency cannot be satisfied.
  */
-function requireSymbol(lib, version, symbol) {
-    if (!checkSymbol(lib, version, symbol)) {
+function requireSymbol(lib, ver, symbol) {
+    if (!checkSymbol(lib, ver, symbol)) {
         if (symbol)
             printerr(`Unsatisfied dependency: No ${symbol} in ${lib}`);
         else
@@ -273,11 +273,11 @@ function requireSymbol(lib, version, symbol) {
  *
  * Returns: %true if @lib can be imported and provides @symbol, %false otherwise
  */
-function checkSymbol(lib, version, symbol) {
+function checkSymbol(lib, ver, symbol) {
     let Lib = null;
 
-    if (version)
-        imports.gi.versions[lib] = version;
+    if (ver)
+        imports.gi.versions[lib] = ver;
 
     try {
         Lib = imports.gi[lib];
@@ -329,11 +329,11 @@ function initFormat() {
     String.prototype.format = format.format;
 }
 
-function initSubmodule(name) {
+function initSubmodule(moduleName) {
     if (_runningFromMesonSource() || _runningFromSource()) {
-        // Running from source tree, add './name' to search paths
+        // Running from source tree, add './moduleName' to search paths
 
-        let submoduledir = GLib.build_filenamev([_submoduledir, name]);
+        let submoduledir = GLib.build_filenamev([_submoduledir, moduleName]);
         let libpath;
         if (_runningFromMesonSource())
             libpath = submoduledir;
diff --git a/modules/tweener/tweener.js b/modules/tweener/tweener.js
index c0981be3..a92ff1ce 100644
--- a/modules/tweener/tweener.js
+++ b/modules/tweener/tweener.js
@@ -1,5 +1,5 @@
 /* -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil; -*- */
-/* eslint-disable block-scoped-var, eqeqeq */
+/* eslint-disable block-scoped-var, eqeqeq, no-shadow */
 
 /* Copyright 2008  litl, LLC. */
 /**


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