[gjs: 20/43] CI: Add no-extra-parens to eslint rules



commit a8a059dad72d1654a01e8a331f8e32e19dcf3d8e
Author: Philip Chimento <philip chimento gmail com>
Date:   Sat Aug 3 22:35:42 2019 -0700

    CI: Add no-extra-parens to eslint rules
    
    This improves readability, having lots of extra parentheses is hard on
    the eye.

 .eslintrc.yml                   |  5 +++++
 examples/calc.js                |  5 ++---
 installed-tests/js/testGDBus.js |  2 +-
 modules/_bootstrap/debugger.js  |  4 ++--
 modules/_legacy.js              | 12 ++++++------
 modules/format.js               |  6 +++---
 modules/lang.js                 | 10 +++++-----
 modules/overrides/GObject.js    | 12 ++++++------
 modules/overrides/Gio.js        |  4 ++--
 modules/package.js              |  6 +++---
 modules/signals.js              |  2 +-
 modules/tweener/equations.js    | 34 +++++++++++++++++-----------------
 modules/tweener/tweener.js      |  8 ++++----
 13 files changed, 57 insertions(+), 53 deletions(-)
---
diff --git a/.eslintrc.yml b/.eslintrc.yml
index 08482876..deed713d 100644
--- a/.eslintrc.yml
+++ b/.eslintrc.yml
@@ -70,6 +70,11 @@ rules:
     - error
     - allowEmptyCatch: true
   no-extra-bind: error
+  no-extra-parens:
+    - error
+    - all
+    - conditionalAssign: false
+      returnAssign: false
   no-implicit-coercion:
     - error
     - allow:
diff --git a/examples/calc.js b/examples/calc.js
index 860c17ff..87e21b62 100644
--- a/examples/calc.js
+++ b/examples/calc.js
@@ -43,13 +43,12 @@ function pressedOperator(button) {
 }
 
 function pressedNumber(button) {
-    calcVal = (((calcVal === 0) ? '' : calcVal) + button.label);
+    calcVal = (calcVal === 0 ? '' : calcVal) + button.label;
     updateDisplay();
 }
 
 function swapSign() {
-    calcVal = ((calcVal[0] === '-') ?
-        calcVal.substring(1) : `-${calcVal}`);
+    calcVal = calcVal[0] === '-' ? calcVal.substring(1) : `-${calcVal}`;
     updateDisplay();
 }
 
diff --git a/installed-tests/js/testGDBus.js b/installed-tests/js/testGDBus.js
index 805435fa..127f4217 100644
--- a/installed-tests/js/testGDBus.js
+++ b/installed-tests/js/testGDBus.js
@@ -268,7 +268,7 @@ describe('Exported DBus object', function () {
         });
 
         while (waitId && (!test[property] ||
-                          (value !== undefined && test[property] !== value)))
+                          value !== undefined && test[property] !== value))
             loop.get_context().iteration(true);
 
         if (waitId)
