Bug 1330791 - Enable no-else-return rule for eslint in /services and fix associated errors. r=markh
authorJared Wein <jwein@mozilla.com>
Thu, 12 Jan 2017 18:14:54 -0500
changeset 464589 5e9e3e81dc8103b412715aa11a5b0a7de0a38674
parent 464588 83aebfdeb00582b3707a5cd0d7404513cc5fea59
child 464590 2d05b9324d102cde14ff5a53a48d1510fe402bc9
push id42370
push usermwein@mozilla.com
push dateSat, 21 Jan 2017 03:10:58 +0000
reviewersmarkh
bugs1330791
milestone53.0a1
Bug 1330791 - Enable no-else-return rule for eslint in /services and fix associated errors. r=markh MozReview-Commit-ID: 7Os4uZQCDox
services/.eslintrc.js
services/common/stringbundle.js
services/crypto/modules/utils.js
services/fxaccounts/FxAccountsProfileClient.jsm
services/fxaccounts/tests/xpcshell/test_web_channel.js
services/sync/modules/addonsreconciler.js
services/sync/modules/addonutils.js
services/sync/modules/browserid_identity.js
services/sync/modules/service.js
services/sync/tests/unit/test_browserid_identity.js
services/sync/tps/extensions/tps/resource/modules/bookmarks.jsm
services/sync/tps/extensions/tps/resource/modules/forms.jsm
--- a/services/.eslintrc.js
+++ b/services/.eslintrc.js
@@ -6,17 +6,16 @@ module.exports = {
   ],
   rules: {
     /* These rules are only set to warn temporarily
        until they get fixed, at which point their
        respective line in this file should be removed. */
     "brace-style": "warn",
     "consistent-return": "warn",
     "no-cond-assign": "warn",
-    "no-else-return": "warn",
     "no-ex-assign": "warn",
     "no-func-assign": "warn",
     "no-native-reassign": "warn",
     "no-nested-ternary": "warn",
     "no-octal": "warn",
     "no-redeclare": "warn",
     "no-unreachable": "warn",
     "no-unsafe-finally": "warn",
--- a/services/common/stringbundle.js
+++ b/services/common/stringbundle.js
@@ -87,18 +87,17 @@ StringBundle.prototype = {
    * @param args {array} [optional]
    *        an array of arguments that replace occurrences of %S in the string
    *
    * @returns {String} the value of the string
    */
   get(key, args) {
     if (args)
       return this.stringBundle.formatStringFromName(key, args, args.length);
-    else
-      return this.stringBundle.GetStringFromName(key);
+    return this.stringBundle.GetStringFromName(key);
   },
 
   /**
    * Get all the strings in the bundle.
    *
    * @returns {Array}
    *          an array of objects with key and value properties
    */
--- a/services/crypto/modules/utils.js
+++ b/services/crypto/modules/utils.js
@@ -255,22 +255,21 @@ this.CryptoUtils = {
   },
 
   deriveKeyFromPassphrase: function deriveKeyFromPassphrase(passphrase,
                                                             salt,
                                                             keyLength,
                                                             forceJS) {
     if (Svc.Crypto.deriveKeyFromPassphrase && !forceJS) {
       return Svc.Crypto.deriveKeyFromPassphrase(passphrase, salt, keyLength);
-    } else {
-      // Fall back to JS implementation.
-      // 4096 is hardcoded in WeaveCrypto, so do so here.
-      return CryptoUtils.pbkdf2Generate(passphrase, atob(salt), 4096,
-                                        keyLength);
     }
+    // Fall back to JS implementation.
+    // 4096 is hardcoded in WeaveCrypto, so do so here.
+    return CryptoUtils.pbkdf2Generate(passphrase, atob(salt), 4096,
+                                      keyLength);
   },
 
   /**
    * Compute the HTTP MAC SHA-1 for an HTTP request.
    *
    * @param  identifier
    *         (string) MAC Key Identifier.
    * @param  key
--- a/services/fxaccounts/FxAccountsProfileClient.jsm
+++ b/services/fxaccounts/FxAccountsProfileClient.jsm
@@ -165,24 +165,23 @@ this.FxAccountsProfileClient.prototype =
         }
 
         // "response.success" means status code is 200
         if (request.response.success) {
           return resolve({
             body,
             etag: request.response.headers["etag"]
           });
-        } else {
-          return reject(new FxAccountsProfileClientError({
-            error: body.error || ERROR_UNKNOWN,
-            errno: body.errno || ERRNO_UNKNOWN_ERROR,
-            code: request.response.status,
-            message: body.message || body,
-          }));
         }
+        return reject(new FxAccountsProfileClientError({
+          error: body.error || ERROR_UNKNOWN,
+          errno: body.errno || ERRNO_UNKNOWN_ERROR,
+          code: request.response.status,
+          message: body.message || body,
+        }));
       };
 
       if (method === "GET") {
         request.get();
       } else {
         // method not supported
         return reject(new FxAccountsProfileClientError({
           error: ERROR_NETWORK,
--- a/services/fxaccounts/tests/xpcshell/test_web_channel.js
+++ b/services/fxaccounts/tests/xpcshell/test_web_channel.js
@@ -486,14 +486,13 @@ function makeObserver(aObserveTopic, aOb
 }
 
 function validationHelper(params, expected) {
   try {
     new FxAccountsWebChannel(params);
   } catch (e) {
     if (typeof expected === "string") {
       return do_check_eq(e.toString(), expected);
-    } else {
-      return do_check_true(e.toString().match(expected));
     }
+    return do_check_true(e.toString().match(expected));
   }
   throw new Error("Validation helper error");
 }
--- a/services/sync/modules/addonsreconciler.js
+++ b/services/sync/modules/addonsreconciler.js
@@ -291,19 +291,18 @@ AddonsReconciler.prototype = {
    * @param listener
    *        Listener instance to remove.
    */
   removeChangeListener: function removeChangeListener(listener) {
     this._listeners = this._listeners.filter(function(element) {
       if (element == listener) {
         this._log.debug("Removing change listener.");
         return false;
-      } else {
-        return true;
       }
+      return true;
     }.bind(this));
   },
 
   /**
    * Tells the instance to start listening for AddonManager changes.
    *
    * This is typically called automatically when Sync is loaded.
    */
--- a/services/sync/modules/addonutils.js
+++ b/services/sync/modules/addonutils.js
@@ -309,19 +309,18 @@ AddonUtilsInternal.prototype = {
             continue;
           }
 
           let params = addon.sourceURI.query.split("&").map(
             function rewrite(param) {
 
             if (param.indexOf("src=") == 0) {
               return "src=sync";
-            } else {
-              return param;
             }
+            return param;
           });
 
           addon.sourceURI.query = params.join("&");
         }
 
         expectedInstallCount = toInstall.length;
 
         if (!expectedInstallCount) {
--- a/services/sync/modules/browserid_identity.js
+++ b/services/sync/modules/browserid_identity.js
@@ -402,19 +402,18 @@ this.BrowserIDManager.prototype = {
     if (this.syncKeyBundle) {
       // TODO: This is probably fine because the code shouldn't be
       // using the sync key directly (it should use the sync key
       // bundle), but I don't like it. We should probably refactor
       // code that is inspecting this to not do validation on this
       // field directly and instead call a isSyncKeyValid() function
       // that we can override.
       return "99999999999999999999999999";
-    } else {
-      return null;
     }
+    return null;
   },
 
   set syncKey(value) {
     throw "syncKey setter should be not used in BrowserIDManager";
   },
 
   get syncKeyBundle() {
     return this._syncKeyBundle;
--- a/services/sync/modules/service.js
+++ b/services/sync/modules/service.js
@@ -657,21 +657,19 @@ Sync11Service.prototype = {
           // If _freshStart fails to clear the server or upload keys, it will
           // throw.
           this._freshStart();
           return true;
         }
 
         // Last-ditch case.
         return false;
-      } else {
-        // No update needed: we're good!
-        return true;
       }
-
+      // No update needed: we're good!
+      return true;
     } catch (ex) {
       // This means no keys are present, or there's a network error.
       this._log.debug("Failed to fetch and verify keys", ex);
       this.errorHandler.checkServerError(ex);
       return false;
     }
   },
 
