Bug 1478572 - Turn on ESLint in mail/components/about-support. r=jorgk
authorGeoff Lankow <geoff@darktrojan.net>
Thu, 26 Jul 2018 22:57:39 +1200
changeset 32690 fe8684d0f25a39d5c63a87f1af8c465750641d74
parent 32689 e9b4a9b6c5ce87ac5e4956a2843f9b43a3cdc44c
child 32691 b7949186a806eac7fac035adf1e0972bcdb2d38f
push id386
push userclokep@gmail.com
push dateTue, 23 Oct 2018 00:48:12 +0000
reviewersjorgk
bugs1478572
Bug 1478572 - Turn on ESLint in mail/components/about-support. r=jorgk
.eslintignore
.eslintrc.js
mail/components/about-support/aboutSupportUnix.js
mail/components/about-support/aboutSupportWin32.js
mail/components/about-support/content/aboutSupport.js
mail/components/about-support/content/accounts.js
mail/components/about-support/content/export.js
--- a/.eslintignore
+++ b/.eslintignore
@@ -35,16 +35,17 @@ mail/config/**
 mail/extensions/**
 mail/installer/**
 mail/locales/**
 mail/test/**
 mail/themes/**
 
 # mail/components exclusions
 mail/components/*
+!mail/components/about-support
 !mail/components/extensions
 
 # calendar/ exclusions
 
 # prefs files
 calendar/lightning/content/lightning.js
 calendar/locales/en-US/lightning-l10n.js
 
--- a/.eslintrc.js
+++ b/.eslintrc.js
@@ -13,17 +13,18 @@ module.exports = {
   // When adding items to this file please check for effects on sub-directories.
   "plugins": [
     "mozilla"
   ],
 
   "rules": {
     // XXX We are waiting for m-c to create a script to fix these in bug 1433175.
     // Disabling this rule as part of bug 1436605 until that is the case.
-    "mozilla/use-cc-etc": "off"
+    "mozilla/use-cc-etc": "off",
+    "no-multi-spaces": ["error", { ignoreEOLComments: true }],
   },
 
   // The html plugin is enabled via a command line option on eslint. To avoid
   // bad interactions with the xml preprocessor in eslint-plugin-mozilla, we
   // turn off processing of the html plugin for .xml files.
   "settings": {
     "html/xml-extensions": [ ".xhtml" ]
   },
--- a/mail/components/about-support/aboutSupportUnix.js
+++ b/mail/components/about-support/aboutSupportUnix.js
@@ -104,20 +104,18 @@ var AboutSupportPlatform = {
         ctypes.char.ptr  // in: attribute
       );
       let fsType = g_file_info_get_attribute_string(
         glibFileInfo, G_FILE_ATTRIBUTE_FILESYSTEM_TYPE);
       if (fsType.isNull())
         return "unknown";
       else if (kNetworkFilesystems.includes(fsType.readString()))
         return "network";
-      else
-        return "local";
-    }
-    finally {
+      return "local";
+    } finally {
       if (filePath)
         g_free(filePath);
       if (glibFile && !glibFile.isNull())
         g_object_unref(glibFile);
       if (glibFileInfo && !glibFileInfo.isNull())
         g_object_unref(glibFileInfo);
     }
   },
--- a/mail/components/about-support/aboutSupportWin32.js
+++ b/mail/components/about-support/aboutSupportWin32.js
@@ -19,20 +19,20 @@ var AboutSupportPlatform = {
   getFileSystemType: function ASPWin32_getFileSystemType(aFile) {
     let kernel32 = ctypes.open("kernel32.dll");
 
     try {
       // Returns the path of the volume a file is on.
       let GetVolumePathName = kernel32.declare(
         "GetVolumePathNameW",
         ctypes.winapi_abi,
-        BOOL,              // return type: 1 indicates success, 0 failure
+        BOOL,                // return type: 1 indicates success, 0 failure
         ctypes.char16_t.ptr, // in: lpszFileName
         ctypes.char16_t.ptr, // out: lpszVolumePathName
-        ctypes.uint32_t    // in: cchBufferLength
+        ctypes.uint32_t      // in: cchBufferLength
       );
 
       // Returns the last error.
       let GetLastError = kernel32.declare(
         "GetLastError",
         ctypes.winapi_abi,
         ctypes.uint32_t // return type: the last error
       );
@@ -48,25 +48,23 @@ var AboutSupportPlatform = {
         throw new Error("Unable to get volume path for " + filePath + ", error " +
                         GetLastError());
       }
 
       // Returns the type of the drive.
       let GetDriveType = kernel32.declare(
         "GetDriveTypeW",
         ctypes.winapi_abi,
-        ctypes.uint32_t,  // return type: the drive type
+        ctypes.uint32_t,    // return type: the drive type
         ctypes.char16_t.ptr // in: lpRootPathName
       );
       let type = GetDriveType(volumePath);
       // http://msdn.microsoft.com/en-us/library/aa364939
       if (type == DRIVE_UNKNOWN)
         return "unknown";
       else if (type == DRIVE_NETWORK)
         return "network";
-      else
-        return "local";
-    }
-    finally {
+      return "local";
+    } finally {
       kernel32.close();
     }
   },
 };
--- a/mail/components/about-support/content/aboutSupport.js
+++ b/mail/components/about-support/content/aboutSupport.js
@@ -1,15 +1,17 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * 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 file is a copy of mozilla/toolkit/content/aboutSupport.js with
    modifications for TB. */
 