diff --git a/modules/_bootstrap/debugger.js b/modules/_bootstrap/debugger.js
index 12e265f8..38ad4c78 100644
--- a/modules/_bootstrap/debugger.js
+++ b/modules/_bootstrap/debugger.js
@@ -34,7 +34,7 @@ function dvToString(v) {
         return 'undefined';  // uneval(undefined) === '(void 0)', confusing
     if (v === null)
         return 'null';  // typeof null === 'object', so avoid that case
-    return (typeof v !== 'object' || v === null) ? uneval(v) : `[object ${v.class}]`;
+    return typeof v !== 'object' || v === null ? uneval(v) : `[object ${v.class}]`;
 }
 
 function summarizeObject(dv) {
@@ -493,7 +493,7 @@ function doStepOrNext(kind) {
                 stop = true;
         } else {
             // regular step; stop whenever the line number changes
-            if ((this.line !== startLine) || (this !== startFrame))
+            if (this.line !== startLine || this !== startFrame)
                 stop = true;
         }
 
diff --git a/modules/_legacy.js b/modules/_legacy.js
index 6d758a0a..b6fb0c4b 100644
--- a/modules/_legacy.js
+++ b/modules/_legacy.js
@@ -337,9 +337,9 @@ Interface.prototype._check = function (proto) {
         // so that required interfaces don't copy over properties from other
         // interfaces that require them.
         let interfaces = proto.__interfaces__;
-        return ((!_interfacePresent(required, proto) ||
+        return (!_interfacePresent(required, proto) ||
             interfaces.indexOf(required) > interfaces.indexOf(this)) &&
-            !(proto instanceof required));
+            !(proto instanceof required);
     }).map(required =>
         // __name__ is only present on GJS-created classes and will be the most
         // accurate name. required.name will be present on introspected GObjects
@@ -419,10 +419,10 @@ function defineGObjectLegacyObjects(GObject) {
     function _createSignals(gtype, signals) {
         for (let signalName in signals) {
             let obj = signals[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;
-            let paramtypes = (obj.param_types !== undefined) ? obj.param_types : [];
+            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;
+            let paramtypes = obj.param_types !== undefined ? obj.param_types : [];
 
             try {
                 obj.signal_id = Gi.signal_new(gtype, signalName, flags, accumulator, rtype, paramtypes);
diff --git a/modules/format.js b/modules/format.js
index 7208a19b..27c7b3e9 100644
--- a/modules/format.js
+++ b/modules/format.js
@@ -12,8 +12,8 @@ function vprintf(str, args) {
             genericGroup !== 'f')
             throw new Error("Precision can only be specified for 'f'");
 
-        let hasAlternativeIntFlag = (flagsGroup &&
-            flagsGroup.indexOf('I') !== -1);
+        let hasAlternativeIntFlag = flagsGroup &&
+            flagsGroup.indexOf('I') !== -1;
         if (hasAlternativeIntFlag && genericGroup !== 'd')
             throw new Error("Alternative output digits can only be specfied for 'd'");
 
@@ -23,7 +23,7 @@ function vprintf(str, args) {
         if (usePos && pos === 0 || !usePos && pos > 0)
             throw new Error('Numbered and unnumbered conversion specifications cannot be mixed');
 
-        let fillChar = (widthGroup && widthGroup[0] === '0') ? '0' : ' ';
+        let fillChar = widthGroup && widthGroup[0] === '0' ? '0' : ' ';
         let width = parseInt(widthGroup, 10) || 0;
 
         function fillWidth(s, c, w) {
diff --git a/modules/lang.js b/modules/lang.js
index d58ae4ea..cc035d43 100644
--- a/modules/lang.js
+++ b/modules/lang.js
@@ -50,7 +50,7 @@ function copyProperties(source, dest) {
 
 function copyPublicProperties(source, dest) {
     for (let property in source) {
-        if (typeof(property) === 'string' && property.startsWith('_'))
+        if (typeof property === 'string' && property.startsWith('_'))
             continue;
         else
             _copyProperty(source, dest, property);
@@ -67,14 +67,14 @@ function copyPublicProperties(source, dest) {
  * @type: function
  */
 function bind(obj, callback) {
-    if (typeof(obj) !== 'object') {
+    if (typeof obj !== 'object') {
         throw new Error(`first argument to Lang.bind() must be an object, not ${
-            typeof(obj)}`);
+            typeof obj}`);
     }
 
-    if (typeof(callback) !== 'function') {
+    if (typeof callback !== 'function') {
         throw new Error(`second argument to Lang.bind() must be a function, not ${
-            typeof(callback)}`);
+            typeof callback}`);
     }
 
     // Use ES5 Function.prototype.bind, but only if not passing any bindArguments,
diff --git a/modules/overrides/GObject.js b/modules/overrides/GObject.js
index bc0c7ebe..edb461e4 100644
--- a/modules/overrides/GObject.js
+++ b/modules/overrides/GObject.js
@@ -98,10 +98,10 @@ function registerClass(klass) {
 function _createSignals(gtype, signals) {
     for (let signalName in signals) {
         let obj = signals[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;
-        let paramtypes = (obj.param_types !== undefined) ? obj.param_types : [];
+        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;
+        let paramtypes = obj.param_types !== undefined ? obj.param_types : [];
 
         try {
             obj.signal_id = Gi.signal_new(gtype, signalName, flags, accumulator, rtype, paramtypes);
@@ -159,9 +159,9 @@ function _checkInterface(iface, proto) {
         // so that required interfaces don't copy over properties from other
         // interfaces that require them.
         let ifaces = proto.constructor[interfaces];
-        return ((!_interfacePresent(required, proto.constructor) ||
+        return (!_interfacePresent(required, proto.constructor) ||
             ifaces.indexOf(required) > ifaces.indexOf(iface)) &&
-            !(proto instanceof required));
+            !(proto instanceof required);
     }).map(required =>
         // required.name will be present on JS classes, but on introspected
         // GObjects it will be the C name. The alternative is just so that
diff --git a/modules/overrides/Gio.js b/modules/overrides/Gio.js
index a08b4861..1d9ed1e3 100644
--- a/modules/overrides/Gio.js
+++ b/modules/overrides/Gio.js
@@ -100,9 +100,9 @@ function _proxyInvoker(methodName, sync, inSignature, argArray) {
     while (argArray.length > signatureLength) {
         var argNum = argArray.length - 1;
         var arg = argArray.pop();
-        if (typeof(arg) === 'function' && !sync) {
+        if (typeof arg === 'function' && !sync) {
             replyFunc = arg;
-        } else if (typeof(arg) === 'number') {
+        } else if (typeof arg === 'number') {
             flags = arg;
         } else if (arg instanceof Gio.Cancellable) {
             cancellable = arg;
diff --git a/modules/package.js b/modules/package.js
index aeaa6652..0010b789 100644
--- a/modules/package.js
+++ b/modules/package.js
@@ -290,14 +290,14 @@ function checkSymbol(lib, version, symbol) {
 
     let [klass, sym] = symbol.split('.');
     if (klass === symbol) // global symbol
-        return (typeof Lib[symbol] !== 'undefined');
+        return typeof Lib[symbol] !== 'undefined';
 
     let obj = Lib[klass];
     if (typeof obj === 'undefined')
         return false;
 
     if (typeof obj[sym] !== 'undefined' ||
-        (obj.prototype && typeof obj.prototype[sym] !== 'undefined'))
+        obj.prototype && typeof obj.prototype[sym] !== 'undefined')
         return true; // class- or object method
 
     // GObject property
@@ -309,7 +309,7 @@ function checkSymbol(lib, version, symbol) {
         pspec = GObject.Object.find_property.call(obj.$gtype, sym);
     }
 
-    return (pspec !== null);
+    return pspec !== null;
 }
 
 function initGettext() {
diff --git a/modules/signals.js b/modules/signals.js
index e4ef9f80..bcb20bf8 100644
--- a/modules/signals.js
+++ b/modules/signals.js
@@ -33,7 +33,7 @@ const Lang = imports.lang;
 function _connect(name, callback) {
     // be paranoid about callback arg since we'd start to throw from emit()
     // if it was messed up
-    if (typeof(callback) !== 'function')
+    if (typeof callback !== 'function')
         throw new Error('When connecting signal must give a callback that is a function');
 
     // we instantiate the "signal machinery" only on-demand if anything
diff --git a/modules/tweener/equations.js b/modules/tweener/equations.js
index d7201350..a9e39bbe 100644
--- a/modules/tweener/equations.js
+++ b/modules/tweener/equations.js
@@ -98,7 +98,7 @@ function easeOutQuad (t, b, c, d, pParams) {
 function easeInOutQuad (t, b, c, d, pParams) {
     if ((t /= d / 2) < 1)
         return c / 2 * t * t + b;
-    return -c / 2 * ((--t) * (t - 2) - 1) + b;
+    return -c / 2 * (--t * (t - 2) - 1) + b;
 }
 
 /**
@@ -113,7 +113,7 @@ function easeInOutQuad (t, b, c, d, pParams) {
 function easeOutInQuad (t, b, c, d, pParams) {
     if (t < d / 2)
         return easeOutQuad(t * 2, b, c / 2, d, pParams);
-    return easeInQuad((t * 2) - d, b + c / 2, c / 2, d, pParams);
+    return easeInQuad(t * 2 - d, b + c / 2, c / 2, d, pParams);
 }
 
 /**
@@ -169,7 +169,7 @@ function easeInOutCubic (t, b, c, d, pParams) {
 function easeOutInCubic (t, b, c, d, pParams) {
     if (t < d / 2)
         return easeOutCubic(t * 2, b, c / 2, d, pParams);
-    return easeInCubic((t * 2) - d, b + c / 2, c / 2, d, pParams);
+    return easeInCubic(t * 2 - d, b + c / 2, c / 2, d, pParams);
 }
 
 /**
@@ -225,7 +225,7 @@ function easeInOutQuart (t, b, c, d, pParams) {
 function easeOutInQuart (t, b, c, d, pParams) {
     if (t < d / 2)
         return easeOutQuart(t * 2, b, c / 2, d, pParams);
-    return easeInQuart((t * 2) - d, b + c / 2, c / 2, d, pParams);
+    return easeInQuart(t * 2 - d, b + c / 2, c / 2, d, pParams);
 }
 
 /**
@@ -281,7 +281,7 @@ function easeInOutQuint (t, b, c, d, pParams) {
 function easeOutInQuint (t, b, c, d, pParams) {
     if (t < d / 2)
         return easeOutQuint(t * 2, b, c / 2, d, pParams);
-    return easeInQuint((t * 2) - d, b + c / 2, c / 2, d, pParams);
+    return easeInQuint(t * 2 - d, b + c / 2, c / 2, d, pParams);
 }
 
 /**
@@ -335,7 +335,7 @@ function easeInOutSine (t, b, c, d, pParams) {
 function easeOutInSine (t, b, c, d, pParams) {
     if (t < d / 2)
         return easeOutSine(t * 2, b, c / 2, d, pParams);
-    return easeInSine((t * 2) - d, b + c / 2, c / 2, d, pParams);
+    return easeInSine(t * 2 - d, b + c / 2, c / 2, d, pParams);
 }
 
 /**
@@ -348,7 +348,7 @@ function easeOutInSine (t, b, c, d, pParams) {
  * @return              The correct value.
  */
 function easeInExpo (t, b, c, d, pParams) {
-    return (t <= 0) ? b : c * Math.pow(2, 10 * (t / d - 1)) + b;
+    return t <= 0 ? b : c * Math.pow(2, 10 * (t / d - 1)) + b;
 }
 
 /**
@@ -361,7 +361,7 @@ function easeInExpo (t, b, c, d, pParams) {
  * @return              The correct value.
  */
 function easeOutExpo (t, b, c, d, pParams) {
-    return (t >= d) ? b + c : c * (-Math.pow(2, -10 * t / d) + 1) + b;
+    return t >= d ? b + c : c * (-Math.pow(2, -10 * t / d) + 1) + b;
 }
 
 /**
@@ -395,7 +395,7 @@ function easeInOutExpo (t, b, c, d, pParams) {
 function easeOutInExpo (t, b, c, d, pParams) {
     if (t < d / 2)
         return easeOutExpo(t * 2, b, c / 2, d, pParams);
-    return easeInExpo((t * 2) - d, b + c / 2, c / 2, d, pParams);
+    return easeInExpo(t * 2 - d, b + c / 2, c / 2, d, pParams);
 }
 
 /**
@@ -451,7 +451,7 @@ function easeInOutCirc (t, b, c, d, pParams) {
 function easeOutInCirc (t, b, c, d, pParams) {
     if (t < d / 2)
         return easeOutCirc(t * 2, b, c / 2, d, pParams);
-    return easeInCirc((t * 2) - d, b + c / 2, c / 2, d, pParams);
+    return easeInCirc(t * 2 - d, b + c / 2, c / 2, d, pParams);
 }
 
 /**
@@ -507,7 +507,7 @@ function easeOutElastic (t, b, c, d, pParams) {
     } else {
         s = p / (2 * Math.PI) * Math.asin(c / a);
     }
-    return (a * Math.pow(2, -10 * t) * Math.sin( (t * d - s) * (2 * Math.PI) / p ) + c + b);
+    return a * Math.pow(2, -10 * t) * Math.sin( (t * d - s) * (2 * Math.PI) / p ) + c + b;
 }
 
 /**
@@ -554,7 +554,7 @@ function easeInOutElastic (t, b, c, d, pParams) {
 function easeOutInElastic (t, b, c, d, pParams) {
     if (t < d / 2)
         return easeOutElastic(t * 2, b, c / 2, d, pParams);
-    return easeInElastic((t * 2) - d, b + c / 2, c / 2, d, pParams);
+    return easeInElastic(t * 2 - d, b + c / 2, c / 2, d, pParams);
 }
 
 /**
@@ -617,7 +617,7 @@ function easeInOutBack (t, b, c, d, pParams) {
 function easeOutInBack (t, b, c, d, pParams) {
     if (t < d / 2)
         return easeOutBack(t * 2, b, c / 2, d, pParams);
-    return easeInBack((t * 2) - d, b + c / 2, c / 2, d, pParams);
+    return easeInBack(t * 2 - d, b + c / 2, c / 2, d, pParams);
 }
 
 /**
@@ -643,11 +643,11 @@ function easeInBounce (t, b, c, d, pParams) {
  * @return              The correct value.
  */
 function easeOutBounce (t, b, c, d, pParams) {
-    if ((t /= d) < (1 / 2.75))
+    if ((t /= d) < 1 / 2.75)
         return c * (7.5625 * t * t) + b;
-    else if (t < (2 / 2.75))
+    else if (t < 2 / 2.75)
         return c * (7.5625 * (t -= (1.5 / 2.75)) * t + .75) + b;
-    else if (t < (2.5 / 2.75))
+    else if (t < 2.5 / 2.75)
         return c * (7.5625 * (t -= (2.25 / 2.75)) * t + .9375) + b;
     else
         return c * (7.5625 * (t -= (2.625 / 2.75)) * t + .984375) + b;
@@ -681,5 +681,5 @@ function easeInOutBounce (t, b, c, d, pParams) {
 function easeOutInBounce (t, b, c, d, pParams) {
     if (t < d / 2)
         return easeOutBounce(t * 2, b, c / 2, d, pParams);
-    return easeInBounce((t * 2) - d, b + c / 2, c / 2, d, pParams);
+    return easeInBounce(t * 2 - d, b + c / 2, c / 2, d, pParams);
 }
diff --git a/modules/tweener/tweener.js b/modules/tweener/tweener.js
index e6a0a999..3adc6f78 100644
--- a/modules/tweener/tweener.js
+++ b/modules/tweener/tweener.js
@@ -230,7 +230,7 @@ function _updateTweenByIndex(i) {
 
     if (tweening.isCaller) {
         do {
-            t = ((tweening.timeComplete - tweening.timeStart) / tweening.count) *
+            t = (tweening.timeComplete - tweening.timeStart) / tweening.count *
                 (tweening.timesCalled + 1);
             b = tweening.timeStart;
             c = tweening.timeComplete - tweening.timeStart;
@@ -559,8 +559,8 @@ function _addTweenOrCaller(target, tweeningParameters, isCaller) {
         }
 
         tween = new TweenList.TweenList(scopes[i],
-            _ticker.getTime() + ((delay * 1000) / _timeScale),
-            _ticker.getTime() + (((delay * 1000) + (time * 1000)) / _timeScale),
+            _ticker.getTime() + delay * 1000 / _timeScale,
+            _ticker.getTime() + (delay * 1000 + time * 1000) / _timeScale,
             false,
             transition,
             obj.transitionParams || null);
@@ -778,7 +778,7 @@ function _affectTweensWithFunction(func, args) {
         scopes = new Array(scope);
 
     for (let i = 1; args[i] != undefined; i++) {
-        if (typeof(args[i]) == 'string' && !_isInArray(args[i], properties)) {
+        if (typeof args[i] == 'string' && !_isInArray(args[i], properties)) {
             if (_specialPropertySplitterList[args[i]]) {
                 // special property, get splitter array first
                 var sps = _specialPropertySplitterList[arguments[i]];


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