From 19eccd05d689917d1be149ad5ebf4558f6832c1b Mon Sep 17 00:00:00 2001 From: Martin Tomes Date: Tue, 12 May 2015 13:45:07 +0100 Subject: [PATCH] Bug 1160496 - Enable eslint rules for Loop: General code format. r=Standard8 --- browser/components/loop/.eslintrc | 6 ------ browser/components/loop/content/js/contacts.js | 2 +- browser/components/loop/content/js/contacts.jsx | 2 +- browser/components/loop/content/js/roomViews.js | 3 ++- browser/components/loop/content/js/roomViews.jsx | 3 ++- .../loop/content/shared/js/activeRoomStore.js | 2 +- .../components/loop/content/shared/js/mixins.js | 10 ++++++---- .../components/loop/content/shared/js/validate.js | 15 +++++++++++---- .../components/loop/modules/GoogleImporter.jsm | 3 ++- browser/components/loop/modules/LoopCalls.jsm | 3 ++- .../components/loop/modules/MozLoopService.jsm | 7 ++++--- .../standalone/content/js/standaloneRoomViews.js | 3 ++- .../standalone/content/js/standaloneRoomViews.jsx | 3 ++- .../loop/test/desktop-local/client_test.js | 2 +- .../loop/test/desktop-local/contacts_test.js | 4 ++-- .../test/desktop-local/conversationViews_test.js | 5 +++-- .../loop/test/desktop-local/panel_test.js | 4 +++- browser/components/loop/test/mochitest/head.js | 6 ++++-- .../loop/test/shared/dispatcher_test.js | 6 +++--- browser/components/loop/test/shared/views_test.js | 6 ++++-- .../loop/test/standalone/multiplexGum_test.js | 2 +- .../loop/test/standalone/webapp_test.js | 6 ++++-- .../loop/test/xpcshell/test_looprooms.js | 12 ++++++------ 23 files changed, 67 insertions(+), 48 deletions(-) diff --git a/browser/components/loop/.eslintrc b/browser/components/loop/.eslintrc index 7b9ac8ed490f..ca48ffbcd328 100644 --- a/browser/components/loop/.eslintrc +++ b/browser/components/loop/.eslintrc @@ -35,9 +35,6 @@ // Eslint built-in rules are documented at "camelcase": 0, // TODO: Remove (use default) "consistent-return": 0, // TODO: Remove (use default) - "curly": 0, // TODO: Remove (use default) - "dot-notation": 0, // TODO: Remove (use default) - "eol-last": 0, // TODO: Remove (use default) "eqeqeq": 0, // TBD. Might need to be separate for content & chrome "global-strict": 0, // Leave as zero (this will be unsupported in eslint 1.0.0) "key-spacing": 0, // TODO: Remove (use default) @@ -60,10 +57,7 @@ "no-use-before-define": 0, // TODO: Remove (use default) "no-wrap-func": 0, // TODO: Remove (use default) "quotes": 0, // [2, "double", "avoid-escape"], - "space-infix-ops": 0, // TODO: Remove (use default) - "space-return-throw-case": 0, // TODO: Remove (use default) "strict": 0, // [2, "function"], - "yoda": 0, // [2, "never"], // eslint-plugin-react rules. These are documented at // "react/jsx-quotes": [2, "double", "avoid-escape"], diff --git a/browser/components/loop/content/js/contacts.js b/browser/components/loop/content/js/contacts.js index 32caed6c64bd..e717046a0ec6 100644 --- a/browser/components/loop/content/js/contacts.js +++ b/browser/components/loop/content/js/contacts.js @@ -693,7 +693,7 @@ loop.contacts = (function(_, mozL10n) { }; var tel = this.state.tel.trim(); if (!!tel) { - contact["tel"] = [{ + contact.tel = [{ pref: true, type: ["fxos"], value: tel diff --git a/browser/components/loop/content/js/contacts.jsx b/browser/components/loop/content/js/contacts.jsx index f45d66fd8fbe..22a2aea025a1 100644 --- a/browser/components/loop/content/js/contacts.jsx +++ b/browser/components/loop/content/js/contacts.jsx @@ -693,7 +693,7 @@ loop.contacts = (function(_, mozL10n) { }; var tel = this.state.tel.trim(); if (!!tel) { - contact["tel"] = [{ + contact.tel = [{ pref: true, type: ["fxos"], value: tel diff --git a/browser/components/loop/content/js/roomViews.js b/browser/components/loop/content/js/roomViews.js index c874cd5138ef..e36d7b204c36 100644 --- a/browser/components/loop/content/js/roomViews.js +++ b/browser/components/loop/content/js/roomViews.js @@ -461,8 +461,9 @@ loop.roomViews = (function(mozL10n) { }, render: function() { - if (!this.state.show && !this.state.editMode) + if (!this.state.show && !this.state.editMode) { return null; + } var url = this._getURL(); var thumbnail = url && url.thumbnail || ""; diff --git a/browser/components/loop/content/js/roomViews.jsx b/browser/components/loop/content/js/roomViews.jsx index 5e5f94e575ff..29e3b3cffcb2 100644 --- a/browser/components/loop/content/js/roomViews.jsx +++ b/browser/components/loop/content/js/roomViews.jsx @@ -461,8 +461,9 @@ loop.roomViews = (function(mozL10n) { }, render: function() { - if (!this.state.show && !this.state.editMode) + if (!this.state.show && !this.state.editMode) { return null; + } var url = this._getURL(); var thumbnail = url && url.thumbnail || ""; diff --git a/browser/components/loop/content/shared/js/activeRoomStore.js b/browser/components/loop/content/shared/js/activeRoomStore.js index 7f489b2724e9..ff6f304a65a7 100644 --- a/browser/components/loop/content/shared/js/activeRoomStore.js +++ b/browser/components/loop/content/shared/js/activeRoomStore.js @@ -464,7 +464,7 @@ loop.store.ActiveRoomStore = (function() { this._setRefreshTimeout(actionData.expires); // Only send media telemetry on one side of the call: the desktop side. - actionData["sendTwoWayMediaTelemetry"] = this._isDesktop; + actionData.sendTwoWayMediaTelemetry = this._isDesktop; this._sdkDriver.connectSession(actionData); diff --git a/browser/components/loop/content/shared/js/mixins.js b/browser/components/loop/content/shared/js/mixins.js index 83d715b19f21..bcd38c412a92 100644 --- a/browser/components/loop/content/shared/js/mixins.js +++ b/browser/components/loop/content/shared/js/mixins.js @@ -120,10 +120,12 @@ loop.shared.mixins = (function() { if (!menu) { return; } - if (menu.style.maxWidth) + if (menu.style.maxWidth) { menu.style.maxWidth = "none"; - if (menu.style.maxHeight) + } + if (menu.style.maxHeight) { menu.style.maxHeight = "none"; + } // Correct the position of the menu only if necessary. var x, y, boundingBox, boundingRect; @@ -453,7 +455,7 @@ loop.shared.mixins = (function() { remoteVideoDimensions.streamWidth = leadingAxis === "width" ? remoteVideoDimensions.width : slaveAxisSize; remoteVideoDimensions.streamHeight = leadingAxis === "height" ? - remoteVideoDimensions.height: slaveAxisSize; + remoteVideoDimensions.height : slaveAxisSize; } else { // If the leading axis is not "full" then we need to adjust it, based // on the length of the leading axis. @@ -462,7 +464,7 @@ loop.shared.mixins = (function() { remoteVideoDimensions.streamWidth = leadingAxis === "height" ? remoteVideoDimensions.width : leadingAxisSize; remoteVideoDimensions.streamHeight = leadingAxis === "width" ? - remoteVideoDimensions.height: leadingAxisSize; + remoteVideoDimensions.height : leadingAxisSize; } } } diff --git a/browser/components/loop/content/shared/js/validate.js b/browser/components/loop/content/shared/js/validate.js index 596089f4a537..33c12bcaa74c 100644 --- a/browser/components/loop/content/shared/js/validate.js +++ b/browser/components/loop/content/shared/js/validate.js @@ -29,12 +29,18 @@ loop.validate = (function() { * @return {String} */ function typeName(obj) { - if (obj === null) + if (obj === null) { return "null"; - if (typeof obj === "function") + } + + if (typeof obj === "function") { return obj.name || obj.toString().match(/^function\s?([^\s(]*)/)[1]; - if (typeof obj.constructor === "function") + } + + if (typeof obj.constructor === "function") { return typeName(obj.constructor); + } + return "unknown"; } @@ -93,8 +99,9 @@ loop.validate = (function() { return typeof values[name] !== "undefined"; }); var diff = difference(Object.keys(this.schema), definedProperties); - if (diff.length > 0) + if (diff.length > 0) { throw new TypeError("missing required " + diff.join(", ")); + } }, /** diff --git a/browser/components/loop/modules/GoogleImporter.jsm b/browser/components/loop/modules/GoogleImporter.jsm index af2734af252a..7bf52f00ba54 100644 --- a/browser/components/loop/modules/GoogleImporter.jsm +++ b/browser/components/loop/modules/GoogleImporter.jsm @@ -106,8 +106,9 @@ const getPreferred = function(contact, which = "email") { * @param {Boolean} encode Whether to URLEncode the param string */ const getUrlParam = function(paramValue, prefName, encode = true) { - if (Services.prefs.getPrefType(prefName)) + if (Services.prefs.getPrefType(prefName)) { paramValue = Services.prefs.getCharPref(prefName); + } paramValue = Services.urlFormatter.formatURL(paramValue); return encode ? encodeURIComponent(paramValue) : paramValue; diff --git a/browser/components/loop/modules/LoopCalls.jsm b/browser/components/loop/modules/LoopCalls.jsm index e55e26fd093e..9adf9b2a72c1 100644 --- a/browser/components/loop/modules/LoopCalls.jsm +++ b/browser/components/loop/modules/LoopCalls.jsm @@ -324,8 +324,9 @@ let LoopCallsInternal = { * @return true if the call is opened, false if it is not opened (i.e. busy) */ startDirectCall: function(contact, callType) { - if ("id" in this.conversationInProgress) + if ("id" in this.conversationInProgress) { return false; + } var callData = { contact: contact, diff --git a/browser/components/loop/modules/MozLoopService.jsm b/browser/components/loop/modules/MozLoopService.jsm index cb362724fd27..93157e00d02c 100644 --- a/browser/components/loop/modules/MozLoopService.jsm +++ b/browser/components/loop/modules/MozLoopService.jsm @@ -724,8 +724,9 @@ let MozLoopServiceInternal = { * @returns {Map} a map of element ids with localized string values */ get localizedStrings() { - if (gLocalizedStrings.size) + if (gLocalizedStrings.size) { return gLocalizedStrings; + } let stringBundle = Services.strings.createBundle("chrome://browser/locale/loop/loop.properties"); @@ -765,7 +766,7 @@ let MozLoopServiceInternal = { let ai = Services.appinfo; let uuid = uuidgen.generateUUID().toString(); - uuid = uuid.substr(1, uuid.length-2); // remove uuid curly braces + uuid = uuid.substr(1, uuid.length - 2); // remove uuid curly braces let directory = OS.Path.join(OS.Constants.Path.profileDir, "saved-telemetry-pings"); @@ -895,7 +896,7 @@ let MozLoopServiceInternal = { var pair = pc.id.split("("); //) if (pair.length == 2) { pc.id = pair[0] + "(session=" + context.sessionId + - (context.callId? " call=" + context.callId : "") + " " + pair[1]; //) + (context.callId ? " call=" + context.callId : "") + " " + pair[1]; //) } } diff --git a/browser/components/loop/standalone/content/js/standaloneRoomViews.js b/browser/components/loop/standalone/content/js/standaloneRoomViews.js index 911cd96183a8..2a37e47d9d5f 100644 --- a/browser/components/loop/standalone/content/js/standaloneRoomViews.js +++ b/browser/components/loop/standalone/content/js/standaloneRoomViews.js @@ -126,7 +126,7 @@ loop.standaloneRoomViews = (function(mozL10n) { ); } case ROOM_STATES.ENDED: { - if (this.props.roomUsed) + if (this.props.roomUsed) { return ( React.createElement("div", {className: "ended-conversation"}, React.createElement(sharedViews.FeedbackView, { @@ -134,6 +134,7 @@ loop.standaloneRoomViews = (function(mozL10n) { ) ) ); + } // In case the room was not used (no one was here), we // bypass the feedback form. diff --git a/browser/components/loop/standalone/content/js/standaloneRoomViews.jsx b/browser/components/loop/standalone/content/js/standaloneRoomViews.jsx index 12e9a7366516..13a56edc96fa 100644 --- a/browser/components/loop/standalone/content/js/standaloneRoomViews.jsx +++ b/browser/components/loop/standalone/content/js/standaloneRoomViews.jsx @@ -126,7 +126,7 @@ loop.standaloneRoomViews = (function(mozL10n) { ); } case ROOM_STATES.ENDED: { - if (this.props.roomUsed) + if (this.props.roomUsed) { return (
); + } // In case the room was not used (no one was here), we // bypass the feedback form. diff --git a/browser/components/loop/test/desktop-local/client_test.js b/browser/components/loop/test/desktop-local/client_test.js index 475fb0184546..d9df8fa1efd1 100644 --- a/browser/components/loop/test/desktop-local/client_test.js +++ b/browser/components/loop/test/desktop-local/client_test.js @@ -115,7 +115,7 @@ describe("loop.Client", function() { sinon.assert.calledOnce(callback); sinon.assert.calledWithExactly(callback, sinon.match(function(err) { - return err.code == 400 && "invalid token" == err.message; + return err.code == 400 && err.message == "invalid token"; })); }); diff --git a/browser/components/loop/test/desktop-local/contacts_test.js b/browser/components/loop/test/desktop-local/contacts_test.js index a88074d06179..d73130fc408f 100644 --- a/browser/components/loop/test/desktop-local/contacts_test.js +++ b/browser/components/loop/test/desktop-local/contacts_test.js @@ -476,7 +476,7 @@ describe("loop.contacts", function() { var contact = {fakeField: [{value: "foobar"}]}; loop.contacts._setPreferred(contact, "fakeField", ""); - expect(contact["fakeField"][0].value).to.eql(""); + expect(contact.fakeField[0].value).to.eql(""); }); it("should set the value on the object if the new value is empty," + @@ -484,7 +484,7 @@ describe("loop.contacts", function() { var contact = {fakeField: [{value: "foobar"}]}; loop.contacts._setPreferred(contact, "fakeField", "barbaz"); - expect(contact["fakeField"][0].value).to.eql("barbaz"); + expect(contact.fakeField[0].value).to.eql("barbaz"); }); }); }); diff --git a/browser/components/loop/test/desktop-local/conversationViews_test.js b/browser/components/loop/test/desktop-local/conversationViews_test.js index c108e7519450..eab9936b4a65 100644 --- a/browser/components/loop/test/desktop-local/conversationViews_test.js +++ b/browser/components/loop/test/desktop-local/conversationViews_test.js @@ -54,8 +54,9 @@ describe("loop.conversationViews", function () { send: function() {}, abort: function() {}, getResponseHeader: function(header) { - if (header === "Content-Type") + if (header === "Content-Type") { return "audio/ogg"; + } }, responseType: null, response: new ArrayBuffer(10), @@ -87,7 +88,7 @@ describe("loop.conversationViews", function () { }; sinon.stub(fakeMozLoop, "getLoopPref", function(pref) { if (pref === "fake") { - return"http://fakeurl"; + return "http://fakeurl"; } return false; diff --git a/browser/components/loop/test/desktop-local/panel_test.js b/browser/components/loop/test/desktop-local/panel_test.js index bc61a5858ca5..c8459e1f94bd 100644 --- a/browser/components/loop/test/desktop-local/panel_test.js +++ b/browser/components/loop/test/desktop-local/panel_test.js @@ -390,8 +390,10 @@ describe("loop.panel", function() { beforeEach(function() { supportUrl = "https://example.com"; navigator.mozLoop.getLoopPref = function(pref) { - if (pref === "support_url") + if (pref === "support_url") { return supportUrl; + } + return "unseen"; }; }); diff --git a/browser/components/loop/test/mochitest/head.js b/browser/components/loop/test/mochitest/head.js index 7364c61d0cd2..7ea962e1384f 100644 --- a/browser/components/loop/test/mochitest/head.js +++ b/browser/components/loop/test/mochitest/head.js @@ -240,14 +240,16 @@ function promiseTabLoadEvent(tab, url, eventType="load") { } let timeout = setTimeout(() => { - if (tab.linkedBrowser) + if (tab.linkedBrowser) { tab.linkedBrowser.removeEventListener(eventType, handle, true); + } reject(new Error("Timed out while waiting for a '" + eventType + "'' event")); }, 30000); tab.linkedBrowser.addEventListener(eventType, handle, true, true); - if (url) + if (url) { tab.linkedBrowser.loadURI(url); + } }); } diff --git a/browser/components/loop/test/shared/dispatcher_test.js b/browser/components/loop/test/shared/dispatcher_test.js index a84b08c59773..ba3c89e88bbe 100644 --- a/browser/components/loop/test/shared/dispatcher_test.js +++ b/browser/components/loop/test/shared/dispatcher_test.js @@ -24,7 +24,7 @@ describe("loop.Dispatcher", function () { dispatcher.register(object, ["getWindowData"]); - expect(dispatcher._eventData["getWindowData"][0]).eql(object); + expect(dispatcher._eventData.getWindowData[0]).eql(object); }); it("should register multiple store against an action name", function() { @@ -34,8 +34,8 @@ describe("loop.Dispatcher", function () { dispatcher.register(object1, ["getWindowData"]); dispatcher.register(object2, ["getWindowData"]); - expect(dispatcher._eventData["getWindowData"][0]).eql(object1); - expect(dispatcher._eventData["getWindowData"][1]).eql(object2); + expect(dispatcher._eventData.getWindowData[0]).eql(object1); + expect(dispatcher._eventData.getWindowData[1]).eql(object2); }); }); diff --git a/browser/components/loop/test/shared/views_test.js b/browser/components/loop/test/shared/views_test.js index 4b876c899427..296828dae8b1 100644 --- a/browser/components/loop/test/shared/views_test.js +++ b/browser/components/loop/test/shared/views_test.js @@ -33,8 +33,9 @@ describe("loop.shared.views", function() { send: function() {}, abort: function() {}, getResponseHeader: function(header) { - if (header === "Content-Type") + if (header === "Content-Type") { return "audio/ogg"; + } }, responseType: null, response: new ArrayBuffer(10), @@ -552,8 +553,9 @@ describe("loop.shared.views", function() { beforeEach(function() { // In standalone, navigator.mozLoop does not exists - if (navigator.hasOwnProperty("mozLoop")) + if (navigator.hasOwnProperty("mozLoop")) { sandbox.stub(navigator, "mozLoop", undefined); + } }); it("should play a connected sound, once, on session:connected", diff --git a/browser/components/loop/test/standalone/multiplexGum_test.js b/browser/components/loop/test/standalone/multiplexGum_test.js index 37c429b99ad3..1d7321482c84 100644 --- a/browser/components/loop/test/standalone/multiplexGum_test.js +++ b/browser/components/loop/test/standalone/multiplexGum_test.js @@ -13,7 +13,7 @@ describe("loop.standaloneMedia._MultiplexGum", function() { navigator.getUserMedia || navigator.mozGetUserMedia || navigator.webkitGetUserMedia || - (window["TBPlugin"] && TBPlugin.getUserMedia); + (window.TBPlugin && TBPlugin.getUserMedia); var sandbox; var multiplexGum; diff --git a/browser/components/loop/test/standalone/webapp_test.js b/browser/components/loop/test/standalone/webapp_test.js index e1568c5a5db0..2ed13bba2eeb 100644 --- a/browser/components/loop/test/standalone/webapp_test.js +++ b/browser/components/loop/test/standalone/webapp_test.js @@ -40,8 +40,9 @@ describe("loop.webapp", function() { send: function() {}, abort: function() {}, getResponseHeader: function(header) { - if (header === "Content-Type") + if (header === "Content-Type") { return "audio/ogg"; + } }, responseType: null, response: new ArrayBuffer(10), @@ -1013,8 +1014,9 @@ describe("loop.webapp", function() { }); afterEach(function() { - if (oldLocalStorageValue !== null) + if (oldLocalStorageValue !== null) { localStorage.setItem("has-seen-tos", oldLocalStorageValue); + } }); it("should show the TOS", function() { diff --git a/browser/components/loop/test/xpcshell/test_looprooms.js b/browser/components/loop/test/xpcshell/test_looprooms.js index 328a19c3a7bb..5dc67b0a9b21 100644 --- a/browser/components/loop/test/xpcshell/test_looprooms.js +++ b/browser/components/loop/test/xpcshell/test_looprooms.js @@ -462,7 +462,7 @@ add_task(function* test_refresh() { // Test if push updates function as expected. add_task(function* test_roomUpdates() { gExpectedUpdates.push("_nxD4V4FflQ"); - gExpectedLeaves["_nxD4V4FflQ"] = [ + gExpectedLeaves._nxD4V4FflQ = [ "2a1787a6-4a73-43b5-ae3e-906ec1e763cb", "781f012b-f1ea-4ce1-9105-7cfc36fb4ec7" ]; @@ -471,21 +471,21 @@ add_task(function* test_roomUpdates() { gExpectedUpdates.length === 0); gExpectedUpdates.push("_nxD4V4FflQ"); - gExpectedJoins["_nxD4V4FflQ"] = ["2a1787a6-4a73-43b5-ae3e-906ec1e763cb"]; + gExpectedJoins._nxD4V4FflQ = ["2a1787a6-4a73-43b5-ae3e-906ec1e763cb"]; roomsPushNotification("2", kChannelGuest); yield waitForCondition(() => Object.getOwnPropertyNames(gExpectedJoins).length === 0 && gExpectedUpdates.length === 0); gExpectedUpdates.push("_nxD4V4FflQ"); - gExpectedJoins["_nxD4V4FflQ"] = ["781f012b-f1ea-4ce1-9105-7cfc36fb4ec7"]; - gExpectedLeaves["_nxD4V4FflQ"] = ["2a1787a6-4a73-43b5-ae3e-906ec1e763cb"]; + gExpectedJoins._nxD4V4FflQ = ["781f012b-f1ea-4ce1-9105-7cfc36fb4ec7"]; + gExpectedLeaves._nxD4V4FflQ = ["2a1787a6-4a73-43b5-ae3e-906ec1e763cb"]; roomsPushNotification("3", kChannelGuest); yield waitForCondition(() => Object.getOwnPropertyNames(gExpectedLeaves).length === 0 && Object.getOwnPropertyNames(gExpectedJoins).length === 0 && gExpectedUpdates.length === 0); gExpectedUpdates.push("_nxD4V4FflQ"); - gExpectedJoins["_nxD4V4FflQ"] = [ + gExpectedJoins._nxD4V4FflQ = [ "2a1787a6-4a73-43b5-ae3e-906ec1e763cb", "5de6281c-6568-455f-af08-c0b0a973100e"]; roomsPushNotification("4", kChannelGuest); @@ -507,7 +507,7 @@ add_task(function* test_channelIdsRespected() { MozLoopServiceInternal.fxAOAuthProfile = { email: "fake@invalid.com" }; gExpectedUpdates.push("_nxD4V4FflQ"); - gExpectedLeaves["_nxD4V4FflQ"] = [ + gExpectedLeaves._nxD4V4FflQ = [ "2a1787a6-4a73-43b5-ae3e-906ec1e763cb", "5de6281c-6568-455f-af08-c0b0a973100e" ];