[gjs: 6/43] js: Fix remaining eslint complaints



commit 49f42a5196bcf65ae10527a654666eb078bf6f08
Author: Philip Chimento <philip chimento gmail com>
Date:   Sat Aug 3 17:19:32 2019 -0700

    js: Fix remaining eslint complaints
    
    Some of these show that there were rules active that we didn't really
    care about, so we disable those rules; others were fixed.

 .eslintrc.yml                                      |  7 +++++++
 examples/gtk.js                                    | 14 +++++++-------
 installed-tests/js/modules/foobar.js               |  1 +
 installed-tests/js/testEverythingBasic.js          |  2 +-
 installed-tests/js/testGDBus.js                    |  2 +-
 installed-tests/js/testGObjectDestructionAccess.js |  4 ++--
 installed-tests/js/testTweener.js                  |  2 +-
 modules/_bootstrap/debugger.js                     |  2 +-
 modules/byteArray.js                               |  1 +
 modules/format.js                                  |  3 ++-
 modules/lang.js                                    |  3 +--
 modules/overrides/GLib.js                          | 12 ++++++++----
 modules/tweener/equations.js                       |  2 ++
 13 files changed, 35 insertions(+), 20 deletions(-)
---
diff --git a/.eslintrc.yml b/.eslintrc.yml
index f107b115..45ebedc0 100644
--- a/.eslintrc.yml
+++ b/.eslintrc.yml
@@ -35,6 +35,9 @@ rules:
   linebreak-style:
     - error
     - unix
+  no-constant-condition:
+    - error
+    - checkLoops: false
   no-empty:
     - error
     - allowEmptyCatch: true
@@ -42,6 +45,7 @@ rules:
     - error
     - allow:
       - '!!'
+  no-prototype-builtins: 'off'
   no-restricted-properties:
     - error
     - object: Lang
@@ -51,6 +55,9 @@ rules:
       property: Class
       message: Use ES6 classes
   no-tabs: error
+  no-unused-vars:
+    - error
+    - varsIgnorePattern: ^unused
   nonblock-statement-body-position:
     - error
     - below
diff --git a/examples/gtk.js b/examples/gtk.js
index c3bf3836..36c4b5c7 100644
--- a/examples/gtk.js
+++ b/examples/gtk.js
@@ -7,7 +7,7 @@ const Gtk = imports.gi.Gtk;
 Gtk.init(null);
 
 // Construct a top-level window
