diff --git a/chat/components/src/imAccounts.js b/chat/components/src/imAccounts.js index a653878ae1..47eb850ebb 100644 --- a/chat/components/src/imAccounts.js +++ b/chat/components/src/imAccounts.js @@ -9,6 +9,7 @@ var { setTimeout, clearTimeout, executeSoon, + l10nHelper, } = ChromeUtils.import("resource:///modules/imXPCOMUtils.jsm"); var {Services} = ChromeUtils.import("resource:///modules/imServices.jsm"); var {GenericAccountPrototype, GenericAccountBuddyPrototype} = ChromeUtils.import("resource:///modules/jsProtoHelper.jsm"); @@ -581,11 +582,7 @@ imAccount.prototype = { }, get autoLogin() { - let autoLogin = true; - try { - autoLogin = this.prefBranch.getBoolPref(kPrefAccountAutoLogin); - } catch (e) { } - return autoLogin; + return this.prefBranch.getBoolPref(kPrefAccountAutoLogin, true); }, set autoLogin(val) { this.prefBranch.setBoolPref(kPrefAccountAutoLogin, val); diff --git a/chat/components/src/imConversations.js b/chat/components/src/imConversations.js index aece5c3bd6..11957b99c9 100644 --- a/chat/components/src/imConversations.js +++ b/chat/components/src/imConversations.js @@ -670,7 +670,7 @@ ConversationsService.prototype = { let normalizedName = aAccount.normalize(aName); for (let conv of this._prplConversations) { if (aAccount.normalize(conv.name) == normalizedName && - aAccount.numericId == aAccount.numericId && + aAccount.numericId == conv.account.numericId && conv.isChat == aIsChat) return conv; } diff --git a/chat/components/src/logger.js b/chat/components/src/logger.js index 2cc1516aa1..5bcf3eea20 100644 --- a/chat/components/src/logger.js +++ b/chat/components/src/logger.js @@ -5,11 +5,16 @@ var CC = Components.Constructor; var {Services} = ChromeUtils.import("resource:///modules/imServices.jsm"); -var {EmptyEnumerator, XPCOMUtils} = ChromeUtils.import("resource:///modules/imXPCOMUtils.jsm"); +var { + EmptyEnumerator, + l10nHelper, + XPCOMUtils, +} = ChromeUtils.import("resource:///modules/imXPCOMUtils.jsm"); var {GenericMessagePrototype} = ChromeUtils.import("resource:///modules/jsProtoHelper.jsm"); var {ClassInfo} = ChromeUtils.import("resource:///modules/imXPCOMUtils.jsm"); var {ToLocaleFormat} = ChromeUtils.import("resource:///modules/ToLocaleFormat.jsm"); var {OS} = ChromeUtils.import("resource://gre/modules/osfile.jsm"); +var {getHiddenHTMLWindow} = ChromeUtils.import("resource:///modules/hiddenWindow.jsm"); XPCOMUtils.defineLazyGetter(this, "_", () => l10nHelper("chrome://chat/locale/logger.properties") @@ -137,7 +142,9 @@ function getNewLogFileName(aFormat, aStartTime) { let minutes = offset % 60; offset = (offset - minutes) / 60; function twoDigits(aNumber) { - return aNumber == 0 ? "00" : aNumber < 10 ? "0" + aNumber : aNumber; + if (aNumber == 0) + return "00"; + return aNumber < 10 ? "0" + aNumber : aNumber; } if (!aFormat) aFormat = "txt"; @@ -167,7 +174,7 @@ LogWriter.prototype = { _messageCount: 0, format: "txt", encoder: new TextEncoder(), - startNewFile: function lw_startNewFile(aStartTime, aContinuedSession) { + startNewFile(aStartTime, aContinuedSession) { // We start a new log file every 1000 messages. The start time of this new // log file is the time of the next message. Since message times are in seconds, // if we receive 1000 messages within a second after starting the new file, @@ -210,10 +217,11 @@ LogWriter.prototype = { this._initialized.catch(aError => Cu.reportError("Failed to initialize log file:\n" + aError)); }, - _serialize: function cl_serialize(aString) { + _serialize(aString) { // TODO cleanup once bug 102699 is fixed let doc = getHiddenHTMLWindow().document; let div = doc.createElementNS("http://www.w3.org/1999/xhtml", "div"); + // eslint-disable-next-line no-unsanitized/property div.innerHTML = aString.replace(/\r?\n/g, "
").replace(/
/gi, "
"); const type = "text/plain"; let encoder = Cu.createDocumentEncoder(type); @@ -237,7 +245,7 @@ LogWriter.prototype = { kDayOverlapLimit: 3 * 60 * 60 * 1000, // - After every 1000 messages. kMessageCountLimit: 1000, - logMessage: function cl_logMessage(aMessage) { + logMessage(aMessage) { // aMessage.time is in seconds, we need it in milliseconds. let messageTime = aMessage.time * 1000; let messageMidnight = new Date(messageTime).setHours(0, 0, 0, 0); @@ -348,7 +356,7 @@ SystemLogWriter.prototype = { // has been written. _initialized: null, path: null, - logEvent: function sl_logEvent(aString) { + logEvent(aString) { let date = ToLocaleFormat("%x %X", new Date()); let lineToWrite = this.encoder.encode("---- " + aString + " @ " + date + " ----" + kLineBreak); @@ -712,7 +720,7 @@ Logger.prototype = { } return []; }, - getLogFromFile: function logger_getLogFromFile(aFilePath, aGroupByDay) { + getLogFromFile(aFilePath, aGroupByDay) { if (!aGroupByDay) return Promise.resolve(new Log(aFilePath)); let [targetDate] = getDateFromFilename(OS.Path.basename(aFilePath)); @@ -747,7 +755,7 @@ Logger.prototype = { }, // Creates and returns the appropriate LogEnumerator for the given log array // depending on aGroupByDay, or an EmptyEnumerator if the input array is empty. - _getEnumerator: function logger__getEnumerator(aLogArray, aGroupByDay) { + _getEnumerator(aLogArray, aGroupByDay) { let enumerator = aGroupByDay ? DailyLogEnumerator : LogEnumerator; return aLogArray.length ? new enumerator(aLogArray) : EmptyEnumerator; }, @@ -764,13 +772,11 @@ Logger.prototype = { await gFilePromises.get(path); return paths; }, - getLogsForAccountAndName: function logger_getLogsForAccountAndName(aAccount, - aNormalizedName, aGroupByDay) { + getLogsForAccountAndName(aAccount, aNormalizedName, aGroupByDay) { return this._getLogArray(aAccount, aNormalizedName) .then(aEntries => this._getEnumerator(aEntries, aGroupByDay)); }, - getLogsForAccountBuddy: function logger_getLogsForAccountBuddy(aAccountBuddy, - aGroupByDay) { + getLogsForAccountBuddy(aAccountBuddy, aGroupByDay) { return this.getLogsForAccountAndName(aAccountBuddy.account, aAccountBuddy.normalizedName, aGroupByDay); }, @@ -792,14 +798,13 @@ Logger.prototype = { } return this._getEnumerator(entries, aGroupByDay); }, - getLogsForConversation: function logger_getLogsForConversation(aConversation, - aGroupByDay) { + getLogsForConversation(aConversation, aGroupByDay) { let name = aConversation.normalizedName; if (convIsRealMUC(aConversation)) name += ".chat"; return this.getLogsForAccountAndName(aConversation.account, name, aGroupByDay); }, - getSystemLogsForAccount: function logger_getSystemLogsForAccount(aAccount) { + getSystemLogsForAccount(aAccount) { return this.getLogsForAccountAndName(aAccount, ".system"); }, async getSimilarLogs(aLog, aGroupByDay) { @@ -884,7 +889,7 @@ Logger.prototype = { } }, - observe: function logger_observe(aSubject, aTopic, aData) { + observe(aSubject, aTopic, aData) { switch (aTopic) { case "profile-after-change": Services.obs.addObserver(this, "final-ui-startup"); diff --git a/chat/components/src/smileProtocolHandler.js b/chat/components/src/smileProtocolHandler.js index aee274f28c..db606cfc92 100644 --- a/chat/components/src/smileProtocolHandler.js +++ b/chat/components/src/smileProtocolHandler.js @@ -23,19 +23,19 @@ smileProtocolHandler.prototype = { Ci.nsIProtocolHandler.URI_NOAUTH | Ci.nsIProtocolHandler.URI_IS_UI_RESOURCE | Ci.nsIProtocolHandler.URI_IS_LOCAL_RESOURCE, - newURI: function SPH_newURI(aSpec, aOriginCharset, aBaseURI) { + newURI(aSpec, aOriginCharset, aBaseURI) { let mutator = Cc["@mozilla.org/network/simple-uri-mutator;1"] .createInstance(Ci.nsIURIMutator); return mutator.setSpec(aSpec).finalize(); }, - newChannel: function SPH_newChannel2(aURI, aLoadInfo) { + newChannel(aURI, aLoadInfo) { let smile = aURI.spec.replace(kSmileRegexp, ""); let uri = Services.io.newURI(getSmileRealURI(smile)); let channel = Services.io.newChannelFromURIWithLoadInfo(uri, aLoadInfo); channel.originalURI = aURI; return channel; }, - allowPort: function SPH_allowPort(aPort, aScheme) { return false; }, + allowPort(aPort, aScheme) { return false; }, classDescription: "Smile Protocol Handler", classID: Components.ID("{04e58eae-dfbc-4c9e-8130-6d9ef19cbff4}"), diff --git a/chat/components/src/test/test_accounts.js b/chat/components/src/test/test_accounts.js index 949762353a..9f32ec3939 100644 --- a/chat/components/src/test/test_accounts.js +++ b/chat/components/src/test/test_accounts.js @@ -2,7 +2,6 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -var {XPCOMUtils} = ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm"); var {Services} = ChromeUtils.import("resource:///modules/imServices.jsm"); const {updateAppInfo} = ChromeUtils.import("resource://testing-common/AppInfo.jsm"); diff --git a/chat/components/src/test/test_conversations.js b/chat/components/src/test/test_conversations.js index c75e0196f3..c58aac1203 100644 --- a/chat/components/src/test/test_conversations.js +++ b/chat/components/src/test/test_conversations.js @@ -3,16 +3,8 @@ var {Services} = ChromeUtils.import("resource:///modules/imServices.jsm"); var { - GenericAccountPrototype, - GenericAccountBuddyPrototype, GenericConvIMPrototype, - GenericConvChatPrototype, - GenericConvChatBuddyPrototype, - GenericConversationPrototype, - GenericMessagePrototype, - GenericProtocolPrototype, Message, - TooltipInfo, } = ChromeUtils.import("resource:///modules/jsProtoHelper.jsm"); var imConversations = {}; diff --git a/chat/components/src/test/test_logger.js b/chat/components/src/test/test_logger.js index 2b5c0b9bec..6bfc91394c 100644 --- a/chat/components/src/test/test_logger.js +++ b/chat/components/src/test/test_logger.js @@ -5,17 +5,6 @@ do_get_profile(); var {Services} = ChromeUtils.import("resource:///modules/imServices.jsm"); -var { - XPCOMUtils, - setTimeout, - clearTimeout, - executeSoon, - nsSimpleEnumerator, - EmptyEnumerator, - ClassInfo, - l10nHelper, - initLogModule, -} = ChromeUtils.import("resource:///modules/imXPCOMUtils.jsm"); const {OS} = ChromeUtils.import("resource://gre/modules/osfile.jsm"); var gLogger = {}; @@ -41,8 +30,6 @@ var dummyTwitterAccount = { }, }; -var test_accounts = [dummyAccount, dummyTwitterAccount]; - var dummyConv = { account: dummyAccount, id: 0, @@ -84,8 +71,6 @@ var dummyTwitterConv = { isChat: true, }; -var test_convs = [dummyConv, dummyMUC, dummyTwitterConv]; - var encodeName_input = [ "CON", "PRN", @@ -177,12 +162,10 @@ var encodeName_output = [ "%2afile", "%26file", "%25file", - "%5c" + "fi" + "%3f%2a%26%25" + "le" + "%3c%3e", + "%5c" + "fi" + "%3f%2a%26%25" + "le" + "%3c%3e", // eslint-disable-line no-useless-concat ]; var test_queueFileOperation = async function() { - let dummyOperation = function() {}; - let dummyRejectedOperation = () => Promise.reject("Rejected!"); let dummyResolvedOperation = () => Promise.resolve("Resolved!"); diff --git a/chat/content/account.xml b/chat/content/account.xml index 9dd93bd739..9fd5382e31 100644 --- a/chat/content/account.xml +++ b/chat/content/account.xml @@ -3,6 +3,7 @@ - License, v. 2.0. If a copy of the MPL was not distributed with this - file, You can obtain one at http://mozilla.org/MPL/2.0/. --> + @@ -139,10 +140,10 @@ let [val1, unit1, val2, unit2] = DownloadUtils.convertTimeUnits(date); if (!val2) reconnect = bundle.getFormattedString("account.reconnectInSingle", - [val1, unit1]) + [val1, unit1]); else reconnect = bundle.getFormattedString("account.reconnectInDouble", - [val1, unit1, val2, unit2]) + [val1, unit1, val2, unit2]); } document.getAnonymousElementByAttribute(this, "anonid", "reconnect") .textContent = reconnect; @@ -168,10 +169,10 @@ let [val1, unit1, val2, unit2] = DownloadUtils.convertTimeUnits(date); if (!val2) value = bundle.getFormattedString("account.connectedForSingle", - [val1, unit1]) + [val1, unit1]); else value = bundle.getFormattedString("account.connectedForDouble", - [val1, unit1, val2, unit2]) + [val1, unit1, val2, unit2]); } else value = bundle.getString("account.connectedForSeconds"); diff --git a/chat/content/conversation-browser.js b/chat/content/conversation-browser.js index debdfe76f7..6060472ffd 100644 --- a/chat/content/conversation-browser.js +++ b/chat/content/conversation-browser.js @@ -6,9 +6,17 @@ /* global MozXULElement */ -var { initHTMLDocument, serializeSelection, getCurrentTheme, isNextMessage, getHTMLForMessage, insertHTMLForMessage } = ChromeUtils.import("resource:///modules/imThemes.jsm"); -var { smileTextNode } = ChromeUtils.import("resource:///modules/imSmileys.jsm"); -var { cleanupImMarkup } = ChromeUtils.import("resource:///modules/imContentSink.jsm"); +var {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm"); +var { + initHTMLDocument, + serializeSelection, + getCurrentTheme, + isNextMessage, + getHTMLForMessage, + insertHTMLForMessage, +} = ChromeUtils.import("resource:///modules/imThemes.jsm"); +var {smileTextNode} = ChromeUtils.import("resource:///modules/imSmileys.jsm"); +var {cleanupImMarkup} = ChromeUtils.import("resource:///modules/imContentSink.jsm"); (function() { // is lazily set up through setElementCreationCallback, diff --git a/chat/modules/DNS.jsm b/chat/modules/DNS.jsm index b04c61d86e..72aa9b0fb3 100644 --- a/chat/modules/DNS.jsm +++ b/chat/modules/DNS.jsm @@ -291,6 +291,8 @@ function TXTRecord(aData) { } if (typeof Components === "undefined") { + /* eslint-env worker */ + // We are in a worker, wait for our message then execute the wanted method. importScripts("resource://gre/modules/workers/require.js"); let PromiseWorker = require("resource://gre/modules/workers/PromiseWorker.js"); @@ -298,7 +300,7 @@ if (typeof Components === "undefined") { let worker = new PromiseWorker.AbstractWorker(); worker.dispatch = function(aMethod, aArgs = []) { return self[aMethod](...aArgs); - }, + }; worker.postMessage = function(...aArgs) { self.postMessage(...aArgs); }; @@ -307,6 +309,7 @@ if (typeof Components === "undefined") { }; self.addEventListener("message", msg => worker.handleMessage(msg)); + // eslint-disable-next-line no-unused-vars function execute(aOS, aMethod, aArgs) { let DNS = (aOS == "WINNT" ? new load_dnsapi() : new load_libresolv()); return DNS[aMethod].apply(DNS, aArgs); diff --git a/chat/modules/ToLocaleFormat.jsm b/chat/modules/ToLocaleFormat.jsm index c8ccf31205..38ca18f3b6 100644 --- a/chat/modules/ToLocaleFormat.jsm +++ b/chat/modules/ToLocaleFormat.jsm @@ -45,7 +45,7 @@ function weekNumber(aDate, weekStart) { if (weekStart) { day = (day || 7) - weekStart; } - return Math.max(Math.floor((DayWithinYear(t) + 7 - day) / 7), 0); + return Math.max(Math.floor((DayWithinYear(aDate) + 7 - day) / 7), 0); } function weekNumberISO(t) { let thisWeek = weekNumber(1, t); diff --git a/chat/modules/imContentSink.jsm b/chat/modules/imContentSink.jsm index cd00d52618..e0349f16c2 100644 --- a/chat/modules/imContentSink.jsm +++ b/chat/modules/imContentSink.jsm @@ -3,7 +3,6 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ const {Services} = ChromeUtils.import("resource:///modules/imServices.jsm"); -Cu.importGlobalProperties(["DOMParser"]); this.EXPORTED_SYMBOLS = [ "cleanupImMarkup", // used to clean up incoming IMs. @@ -175,7 +174,7 @@ function initGlobalRuleset() } var styleObserver = { - observe: function so_observe(aObject, aTopic, aMsg) { + observe(aObject, aTopic, aMsg) { if (aTopic != "nsPref:changed" || aMsg != kModePref) throw "bad notification"; @@ -262,7 +261,7 @@ function cleanupNode(aNode, aRules, aTextModifiers) else { // this node is not allowed, replace it with its children while (node.hasChildNodes()) - aNode.insertBefore(node.removeChild(node.firstChild), node); + aNode.insertBefore(node.firstChild, node); } aNode.removeChild(node); // We want to process again the node at the index i which is diff --git a/chat/modules/imSmileys.jsm b/chat/modules/imSmileys.jsm index d696d5a788..ec4bbc4636 100644 --- a/chat/modules/imSmileys.jsm +++ b/chat/modules/imSmileys.jsm @@ -35,11 +35,11 @@ Object.defineProperty(this, "gTheme", { }); var gPrefObserver = { - init: function po_init() { + init() { Services.prefs.addObserver(kEmoticonsThemePref, gPrefObserver); }, - observe: function so_observe(aObject, aTopic, aMsg) { + observe(aObject, aTopic, aMsg) { if (aTopic != "nsPref:changed" || aMsg != kEmoticonsThemePref) throw "bad notification"; @@ -49,9 +49,7 @@ var gPrefObserver = { function getSmileRealURI(aSmile) { - aSmile = Cc["@mozilla.org/intl/texttosuburi;1"] - .getService(Ci.nsITextToSubURI) - .unEscapeURIForUI("UTF-8", aSmile); + aSmile = Services.textToSubURI.unEscapeURIForUI("UTF-8", aSmile); if (aSmile in gTheme.iconsHash) return gTheme.baseUri + gTheme.iconsHash[aSmile].filename; @@ -228,6 +226,7 @@ function smileImMarkup(aDocument, aText) return aText; let div = aDocument.createElement("div"); + // eslint-disable-next-line no-unsanitized/property div.innerHTML = aText; smileNode(div); return div.innerHTML; diff --git a/chat/modules/imStatusUtils.jsm b/chat/modules/imStatusUtils.jsm index f96056ffba..2abbc3ff18 100644 --- a/chat/modules/imStatusUtils.jsm +++ b/chat/modules/imStatusUtils.jsm @@ -6,16 +6,8 @@ this.EXPORTED_SYMBOLS = ["Status"]; var { XPCOMUtils, - setTimeout, - clearTimeout, - executeSoon, - nsSimpleEnumerator, - EmptyEnumerator, - ClassInfo, l10nHelper, - initLogModule, } = ChromeUtils.import("resource:///modules/imXPCOMUtils.jsm"); -var {Services} = ChromeUtils.import("resource:///modules/imServices.jsm"); XPCOMUtils.defineLazyGetter(this, "_", () => l10nHelper("chrome://chat/locale/status.properties") diff --git a/chat/modules/imThemes.jsm b/chat/modules/imThemes.jsm index 059f6f13e8..ed8907610a 100644 --- a/chat/modules/imThemes.jsm +++ b/chat/modules/imThemes.jsm @@ -17,7 +17,6 @@ this.EXPORTED_SYMBOLS = [ const {Services} = ChromeUtils.import("resource:///modules/imServices.jsm"); const {DownloadUtils} = ChromeUtils.import("resource://gre/modules/DownloadUtils.jsm"); const {XPCOMUtils} = ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm"); -Cu.importGlobalProperties(["DOMParser", "Element"]); var kMessagesStylePrefBranch = "messenger.options.messagesStyle."; var kThemePref = "theme"; @@ -539,6 +538,7 @@ function insertHTMLForMessage(aMsg, aHTML, aDoc, aIsNext) let range = aDoc.createRange(); let parent = insert ? insert.parentNode : aDoc.getElementById("Chat"); range.selectNode(parent); + // eslint-disable-next-line no-unsanitized/method let documentFragment = range.createContextualFragment(aHTML); let result = documentFragment.firstChild; @@ -894,6 +894,7 @@ SelectedMessage.prototype = { } else { let div = this._rootNodes[0].ownerDocument.createElement("div"); + // eslint-disable-next-line no-unsanitized/property div.innerHTML = msg.autoResponse ? formatAutoResponce(msg.message) : msg.message; text = serializeNode(div); } diff --git a/chat/modules/imXPCOMUtils.jsm b/chat/modules/imXPCOMUtils.jsm index 9821488502..1942cf14c6 100644 --- a/chat/modules/imXPCOMUtils.jsm +++ b/chat/modules/imXPCOMUtils.jsm @@ -94,7 +94,7 @@ function initLogModule(aModule, aObj = {}) aObj.ERROR = scriptError.bind(aObj, aModule, Ci.imIDebugMessage.LEVEL_ERROR); return aObj; } -XPCOMUtils.defineLazyGetter(Cu.getGlobalForObject({}), "gLogLevels", function() { +XPCOMUtils.defineLazyGetter(this, "gLogLevels", function() { // This object functions both as an obsever as well as a dict keeping the // log levels with prefs; the log levels all start with "level" (i.e. "level" // for the global level, "level.irc" for the IRC module). The dual-purpose diff --git a/chat/modules/jsProtoHelper.jsm b/chat/modules/jsProtoHelper.jsm index 59156cc981..3586c0f5c0 100644 --- a/chat/modules/jsProtoHelper.jsm +++ b/chat/modules/jsProtoHelper.jsm @@ -32,7 +32,7 @@ XPCOMUtils.defineLazyGetter(this, "_", () => var GenericAccountPrototype = { __proto__: ClassInfo("prplIAccount", "generic account object"), get wrappedJSObject() { return this; }, - _init: function _init(aProtocol, aImAccount) { + _init(aProtocol, aImAccount) { this.protocol = aProtocol; this.imAccount = aImAccount; initLogModule(aProtocol.id, this); diff --git a/chat/modules/socket.jsm b/chat/modules/socket.jsm index d03e4b96f4..76a4e2f3f2 100644 --- a/chat/modules/socket.jsm +++ b/chat/modules/socket.jsm @@ -90,12 +90,8 @@ var {getHiddenHTMLWindow} = ChromeUtils.import("resource:///modules/hiddenWindow // Network errors see: xpcom/base/nsError.h var NS_ERROR_MODULE_NETWORK = 2152398848; -var NS_ERROR_CONNECTION_REFUSED = NS_ERROR_MODULE_NETWORK + 13; var NS_ERROR_NET_TIMEOUT = NS_ERROR_MODULE_NETWORK + 14; var NS_ERROR_NET_RESET = NS_ERROR_MODULE_NETWORK + 20; -var NS_ERROR_UNKNOWN_HOST = NS_ERROR_MODULE_NETWORK + 30; -var NS_ERROR_UNKNOWN_PROXY_HOST = NS_ERROR_MODULE_NETWORK + 42; -var NS_ERROR_PROXY_CONNECTION_REFUSED = NS_ERROR_MODULE_NETWORK + 72; var BinaryInputStream = Components.Constructor("@mozilla.org/binaryinputstream;1", diff --git a/chat/modules/test/test_filtering.js b/chat/modules/test/test_filtering.js index b40969c2c0..d78358d2cd 100644 --- a/chat/modules/test/test_filtering.js +++ b/chat/modules/test/test_filtering.js @@ -143,8 +143,8 @@ function test_standardMode() { } // Remove font settings - let string = "foo"; - Assert.equal("foo", cleanupImMarkup(string)); + let font_string = "foo"; + Assert.equal("foo", cleanupImMarkup(font_string)); // Discard hr Assert.equal("foobar", cleanupImMarkup("foo
bar")); @@ -211,8 +211,8 @@ function test_permissiveMode() { } // Allow hr - let string = "foo
bar"; - Assert.equal(string, cleanupImMarkup(string)); + let hr_string = "foo
bar"; + Assert.equal(hr_string, cleanupImMarkup(hr_string)); // Allow most CSS rules changing the text appearance. const okCSS = [ diff --git a/chat/protocols/irc/irc.js b/chat/protocols/irc/irc.js index e9acec7a9e..aadb47a8cf 100644 --- a/chat/protocols/irc/irc.js +++ b/chat/protocols/irc/irc.js @@ -8,13 +8,13 @@ var { EmptyEnumerator, setTimeout, executeSoon, + l10nHelper, XPCOMUtils, nsSimpleEnumerator, } = ChromeUtils.import("resource:///modules/imXPCOMUtils.jsm"); var {Services} = ChromeUtils.import("resource:///modules/imServices.jsm"); var { _, - _conv, ctcpFormatToText, ctcpFormatToHTML, conversationErrorMessage, @@ -42,6 +42,10 @@ ChromeUtils.defineModuleGetter(this, "PluralForm", ChromeUtils.defineModuleGetter(this, "DownloadUtils", "resource://gre/modules/DownloadUtils.jsm"); +XPCOMUtils.defineLazyGetter(this, "_conv", () => + l10nHelper("chrome://chat/locale/conversations.properties") +); + /* * Parses a raw IRC message into an object (see section 2.3 of RFC 2812). This * returns an object with the following fields: @@ -738,6 +742,7 @@ ircSocket.prototype = { // \020 with a \0, \n, \r or \020, respectively. Any other character is // replaced with itself. const lowDequote = {"0": "\0", "n": "\n", "r": "\r", "\x10": "\x10"}; + // eslint-disable-next-line no-control-regex let dequotedMessage = aRawMessage.replace(/\x10./g, aStr => lowDequote[aStr[1]] || aStr[1]); @@ -759,7 +764,7 @@ ircSocket.prototype = { } }, onConnection() { - this._account._connectionRegistration.call(this._account); + this._account._connectionRegistration(); }, disconnect() { if (!this._account) @@ -993,14 +998,14 @@ ircAccount.prototype = { _userModeReceived: false, setUserMode(aNick, aNewModes, aSetter, aDisplayFullMode) { if (this.normalizeNick(aNick) != this.normalizeNick(this._nickname)) { - WARN("Received unexpected mode for " + aNick); + this.WARN("Received unexpected mode for " + aNick); return false; } // Are modes being added or removed? let addNewMode = aNewModes[0] == "+"; if (!addNewMode && aNewModes[0] != "-") { - WARN("Invalid mode string: " + aNewModes); + this.WARN("Invalid mode string: " + aNewModes); return false; } _setMode.call(this, addNewMode, aNewModes.slice(1)); @@ -1223,7 +1228,9 @@ ircAccount.prototype = { let sortWithoutPrefix = function(a, b) { a = this.normalize(a, prefixes); b = this.normalize(b, prefixes); - return a < b ? -1 : a > b ? 1 : 0; + if (a < b) + return -1; + return a > b ? 1 : 0; }.bind(this); let sortChannels = channels => channels.trim().split(/\s+/).sort(sortWithoutPrefix).join(" "); @@ -1509,13 +1516,17 @@ ircAccount.prototype = { // Count the number of bytes in a UTF-8 encoded string. function charCodeToByteCount(c) { // UTF-8 stores: - // - code points below U+0080 on 1 byte, - // - code points below U+0800 on 2 bytes, + // - code points below U+0080 are 1 byte, + // - code points below U+0800 are 2 bytes, // - code points U+D800 through U+DFFF are UTF-16 surrogate halves // (they indicate that JS has split a 4 bytes UTF-8 character // in two halves of 2 bytes each), - // - other code points on 3 bytes. - return c < 0x80 ? 1 : (c < 0x800 || (c >= 0xD800 && c <= 0xDFFF)) ? 2 : 3; + // - other code points are 3 bytes. + if (c < 0x80) + return 1; + if (c < 0x800 || (c >= 0xD800 && c <= 0xDFFF)) + return 2; + return 3; } let bytes = 0; for (let i = 0; i < aStr.length; i++) @@ -1849,6 +1860,7 @@ ircAccount.prototype = { // High/CTCP level quoting, replace \134 or \001 with \134\134 or \134a, // respectively. This is only done inside the extended data message. + // eslint-disable-next-line no-control-regex const highRegex = /\\|\x01/g; ircParam = ircParam.replace(highRegex, aChar => "\\" + (aChar == "\\" ? "\\" : "a")); diff --git a/chat/protocols/irc/ircCTCP.jsm b/chat/protocols/irc/ircCTCP.jsm index d2ef4cd079..2983b55f9a 100644 --- a/chat/protocols/irc/ircCTCP.jsm +++ b/chat/protocols/irc/ircCTCP.jsm @@ -26,7 +26,11 @@ function CTCPMessage(aMessage, aRawCTCPMessage) { // with \001 or \134, respectively. Any other character after \134 is replaced // with itself. let dequotedCTCPMessage = message.ctcp.rawMessage.replace(/\\(.|$)/g, - aStr => aStr[1] ? (aStr[1] == "a" ? "\x01" : aStr[1]) : ""); + aStr => { + if (aStr[1]) + return aStr[1] == "a" ? "\x01" : aStr[1]; + return ""; + }); let separator = dequotedCTCPMessage.indexOf(" "); // If there's no space, then only a command is given. @@ -68,6 +72,7 @@ function ctcpHandleMessage(aMessage) { // Split the raw message into the multiple CTCP messages and pull out the // command and parameters. let ctcpMessages = []; + // eslint-disable-next-line no-control-regex let otherMessage = rawCTCPParam.replace(/\x01([^\x01]*)\x01/g, function(aMatch, aMsg) { if (aMsg) diff --git a/chat/protocols/irc/ircCommands.jsm b/chat/protocols/irc/ircCommands.jsm index 8c24f19526..14d61eeb38 100644 --- a/chat/protocols/irc/ircCommands.jsm +++ b/chat/protocols/irc/ircCommands.jsm @@ -346,6 +346,7 @@ var commands = [ get helpString() { return _("command.nick", "nick"); }, run(aMsg, aConv) { let newNick = aMsg.trim(); + // eslint-disable-next-line mozilla/use-includes-instead-of-indexOf if (newNick.indexOf(/\s+/) != -1) return false; diff --git a/chat/protocols/irc/ircUtils.jsm b/chat/protocols/irc/ircUtils.jsm index e28acb536c..848a46b720 100644 --- a/chat/protocols/irc/ircUtils.jsm +++ b/chat/protocols/irc/ircUtils.jsm @@ -2,7 +2,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -this.EXPORTED_SYMBOLS = ["_", "_conv", "ctcpFormatToText", "ctcpFormatToHTML", +this.EXPORTED_SYMBOLS = ["_", "ctcpFormatToText", "ctcpFormatToHTML", "conversationErrorMessage", "kListRefreshInterval"]; var { @@ -14,10 +14,6 @@ XPCOMUtils.defineLazyGetter(this, "_", () => l10nHelper("chrome://chat/locale/irc.properties") ); -XPCOMUtils.defineLazyGetter(this, "_conv", () => - l10nHelper("chrome://chat/locale/conversations.properties") -); - XPCOMUtils.defineLazyGetter(this, "TXTToHTML", function() { let cs = Cc["@mozilla.org/txttohtmlconv;1"].getService(Ci.mozITXTToHTMLConv); return aTXT => cs.scanTXT(aTXT, cs.kEntities); @@ -40,12 +36,14 @@ var kListRefreshInterval = 12 * 60 * 60 * 1000; // 12 hours. * The number of characters (from the start of the input string) that the * function handled. */ -var CTCP_TAGS = {"\x02": "b", // \002, ^B, Bold - "\x16": "i", // \026, ^V, Reverse or Inverse (Italics) - "\x1D": "i", // \035, ^], Italics (mIRC) - "\x1F": "u", // \037, ^_, Underline - "\x03": mIRCColoring, // \003, ^C, Coloring - "\x0F": null}; // \017, ^O, Clear all formatting +var CTCP_TAGS = { + "\x02": "b", // \002, ^B, Bold + "\x16": "i", // \026, ^V, Reverse or Inverse (Italics) + "\x1D": "i", // \035, ^], Italics (mIRC) + "\x1F": "u", // \037, ^_, Underline + "\x03": mIRCColoring, // \003, ^C, Coloring + "\x0F": null, // \017, ^O, Clear all formatting +}; // Generate an expression that will search for any of the control characters. var CTCP_TAGS_EXP = new RegExp("[" + Object.keys(CTCP_TAGS).join("") + "]"); @@ -140,6 +138,7 @@ function ctcpFormatToHTML(aString) { // mIRC colors are defined at http://www.mirc.com/colors.html. // This expression matches \003[,]. +// eslint-disable-next-line no-control-regex var M_IRC_COLORS_EXP = /^\x03(?:(\d\d?)(?:,(\d\d?))?)?/; var M_IRC_COLOR_MAP = { "0": "white", diff --git a/chat/protocols/irc/test/test_ircCommands.js b/chat/protocols/irc/test/test_ircCommands.js index c6685eb3ec..dcf4d196f3 100644 --- a/chat/protocols/irc/test/test_ircCommands.js +++ b/chat/protocols/irc/test/test_ircCommands.js @@ -202,4 +202,5 @@ function _getRunCommand(aCommandName) { // Fail if no command was found. ok(false, "Could not find the '" + aCommandName + "' command."); + return null; // Shut-up eslint. } diff --git a/chat/protocols/xmpp/xmpp.jsm b/chat/protocols/xmpp/xmpp.jsm index fbb9334f23..05c099905b 100644 --- a/chat/protocols/xmpp/xmpp.jsm +++ b/chat/protocols/xmpp/xmpp.jsm @@ -1674,26 +1674,6 @@ var XMPPAccountPrototype = { }; }, - // Send an error stanza in response to the given stanza (rfc6120#8.3). - // aCondition is the name of the defined-condition child, aText an - // optional plain-text description. - sendErrorStanza(aStanza, aCondition, aType, aText) { - // TODO: Support the other stanza types (message, presence). - let qName = aStanza.qName; - if (qName != "iq") { - this.ERROR(`Sending an error stanza for a ${qName} stanza is not ` + - `implemented yet.`); - return; - } - - let error = Stanza.node("error", null, {type: aType}, - Stanza.node(aCondition, Stanza.NS.stanzas)); - if (aText) - error.addChild(Stanza.node("text", Stanza.NS.stanzas, null, aText)); - return this.sendStanza(Stanza.iq("error", aStanza.attributes.id, - aStanza.attributes.from, error)); - }, - // Returns a callback suitable for use in sendStanza, to handle type==result // responses. aHandlers and aThis are passed on to handleErrors for error // handling. @@ -1952,15 +1932,13 @@ var XMPPAccountPrototype = { let query = aStanza.getElement(["query"]); if (!query || query.uri != Stanza.NS.disco_items) { this.LOG("Could not get rooms for this server: " + this._jid.domain); - return true; + return; } // XEP-0059: Result Set Management. let set = query.getElement(["set"]); let last = set ? set.getElement(["last"]) : null; if (last) { - let after = Stanza.node("after", null, null, last.innerText); - let setNode = Stanza.node("set", Stanza.NS.rsm, null, after); let iq = Stanza.iq("get", null, this._mucService, Stanza.node("query", Stanza.NS.disco_items)); this.sendStanza(iq, this.onRoomDiscovery, this);