Bug 1497705 - Remove ESLint rule overrides in common/ and broken code they were hiding. r=jorgk
authorGeoff Lankow <geoff@darktrojan.net>
Wed, 10 Oct 2018 18:44:21 +1300
changeset 33364 fe10a3a8d48e6395ff6456ee2bbffebb8bd024da
parent 33363 dc3c8dc2370a631044218746be0798259cda73f5
child 33365 d3153e99afae5c8ec62f70bf6b5184fffea35c8a
push id387
push userclokep@gmail.com
push dateMon, 10 Dec 2018 21:30:47 +0000
reviewersjorgk
bugs1497705
Bug 1497705 - Remove ESLint rule overrides in common/ and broken code they were hiding. r=jorgk
common/.eslintrc.js
common/bindings/preferences.xml
common/src/ChromeManifest.jsm
common/src/browser-development-helpers.js
common/src/extensionSupport.jsm
common/src/viewSource.js
mail/components/mailGlue.js
deleted file mode 100644
--- a/common/.eslintrc.js
+++ /dev/null
@@ -1,15 +0,0 @@
-"use strict";
-
-module.exports = {
-  "rules": {
-    // Don't Disallow Undeclared Variables (for now).
-    // The linter does not see many globals from imported files
-    // and .xul linked .js files, so there are too many false positives.
-    "no-undef": "off",
-
-    // Require spaces around operators, except for a|0.
-    // Disabled for now given eslint doesn't support default args yet
-    // "space-infix-ops": [2, { "int32Hint": true }],
-    "space-infix-ops": 0,
-  },
-};
--- a/common/bindings/preferences.xml
+++ b/common/bindings/preferences.xml
@@ -715,16 +715,17 @@
                 onget="return document.getAnonymousElementByAttribute(this, 'anonid', 'paneDeck');"/>
       <property name="_paneDeckContainer"
                 onget="return document.getAnonymousElementByAttribute(this, 'class', 'paneDeckContainer');"/>
       <property name="_selector"
                 onget="return document.getAnonymousElementByAttribute(this, 'anonid', 'selector');"/>
       <property name="lastSelected"
                 onget="return this.getAttribute('lastSelected');">
         <setter>
+          /* globals Services */
           this.setAttribute("lastSelected", val);
           Services.xulStore.persist(this, "lastSelected");
           return val;
         </setter>
       </property>
       <property name="currentPane"
                 onset="return this._currentPane = val;">
         <getter>