@@ -1216,29 +1214,28 @@ Sync11Service.prototype = {
       // bug 545725 - re-verify creds and fail sanely
       if (!this.verifyLogin()) {
         this.status.sync = CREDENTIALS_CHANGED;
         this._log.info("Credentials have changed, aborting sync and forcing re-login.");
         return false;
       }
 
       return true;
-    } else {
-      if (!this.upgradeSyncKey(meta.payload.syncID)) {
-        this._log.warn("Failed to upgrade sync key. Failing remote setup.");
-        return false;
-      }
+    }
+    if (!this.upgradeSyncKey(meta.payload.syncID)) {
+      this._log.warn("Failed to upgrade sync key. Failing remote setup.");
+      return false;
+    }
 
-      if (!this.verifyAndFetchSymmetricKeys(infoResponse)) {
-        this._log.warn("Failed to fetch symmetric keys. Failing remote setup.");
-        return false;
-      }
+    if (!this.verifyAndFetchSymmetricKeys(infoResponse)) {
+      this._log.warn("Failed to fetch symmetric keys. Failing remote setup.");
+      return false;
+    }
 
-      return true;
-    }
+    return true;
   },
 
   /**
    * Return whether we should attempt login at the start of a sync.
    *
    * Note that this function has strong ties to _checkSync: callers
    * of this function should typically use _checkSync to verify that
    * any necessary login took place.
--- a/services/sync/tests/unit/test_browserid_identity.js
+++ b/services/sync/tests/unit/test_browserid_identity.js
@@ -468,30 +468,29 @@ add_task(async function test_refreshCert
   let mockTSC = mockTokenServer(() => {
     if (getCertCount <= 1) {
       didReturn401 = true;
       return {
         status: 401,
         headers: {"content-type": "application/json"},
         body: JSON.stringify({}),
       };
-    } else {
-      didReturn200 = true;
-      return {
-        status: 200,
-        headers: {"content-type": "application/json"},
-        body: JSON.stringify({
-          id:           "id",
-          key:          "key",
-          api_endpoint: "http://example.com/",
-          uid:          "uid",
-          duration:     300,
-        })
-      };
     }
+    didReturn200 = true;
+    return {
+      status: 200,
+      headers: {"content-type": "application/json"},
+      body: JSON.stringify({
+        id:           "id",
+        key:          "key",
+        api_endpoint: "http://example.com/",
+        uid:          "uid",
+        duration:     300,
+      })
+    };
   });
 
   browseridManager._tokenServerClient = mockTSC;
 
   await browseridManager.initializeWithCurrentIdentity();
   await browseridManager.whenReadyToAuthenticate.promise;
 
   do_check_eq(getCertCount, 2);
--- a/services/sync/tps/extensions/tps/resource/modules/bookmarks.jsm
+++ b/services/sync/tps/extensions/tps/resource/modules/bookmarks.jsm
@@ -212,19 +212,18 @@ PlacesItem.prototype = {
     let folder_id = PlacesUtils.bookmarks[this._bookmarkFolders[folder_parts[0]]];
     for (let i = 1; i < folder_parts.length; i++) {
       let subfolder_id = this.GetPlacesNodeId(
         folder_id,
         Ci.nsINavHistoryResultNode.RESULT_TYPE_FOLDER,
         folder_parts[i]);
       if (subfolder_id == -1) {
         return -1;
-      } else {
-        folder_id = subfolder_id;
       }
+      folder_id = subfolder_id;
     }
     return folder_id;
   },
 
   /**
    * CreateFolder
    *
    * Creates a bookmark folder.
--- a/services/sync/tps/extensions/tps/resource/modules/forms.jsm
+++ b/services/sync/tps/extensions/tps/resource/modules/forms.jsm
@@ -162,22 +162,21 @@ FormData.prototype = {
     Logger.AssertTrue(this.fieldname != null && this.value != null,
       "Must specify both fieldname and value");
 
     return FormDB.getDataForValue(this.fieldname, this.value).then(formdata => {
       if (!formdata) {
         // this item doesn't exist yet in the db, so we need to insert it
         return FormDB.insertValue(this.fieldname, this.value,
                                   this.hours_to_us(this.date));
-      } else {
-        /* Right now, we ignore this case.  If bug 552531 is ever fixed,
-           we might need to add code here to update the firstUsed or
-           lastUsed fields, as appropriate.
-         */
       }
+      /* Right now, we ignore this case.  If bug 552531 is ever fixed,
+         we might need to add code here to update the firstUsed or
+         lastUsed fields, as appropriate.
+       */
     });
   },
 
   /**
    * Find
    *
    * Attempts to locate an entry in the moz_formhistory database that
    * matches the fieldname and value for this FormData object.