+/* globals AboutSupportPlatform, populateAccountsSection, sendViaEmail */
+
 "use strict";
 
 ChromeUtils.import("resource://gre/modules/Services.jsm");
 ChromeUtils.import("resource://gre/modules/Troubleshoot.jsm");
 ChromeUtils.import("resource://gre/modules/ResetProfile.jsm");
 ChromeUtils.import("resource://gre/modules/AppConstants.jsm");
 // added for TB
 ChromeUtils.import("resource:///modules/mailServices.js");
@@ -162,18 +164,17 @@ var snapshotFormatters = {
     try {
       fsType = AboutSupportPlatform.getFileSystemType(currProfD);
       let bundle = Services.strings.createBundle(
         "chrome://messenger/locale/aboutSupportMail.properties");
       let fsText = bundle.GetStringFromName("fsType." + fsType);
       let fsTextNode = document.createElement("span");
       fsTextNode.textContent = fsText;
       profElem.appendChild(fsTextNode);
-    }
-    catch (x) {
+    } catch (x) {
       Cu.reportError(x);
     }
     // end of TB addition
   },
 
   crashes: function crashes(data) {
     if (!AppConstants.MOZ_CRASHREPORTER)
       return;
@@ -222,17 +223,17 @@ var snapshotFormatters = {
       } else {
         let minutesPassed = Math.max(Math.round(timePassed / (60 * 1000)), 1);
         let minutesPassedString = strings.GetStringFromName("crashesTimeMinutes");
         formattedDate = PluralForm.get(minutesPassed, minutesPassedString)
                                   .replace("#1", minutesPassed);
       }
       return $.new("tr", [
         $.new("td", [
-          $.new("a", crash.id, null, {href : reportURL + crash.id})
+          $.new("a", crash.id, null, {href: reportURL + crash.id})
         ]),
         $.new("td", formattedDate)
       ]);
     }));
   },
 
   extensions: function extensions(data) {
     $.append($("extensions-tbody"), data.map(function(extension) {
@@ -288,16 +289,17 @@ var snapshotFormatters = {
         return $.new("tr", [
           $.new("td", name, "pref-name"),
           $.new("td", String(value).substr(0, 120), "pref-value"),
         ]);
       }
     ));
   },
 
+  /* eslint-disable complexity */
   graphics: function graphics(data) {
     let strings = stringBundle();
 
     function localizedMsg(msgArray) {
       let nameOrMsg = msgArray.shift();
       if (msgArray.length) {
         // formatStringFromName logs an NS_ASSERTION failure otherwise that says
         // "use GetStringFromName".  Lame.
@@ -661,16 +663,17 @@ var snapshotFormatters = {
     for (let key in data) {
       let value = data[key];
       if (Array.isArray(value)) {
         value = localizedMsg(value);
       }
       addRow("diagnostics", key, value);
     }
   },
+  /* eslint-enable complexity */
 
   media: function media(data) {
     let strings = stringBundle();
 
     function insertBasicInfo(key, value) {
       function createRow(key, value) {
         let th = $.new("th", strings.GetStringFromName(key), "column");
         let td = $.new("td", value);
@@ -827,17 +830,17 @@ var snapshotFormatters = {
     if (!AppConstants.MOZ_SANDBOX)
       return;
 
     let strings = stringBundle();
     let tbody = $("sandbox-tbody");
     for (let key in data) {
       // Simplify the display a little in the common case.
       if (key === "hasPrivilegedUserNamespaces" &&
-          data[key] === data["hasUserNamespaces"]) {
+          data[key] === data.hasUserNamespaces) {
         continue;
       }
       if (key === "syscallLog") {
         // Not in this table.
         continue;
       }
       tbody.appendChild($.new("tr", [
         $.new("th", strings.GetStringFromName(key), "column"),
@@ -928,19 +931,19 @@ function assembleFromGraphicsFailure(i, 
     // Non-asserting - the message is substring(9)
     what = "Error";
     message = message.substring(9);
   } else if (message.search(/\[GFX1\]: /) == 0) {
     // Asserting - the message is substring(8)
     what = "Assert";
     message = message.substring(8);
   }
-  let assembled = {"index" : index,
-                   "header" : ("(#" + index + ") " + what),
-                   "message" : message};
+  let assembled = {"index": index,
+                   "header": ("(#" + index + ") " + what),
+                   "message": message};
   return assembled;
 }
 
 function sortedArrayFromObject(obj) {
   let tuples = [];
   for (let prop in obj)
     tuples.push([prop, obj[prop]]);
   tuples.sort(([prop1, v1], [prop2, v2]) => prop1.localeCompare(prop2));
@@ -1242,17 +1245,17 @@ function safeModeRestart() {
                      .createInstance(Ci.nsISupportsPRBool);
   Services.obs.notifyObservers(cancelQuit, "quit-application-requested", "restart");
 
   if (!cancelQuit.data) {
     Services.startup.restartInSafeMode(Ci.nsIAppStartup.eAttemptQuit);
   }
 }
 
-//added for TB
+// Added for TB.
 function onShowPrivateDataChange(aCheckbox) {
   document.getElementById("about-support-private").disabled = aCheckbox.checked;
 }
 
 /**
  * Set up event listeners for buttons.
  */
 function setupEventListeners() {
--- a/mail/components/about-support/content/accounts.js
+++ b/mail/components/about-support/content/accounts.js
@@ -1,12 +1,14 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * 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/. */
 
+/* globals CLASS_DATA_PRIVATE, CLASS_DATA_PUBLIC, fixIterator, MailServices */
+
 "use strict";
 
 ChromeUtils.import("resource:///modules/mailServices.js");
 ChromeUtils.import("resource:///modules/iteratorUtils.jsm");
 ChromeUtils.import("resource://gre/modules/Services.jsm");
 
 // Platform-specific includes
 if ("@mozilla.org/windows-registry-key;1" in Cc)
@@ -53,17 +55,17 @@ var AboutSupport = {
     for (let identity of fixIterator(identities, Ci.nsIMsgIdentity)) {
       let isDefault = identity == defaultIdentity;
       let smtpServer = {};
       MailServices.smtp.getServerByIdentity(identity, smtpServer);
       smtpDetails.push({identityName: identity.identityName,
                         name: smtpServer.value.displayname,
                         authMethod: smtpServer.value.authMethod,
                         socketType: smtpServer.value.socketType,
-                        isDefault: isDefault});
+                        isDefault});
     }
 
     return smtpDetails;
   },
 
   /**
    * Returns account details as an array of records.
    */
@@ -112,18 +114,17 @@ var AboutSupport = {
    */
   getSocketTypeText: function AboutSupport_getSocketTypeText(aIndex) {
     let plainSocketType = (aIndex in gSocketTypes ?
                            gSocketTypes[aIndex] : aIndex);
     let prettySocketType;
     try {
       prettySocketType = gMessengerBundle.GetStringFromName(
         "smtpServer-ConnectionSecurityType-" + aIndex);
-    }
-    catch (e) {
+    } catch (e) {
       if (e.result == Cr.NS_ERROR_FAILURE) {
         // The string wasn't found in the bundle. Make do without it.
         prettySocketType = plainSocketType;
       } else {
         throw e;
       }
     }
     return {localized: prettySocketType, neutral: plainSocketType};
@@ -135,18 +136,17 @@ var AboutSupport = {
    */
   getAuthMethodText: function AboutSupport_getAuthMethodText(aIndex) {
     let prettyAuthMethod;
     let plainAuthMethod = (aIndex in gAuthMethods ?
                            gAuthMethods[aIndex] : aIndex);
     if (aIndex in gAuthMethodProperties) {
       prettyAuthMethod =
         gMessengerBundle.GetStringFromName(gAuthMethodProperties[aIndex]);
-    }
-    else {
+    } else {
       prettyAuthMethod = plainAuthMethod;
     }
     return {localized: prettyAuthMethod, neutral: plainAuthMethod};
   }
 };
 
 function createParentElement(tagName, childElems) {
   let elem = document.createElement(tagName);
--- a/mail/components/about-support/content/export.js
+++ b/mail/components/about-support/content/export.js
@@ -1,12 +1,15 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * 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/. */
 
+/* globals CLASS_DATA_PRIVATE, CLASS_DATA_PUBLIC, CLASS_DATA_UIONLY, createElement,
+createParentElement, getAccountsText, getLoadContext, MailServices, Services */
+
 "use strict";
 
 ChromeUtils.import("resource://gre/modules/AppConstants.jsm");
 
 /**
  * Create warning text to add to any private data.
  * @returns A HTML paragraph node containing the warning.
  */
@@ -111,31 +114,26 @@ function cleanUpText(aElem, aHidePrivate
     // Delete uionly and no-copy nodes.
     if (classList && (classList.contains(CLASS_DATA_UIONLY) || classList.contains("no-copy"))) {
       // Advance to the next node before removing the current node, since
       // node.nextSibling is null after remove()
       let nextNode = node.nextSibling;
       node.remove();
       node = nextNode;
       continue;
-    }
-    // Replace private data with a blank string
-    else if (aHidePrivateData && classList && classList.contains(CLASS_DATA_PRIVATE)) {
-      node.textContent = "";
-    }
-    // Replace public data with a blank string
-    else if (!aHidePrivateData && classList && classList.contains(CLASS_DATA_PUBLIC)) {
+    } else if (aHidePrivateData && classList && classList.contains(CLASS_DATA_PRIVATE)) {
+      // Replace private data with a blank string.
       node.textContent = "";
-    }
-    else {
-      // Replace localized text with non-localized text
-      if (copyData != null) {
-        node.textContent = copyData;
-        copyData = null;
-      }
+    } else if (!aHidePrivateData && classList && classList.contains(CLASS_DATA_PUBLIC)) {
+      // Replace public data with a blank string.
+      node.textContent = "";
+    } else if (copyData != null) {
+      // Replace localized text with non-localized text.
+      node.textContent = copyData;
+      copyData = null;
     }
 
     if (node.nodeType == Node.ELEMENT_NODE)
       cleanUpText(node, aHidePrivateData);
 
     // Advance!
     node = node.nextSibling;
   }
@@ -176,21 +174,20 @@ function generateTextForElement(elem, aH
   if (!["td", "th", "span", "a"].includes(elem.tagName))
     textFragmentAccumulator.push("\n");
 
   // If this element is one of our elements to replace with text, do it.
   if (elem.id in gElementsToReplace) {
     let replaceFn = gElementsToReplace[elem.id];
     textFragmentAccumulator.push(replaceFn(aHidePrivateData, indent + "  "));
     return;
-  };
+  }
 
   if (AppConstants.MOZ_CRASHREPORTER) {
-    if (elem.id == "crashes-table")
-    {
+    if (elem.id == "crashes-table") {
       textFragmentAccumulator.push(getCrashesText(indent));
       return;
     }
   }
 
   let childCount = elem.childElementCount;
 
   // We're not going to spread a two-column <tr> across multiple lines, so
@@ -203,18 +200,17 @@ function generateTextForElement(elem, aH
   }
 
   // Generate the text representation for each child node.
   let node = elem.firstChild;
   while (node) {
     if (node.nodeType == Node.TEXT_NODE) {
       // Text belonging to this element uses its indentation level.
       generateTextForTextNode(node, indent, textFragmentAccumulator);
-    }
-    else if (node.nodeType == Node.ELEMENT_NODE) {
+    } else if (node.nodeType == Node.ELEMENT_NODE) {
       // Recurse on the child element with an extra level of indentation (but
       // only if there's more than one child).
       generateTextForElement(node, aHidePrivateData,
                              indent + (childCount > 1 ? "  " : ""),
                              textFragmentAccumulator);
     }
     // Advance!
     node = node.nextSibling;
@@ -236,16 +232,15 @@ function generateTextForTextNode(node, i
 
 /**
  * Returns a plaintext representation of crashes data.
  */
 
 function getCrashesText(aIndent) {
   let crashesData = "";
   let recentCrashesSubmitted = document.querySelectorAll("#crashes-tbody > tr");
-  for (let i = 0; i < recentCrashesSubmitted.length; i++)
-  {
+  for (let i = 0; i < recentCrashesSubmitted.length; i++) {
     let tds = recentCrashesSubmitted.item(i).querySelectorAll("td");
     crashesData += aIndent.repeat(2) + tds.item(0).firstChild.href +
                    " (" + tds.item(1).textContent + ")\n";
   }
   return crashesData;
 }