From d3dba448bd36c97b0c5252a59ab0fddc34541689 Mon Sep 17 00:00:00 2001 From: Jared Wein Date: Thu, 12 Jan 2017 18:14:54 -0500 Subject: [PATCH] Bug 1330791 - Enable no-else-return rule for eslint in /services and fix associated errors. r=markh MozReview-Commit-ID: 7Os4uZQCDox --HG-- extra : rebase_source : 8d14b02c97b8024268b5625a633393e75efed117 --- services/.eslintrc.js | 1 - services/common/stringbundle.js | 3 +- services/crypto/modules/utils.js | 9 +++--- services/fxaccounts/FxAccountsProfile.jsm | 3 +- .../fxaccounts/FxAccountsProfileClient.jsm | 13 ++++----- .../tests/xpcshell/test_web_channel.js | 3 +- services/sync/modules/addonsreconciler.js | 3 +- services/sync/modules/addonutils.js | 3 +- services/sync/modules/browserid_identity.js | 3 +- services/sync/modules/service.js | 29 +++++++++---------- .../tests/unit/test_browserid_identity.js | 25 ++++++++-------- .../tps/resource/modules/bookmarks.jsm | 3 +- .../extensions/tps/resource/modules/forms.jsm | 9 +++--- 13 files changed, 46 insertions(+), 61 deletions(-) diff --git a/services/.eslintrc.js b/services/.eslintrc.js index 3d7ddb44fd05..77d90fd332c9 100644 --- a/services/.eslintrc.js +++ b/services/.eslintrc.js @@ -11,7 +11,6 @@ module.exports = { "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", diff --git a/services/common/stringbundle.js b/services/common/stringbundle.js index da2a14f75d4d..748ba528b5f6 100644 --- a/services/common/stringbundle.js +++ b/services/common/stringbundle.js @@ -92,8 +92,7 @@ StringBundle.prototype = { get(key, args) { if (args) return this.stringBundle.formatStringFromName(key, args, args.length); - else - return this.stringBundle.GetStringFromName(key); + return this.stringBundle.GetStringFromName(key); }, /** diff --git a/services/crypto/modules/utils.js b/services/crypto/modules/utils.js index edf0794dedf0..e61fac00432d 100644 --- a/services/crypto/modules/utils.js +++ b/services/crypto/modules/utils.js @@ -260,12 +260,11 @@ this.CryptoUtils = { 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); }, /** diff --git a/services/fxaccounts/FxAccountsProfile.jsm b/services/fxaccounts/FxAccountsProfile.jsm index 46271a7dda75..85800288a859 100644 --- a/services/fxaccounts/FxAccountsProfile.jsm +++ b/services/fxaccounts/FxAccountsProfile.jsm @@ -30,9 +30,8 @@ function deepEqual(actual, expected) { return true; } else if (typeof actual != "object" && typeof expected != "object") { return actual == expected; - } else { - return objEquiv(actual, expected); } + return objEquiv(actual, expected); } function isUndefinedOrNull(value) { diff --git a/services/fxaccounts/FxAccountsProfileClient.jsm b/services/fxaccounts/FxAccountsProfileClient.jsm index ea40258fbfc1..caccb5293e7c 100644 --- a/services/fxaccounts/FxAccountsProfileClient.jsm +++ b/services/fxaccounts/FxAccountsProfileClient.jsm @@ -161,14 +161,13 @@ this.FxAccountsProfileClient.prototype = { // "response.success" means status code is 200 if (request.response.success) { return resolve(body); - } 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") { diff --git a/services/fxaccounts/tests/xpcshell/test_web_channel.js b/services/fxaccounts/tests/xpcshell/test_web_channel.js index 8015431bbd7b..245ad21e66eb 100644 --- a/services/fxaccounts/tests/xpcshell/test_web_channel.js +++ b/services/fxaccounts/tests/xpcshell/test_web_channel.js @@ -491,9 +491,8 @@ function validationHelper(params, expected) { } 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"); } diff --git a/services/sync/modules/addonsreconciler.js b/services/sync/modules/addonsreconciler.js index 1001d23018e4..ade1eda157f5 100644 --- a/services/sync/modules/addonsreconciler.js +++ b/services/sync/modules/addonsreconciler.js @@ -296,9 +296,8 @@ AddonsReconciler.prototype = { if (element == listener) { this._log.debug("Removing change listener."); return false; - } else { - return true; } + return true; }.bind(this)); }, diff --git a/services/sync/modules/addonutils.js b/services/sync/modules/addonutils.js index bcfc4159d8ba..c5ad5d39fc7d 100644 --- a/services/sync/modules/addonutils.js +++ b/services/sync/modules/addonutils.js @@ -314,9 +314,8 @@ AddonUtilsInternal.prototype = { if (param.indexOf("src=") == 0) { return "src=sync"; - } else { - return param; } + return param; }); addon.sourceURI.query = params.join("&"); diff --git a/services/sync/modules/browserid_identity.js b/services/sync/modules/browserid_identity.js index d9f1a4be70fe..efde0c283f9d 100644 --- a/services/sync/modules/browserid_identity.js +++ b/services/sync/modules/browserid_identity.js @@ -407,9 +407,8 @@ this.BrowserIDManager.prototype = { // field directly and instead call a isSyncKeyValid() function // that we can override. return "99999999999999999999999999"; - } else { - return null; } + return null; }, set syncKey(value) { diff --git a/services/sync/modules/service.js b/services/sync/modules/service.js index 0829441c11e3..489022a4e9e9 100644 --- a/services/sync/modules/service.js +++ b/services/sync/modules/service.js @@ -662,11 +662,9 @@ Sync11Service.prototype = { // 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); @@ -1222,20 +1220,19 @@ Sync11Service.prototype = { 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.verifyAndFetchSymmetricKeys(infoResponse)) { - this._log.warn("Failed to fetch symmetric keys. Failing remote setup."); - return false; - } - return true; } + 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; + } + + return true; }, /** diff --git a/services/sync/tests/unit/test_browserid_identity.js b/services/sync/tests/unit/test_browserid_identity.js index b7a9eedcb201..251000c7fea2 100644 --- a/services/sync/tests/unit/test_browserid_identity.js +++ b/services/sync/tests/unit/test_browserid_identity.js @@ -473,20 +473,19 @@ add_task(async function test_refreshCertificateOn401() { 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; diff --git a/services/sync/tps/extensions/tps/resource/modules/bookmarks.jsm b/services/sync/tps/extensions/tps/resource/modules/bookmarks.jsm index 15e773c3fd85..bbc7a43303c4 100644 --- a/services/sync/tps/extensions/tps/resource/modules/bookmarks.jsm +++ b/services/sync/tps/extensions/tps/resource/modules/bookmarks.jsm @@ -217,9 +217,8 @@ PlacesItem.prototype = { folder_parts[i]); if (subfolder_id == -1) { return -1; - } else { - folder_id = subfolder_id; } + folder_id = subfolder_id; } return folder_id; }, diff --git a/services/sync/tps/extensions/tps/resource/modules/forms.jsm b/services/sync/tps/extensions/tps/resource/modules/forms.jsm index a88aaf0e7527..31018c337e9e 100644 --- a/services/sync/tps/extensions/tps/resource/modules/forms.jsm +++ b/services/sync/tps/extensions/tps/resource/modules/forms.jsm @@ -167,12 +167,11 @@ FormData.prototype = { // 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. + */ }); },