-let window = new Gtk.Window ({
+let win = new Gtk.Window ({
     type: Gtk.WindowType.TOPLEVEL,
     title: 'A default title',
     default_width: 300,
@@ -20,7 +20,7 @@ let window = new Gtk.Window ({
 
 // Object properties can also be set or changed after construction, unless they
 // are marked construct-only.
-window.title = 'Hello World!';
+win.title = 'Hello World!';
 
 // This is a callback function
 function onDeleteEvent() {
@@ -36,14 +36,14 @@ function onDeleteEvent() {
 // When the window is given the "delete_event" signal (this is given by the
 // window manager, usually by the "close" option, or on the titlebar), we ask
 // it to call the onDeleteEvent() function as defined above.
-window.connect('delete-event', onDeleteEvent);
+win.connect('delete-event', onDeleteEvent);
 
 // GJS will warn when calling a C function with unexpected arguments...
 //
 //     window.connect("destroy", Gtk.main_quit);
 //
 // ...so use arrow functions for inline callbacks with arguments to adjust
-window.connect('destroy', () => {
+win.connect('destroy', () => {
     Gtk.main_quit();
 });
 
@@ -60,13 +60,13 @@ let button = new Gtk.Button({
 });
 
 // Connect to the 'clicked' signal, using another way to call an arrow function
-button.connect('clicked', () => window.destroy());
+button.connect('clicked', () => win.destroy());
 
 // Add the button to the window
-window.add(button);
+win.add(button);
 
 // Show the window
-window.show();
+win.show();
 
 // All gtk applications must have a Gtk.main(). Control will end here and wait
 // for an event to occur (like a key press or mouse event). The main loop will
diff --git a/installed-tests/js/modules/foobar.js b/installed-tests/js/modules/foobar.js
index f2736ac8..44b3deaa 100644
--- a/installed-tests/js/modules/foobar.js
+++ b/installed-tests/js/modules/foobar.js
@@ -1,5 +1,6 @@
 // simple test module (used by testImporter.js)
 
+/* eslint no-redeclare: ["error", { "builtinGlobals": false }] */ // for toString
 /* exported bar, foo, testToString, toString */
 
 var foo = 'This is foo';
diff --git a/installed-tests/js/testEverythingBasic.js b/installed-tests/js/testEverythingBasic.js
index ff079031..9f13351a 100644
--- a/installed-tests/js/testEverythingBasic.js
+++ b/installed-tests/js/testEverythingBasic.js
@@ -526,7 +526,7 @@ describe('Life, the Universe and Everything', function () {
         });
 
         it('throws errors for invalid signals', function () {
-            expect(() => o.connect('invalid-signal', o => {})).toThrow();
+            expect(() => o.connect('invalid-signal', () => {})).toThrow();
             expect(() => o.emit('invalid-signal')).toThrow();
         });
 
diff --git a/installed-tests/js/testGDBus.js b/installed-tests/js/testGDBus.js
index b7ac134d..65597f2f 100644
--- a/installed-tests/js/testGDBus.js
+++ b/installed-tests/js/testGDBus.js
@@ -112,7 +112,7 @@ class Test {
         this._impl.export(Gio.DBus.session, '/org/gnome/gjs/Test');
     }
 
-    frobateStuff(args) {
+    frobateStuff() {
         return {hello: new GLib.Variant('s', 'world')};
     }
 
diff --git a/installed-tests/js/testGObjectDestructionAccess.js 
b/installed-tests/js/testGObjectDestructionAccess.js
index fa195d2a..dffd4be0 100644
--- a/installed-tests/js/testGObjectDestructionAccess.js
+++ b/installed-tests/js/testGObjectDestructionAccess.js
@@ -20,7 +20,7 @@ describe('Access to destroyed GObject', () => {
         GLib.test_expect_message('Gjs', GLib.LogLevelFlags.LEVEL_CRITICAL,
             'Object Gtk.Window (0x*');
 
-        let title = destroyedWindow.title;
+        void destroyedWindow.title;
 
         GLib.test_assert_expected_messages_internal('Gjs', 'testGObjectDestructionAccess.js', 0,
             'testExceptionInDestroyedObjectPropertyGet');
@@ -40,7 +40,7 @@ describe('Access to destroyed GObject', () => {
         GLib.test_expect_message('Gjs', GLib.LogLevelFlags.LEVEL_CRITICAL,
             'Object Gtk.Window (0x*');
 
-        let title = destroyedWindow.get_title();
+        void destroyedWindow.get_title();
 
         GLib.test_assert_expected_messages_internal('Gjs', 'testGObjectDestructionAccess.js', 0,
             'testExceptionInDestroyedObjectMethodGet');
diff --git a/installed-tests/js/testTweener.js b/installed-tests/js/testTweener.js
index 14951bda..ab0a59bb 100644
--- a/installed-tests/js/testTweener.js
+++ b/installed-tests/js/testTweener.js
@@ -307,7 +307,7 @@ describe('Tweener', function () {
                 return {name: prop, parameters: null};
             });
         }
-        function discrete_get(begin, end, time, params) {
+        function discrete_get(begin, end, time) {
             return Math.floor(begin + time * (end - begin));
         }
 
diff --git a/modules/_bootstrap/debugger.js b/modules/_bootstrap/debugger.js
index 02ccb35a..eb8c2f19 100644
--- a/modules/_bootstrap/debugger.js
+++ b/modules/_bootstrap/debugger.js
@@ -1,4 +1,4 @@
-/* global Debugger, debuggee, quit, readline, uneval */
+/* global debuggee, quit, readline, uneval */
 /* -*- indent-tabs-mode: nil; js-indent-level: 4 -*-
  *
  * This Source Code Form is subject to the terms of the Mozilla Public
diff --git a/modules/byteArray.js b/modules/byteArray.js
index ff54374c..53a49f5b 100644
--- a/modules/byteArray.js
+++ b/modules/byteArray.js
@@ -1,5 +1,6 @@
 /* exported ByteArray, fromArray, fromGBytes, fromString, toGBytes, toString */
 
+/* eslint no-redeclare: ["error", { "builtinGlobals": false }] */  // for toString
 var {fromGBytes, fromString, toGBytes, toString} = imports._byteArrayNative;
 
 // For backwards compatibility
diff --git a/modules/format.js b/modules/format.js
index fd994502..5e841c27 100644
--- a/modules/format.js
+++ b/modules/format.js
@@ -44,13 +44,14 @@ function vprintf(str, args) {
         case 's':
             s = String(getArg());
             break;
-        case 'd':
+        case 'd': {
             let intV = parseInt(getArg());
             if (hasAlternativeIntFlag)
                 s = GjsPrivate.format_int_alternative_output(intV);
             else
                 s = intV.toString();
             break;
+        }
         case 'x':
             s = parseInt(getArg()).toString(16);
             break;
diff --git a/modules/lang.js b/modules/lang.js
index 0b4c3143..4c41c8e8 100644
--- a/modules/lang.js
+++ b/modules/lang.js
@@ -27,9 +27,8 @@ var {Class, Interface, getMetaClass} = imports._legacy;
 
 function countProperties(obj) {
     let count = 0;
-    for (let property in obj) {
+    for (let unusedProperty in obj)
         count += 1;
-    }
     return count;
 }
 
diff --git a/modules/overrides/GLib.js b/modules/overrides/GLib.js
index ffdb39c2..3ffa57fe 100644
--- a/modules/overrides/GLib.js
+++ b/modules/overrides/GLib.js
@@ -151,7 +151,7 @@ function _pack_variant(signature, value) {
         return GLib.Variant.new_array(new GLib.VariantType(arrayType.join('')), arrayValue);
     }
 
-    case '(':
+    case '(': {
         let children = [];
         for (let i = 0; i < value.length; i++) {
             let next = signature[0];
@@ -164,7 +164,8 @@ function _pack_variant(signature, value) {
             throw new TypeError('Invalid GVariant signature for type TUPLE (expected ")")');
         signature.shift();
         return GLib.Variant.new_tuple(children);
-    case '{':
+    }
+    case '{': {
         let key = _pack_variant(signature, value[0]);
         let child = _pack_variant(signature, value[1]);
 
@@ -173,6 +174,7 @@ function _pack_variant(signature, value) {
         signature.shift();
 
         return GLib.Variant.new_dict_entry(key, child);
+    }
     default:
         throw new TypeError(`Invalid GVariant signature (unexpected character ${char})`);
     }
@@ -211,12 +213,13 @@ function _unpack_variant(variant, deep, recursive = false) {
             return _unpack_variant(ret, deep, recursive);
         return ret;
     }
-    case 'm':
+    case 'm': {
         let val = variant.get_maybe();
         if (deep && val)
             return _unpack_variant(val, deep, recursive);
         else
             return val;
+    }
     case 'a':
         if (variant.is_of_type(new GLib.VariantType('a{?*}'))) {
             // special case containers
@@ -243,7 +246,7 @@ function _unpack_variant(variant, deep, recursive = false) {
 
         // fall through
     case '(':
-    case '{':
+    case '{': {
         let ret = [];
         let nElements = variant.n_children();
         for (let i = 0; i < nElements; i++) {
@@ -255,6 +258,7 @@ function _unpack_variant(variant, deep, recursive = false) {
         }
         return ret;
     }
+    }
 
     throw new Error('Assertion failure: this code should not be reached');
 }
diff --git a/modules/tweener/equations.js b/modules/tweener/equations.js
index c4c4568e..49e5cdab 100644
--- a/modules/tweener/equations.js
+++ b/modules/tweener/equations.js
@@ -1,4 +1,6 @@
 /* -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil; -*- */
+/* eslint-disable no-unused-vars */
+
 /* Copyright 2008 litl, LLC. */
 /**
  * Equations


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