--- a/common/src/ChromeManifest.jsm
+++ b/common/src/ChromeManifest.jsm
@@ -1,14 +1,16 @@
 /* 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.EXPORTED_SYMBOLS = ["ChromeManifest"];
 
+ChromeUtils.import("resource://gre/modules/Services.jsm");
+
 /**
  * A parser for chrome.manifest files. Implements a subset of
  * https://developer.mozilla.org/en-US/docs/Mozilla/Chrome_Registration
  */
 class ChromeManifest {
 
   /**
    * Constucts the chrome.manifest parser
@@ -42,32 +44,32 @@ class ChromeManifest {
 
   /**
    * Parse the given file.
    *
    * @param {String} filename           The filename to load
    * @param {String} base               The relative directory this file is expected to be in.
    * @return {Promise}                  Resolved when loading completes
    */
-  async parse(filename="chrome.manifest", base="") {
+  async parse(filename = "chrome.manifest", base = "") {
     await this.parseString(await this.loader(filename), base);
   }
 
   /**
    * Parse the given string.
    *
    * @param {String} data               The file data to load
    * @param {String} base               The relative directory this file is expected to be in.
    * @return {Promise}                  Resolved when loading completes
    */
-  async parseString(data, base="") {
+  async parseString(data, base = "") {
     let lines = data.split("\n");
     let extraManifests = [];
     for (let line of lines) {
-      let parts = line.split(/\s+/);
+      let parts = line.trim().split(/\s+/);
       let directive = parts.shift();
       switch (directive) {
         case "manifest":
           extraManifests.push(this._parseManifest(base, ...parts));
           break;
         case "component": this._parseComponent(...parts); break;
         case "contract": this._parseContract(...parts); break;
 
@@ -88,16 +90,20 @@ class ChromeManifest {
 
   /**
    * Ensure the flags provided for the instruction match our options
    *
    * @param {String[]} flags        An array of raw flag values in the form key=value.
    * @return {Boolean}              True, if the flags match the options provided in the constructor
    */
   _parseFlags(flags) {
+    if (flags.length == 0) {
+      return true;
+    }
+
     let matchString = (a, sign, b) => {
       if (sign != "=") {
         console.warn(`Invalid sign ${sign} in ${a}${sign}${b}, dropping manifest instruction`);
         return false;
       }
       return a == b;
     };
 
@@ -308,17 +314,17 @@ class DefaultMap extends Map {
   }
 
   /**
    * Get the given key, creating if necessary
    *
    * @param {String} key            The key of the map to get
    * @param {Boolean} create        True, if the key should be created in case it doesn't exist.
    */
-  get(key, create=true) {
+  get(key, create = true) {
     if (this.has(key)) {
       return super.get(key);
     } else if (create) {
       this.set(key, this._default());
       return super.get(key);
     }
 
     return this._default();
--- a/common/src/browser-development-helpers.js
+++ b/common/src/browser-development-helpers.js
@@ -2,16 +2,18 @@
  * 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/. */
 
 /**
  * Extra features for local development. This file isn't loaded in
  * non-local builds.
  */
 
+/* globals Services */
+
 var DevelopmentHelpers = {
   init() {
     this.quickRestart = this.quickRestart.bind(this);
     this.addRestartShortcut();
   },
 
   quickRestart() {
     Services.obs.notifyObservers(null, "startupcache-invalidate");
--- a/common/src/extensionSupport.jsm
+++ b/common/src/extensionSupport.jsm
@@ -2,40 +2,28 @@
  * 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/. */
 
 /**
  * Helper functions for use by entensions that should ease them plug
  * into the application.
  */
 
-this.EXPORTED_SYMBOLS = [ "extensionDefaults", "ExtensionSupport" ];
+this.EXPORTED_SYMBOLS = ["ExtensionSupport"];
 
 ChromeUtils.import("resource://gre/modules/Services.jsm");
 // ChromeUtils.import("resource://gre/modules/Deprecated.jsm") - needed for warning.
 ChromeUtils.import("resource://gre/modules/NetUtil.jsm");
 
 var { fixIterator } = ChromeUtils.import("resource:///modules/iteratorUtils.jsm", null);
 ChromeUtils.import("resource:///modules/IOUtils.js");
 
 var extensionHooks = new Map();
 var openWindowList;
 
-/**
- * Reads preferences from addon provided locations (defaults/preferences/*.js)
- * and stores them in the default preferences branch.
- */
-function extensionDefaults() {
-  // Fetch enabled non-bootstrapped add-ons.
-  let enabledAddons = Services.dirsvc.get("XREExtDL", Ci.nsISimpleEnumerator);
-  for (let addonFile of fixIterator(enabledAddons, Ci.nsIFile)) {
-    loadAddonPrefs(addonFile);
-  }
-}
-
 var ExtensionSupport = {
   loadedLegacyExtensions: new Set(),
 
   loadAddonPrefs(addonFile) {
     function setPref(preferDefault, name, value) {
       let branch = preferDefault ? Services.prefs.getDefaultBranch("") : Services.prefs.getBranch("");
 
       if (typeof value == "boolean") {
--- a/common/src/viewSource.js
+++ b/common/src/viewSource.js
@@ -1,14 +1,16 @@
 // -*- indent-tabs-mode: nil; js-indent-level: 2 -*-
 
 /* 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 internalSave, goDoCommand */
+
 ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
 ChromeUtils.import("resource://gre/modules/ViewSourceBrowser.jsm");
 
 ChromeUtils.defineModuleGetter(this, "Services",
   "resource://gre/modules/Services.jsm");
 ChromeUtils.defineModuleGetter(this, "CharsetMenu",
   "resource://gre/modules/CharsetMenu.jsm");
 ChromeUtils.defineModuleGetter(this, "Deprecated",
--- a/mail/components/mailGlue.js
+++ b/mail/components/mailGlue.js
@@ -8,17 +8,16 @@
 ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
 ChromeUtils.import("resource://gre/modules/Services.jsm");
 ChromeUtils.import("resource://gre/modules/AddonManager.jsm");
 ChromeUtils.import("resource://gre/modules/LightweightThemeConsumer.jsm");
 ChromeUtils.import("resource:///modules/TBDistCustomizer.jsm");
 ChromeUtils.import("resource:///modules/MailMigrator.jsm");
 const {
   ExtensionSupport,
-  extensionDefaults,
 } = ChromeUtils.import("resource:///modules/extensionSupport.jsm", null);
 const { L10nRegistry, FileSource } = ChromeUtils.import("resource://gre/modules/L10nRegistry.jsm", null);
 
 // lazy module getters
 
 XPCOMUtils.defineLazyModuleGetters(this, {
   LightweightThemeManager: "resource://gre/modules/LightweightThemeManager.jsm",
 });
@@ -56,17 +55,16 @@ function MailGlue() {
 
 MailGlue.prototype = {
   // init (called at app startup)
   _init: function MailGlue__init() {
     Services.obs.addObserver(this, "xpcom-shutdown");
     Services.obs.addObserver(this, "final-ui-startup");
     Services.obs.addObserver(this, "mail-startup-done");
     Services.obs.addObserver(this, "handle-xul-text-link");
-    Services.obs.addObserver(this, "profile-after-change");
     Services.obs.addObserver(this, "chrome-document-global-created");
 
     // Inject scripts into some devtools windows.
     function _setupBrowserConsole(domWindow) {
       domWindow.document.documentElement.setAttribute("title", gMailBundle.GetStringFromName("errorConsoleTitle"));
       Services.scriptloader.loadSubScript("chrome://global/content/viewSourceUtils.js", domWindow);
     }
 
@@ -94,17 +92,16 @@ MailGlue.prototype = {
   },
 
   // cleanup (called at shutdown)
   _dispose: function MailGlue__dispose() {
     Services.obs.removeObserver(this, "xpcom-shutdown");
     Services.obs.removeObserver(this, "final-ui-startup");
     Services.obs.removeObserver(this, "mail-startup-done");
     Services.obs.removeObserver(this, "handle-xul-text-link");
-    Services.obs.removeObserver(this, "profile-after-change");
     Services.obs.removeObserver(this, "chrome-document-global-created");
 
     ExtensionSupport.unregisterWindowListener("Thunderbird-internal-Toolbox");
     ExtensionSupport.unregisterWindowListener("Thunderbird-internal-BrowserConsole");
   },
 
   // nsIObserver implementation
   observe: function MailGlue_observe(aSubject, aTopic, aData) {
@@ -116,19 +113,16 @@ MailGlue.prototype = {
       this._onProfileStartup();
       break;
     case "mail-startup-done":
       this._onMailStartupDone();
       break;
     case "handle-xul-text-link":
       this._handleLink(aSubject, aData);
       break;
-    case "profile-after-change":
-      extensionDefaults(); // extensionSupport.jsm
-      break;
     case "chrome-document-global-created":
       // Set up lwt, but only if the "lightweightthemes" attr is set on the root
       // (i.e. in messenger.xul).
       aSubject.addEventListener("DOMContentLoaded", () => {
         if (aSubject.document.documentElement.hasAttribute("lightweightthemes")) {
           new LightweightThemeConsumer(aSubject.document);
         }
       }, {once: true});