Bug 1452575 - Enable ESLint for devtools/client/shared/**/*.jsm. r?jryans draft
authorMark Banner <standard8@mozilla.com>
Mon, 09 Apr 2018 11:14:01 +0100
changeset 779594 29503d06086608b754810b4af28f48e4584f3238
parent 779593 c016619dd495a64e561b6f831da8fb0d92b502ae
push id105819
push userbmo:standard8@mozilla.com
push dateTue, 10 Apr 2018 09:15:25 +0000
reviewersjryans
bugs1452575
milestone61.0a1
Bug 1452575 - Enable ESLint for devtools/client/shared/**/*.jsm. r?jryans MozReview-Commit-ID: G7g94FkBbhp
.eslintignore
devtools/.eslintrc.js
devtools/client/shared/AppCacheUtils.jsm
devtools/client/shared/DOMHelpers.jsm
devtools/client/shared/widgets/AbstractTreeItem.jsm
devtools/client/shared/widgets/SideMenuWidget.jsm
devtools/client/shared/widgets/VariablesView.jsm
devtools/client/shared/widgets/VariablesViewController.jsm
--- a/.eslintignore
+++ b/.eslintignore
@@ -101,30 +101,20 @@ browser/extensions/mortar/**
 browser/extensions/formautofill/phonenumberutils/PhoneNumberMetaData.jsm
 
 # devtools/ exclusions
 devtools/client/inspector/markup/test/doc_markup_events_*.html
 devtools/client/inspector/rules/test/doc_media_queries.html
 devtools/client/memory/test/chrome/*.html
 devtools/client/performance/components/test/test_jit_optimizations_01.html
 devtools/client/responsive.html/test/browser/touch.html
-devtools/client/shared/*.jsm
-devtools/client/shared/components/reps/reps.js
-devtools/client/shared/components/reps/test/mochitest/*.html
-!devtools/client/shared/components/reps/test/mochitest/test_reps_infinity.html
-!devtools/client/shared/components/reps/test/mochitest/test_reps_nan.html
-!devtools/client/shared/components/reps/test/mochitest/test_reps_promise.html
-!devtools/client/shared/components/reps/test/mochitest/test_reps_symbol.html
-!devtools/client/shared/components/reps/test/mochitest/test_reps_text-node.html
 devtools/client/shared/components/test/mochitest/*.html
 !devtools/client/shared/components/test/mochitest/test_stack-trace.html
 devtools/client/shared/shim/test/test_*.html
 devtools/client/shared/test/browser_toolbar_webconsole_errors_count.html
-devtools/client/shared/webgl-utils.js
-devtools/client/shared/widgets/*.jsm
 devtools/client/storage/test/*.html
 !devtools/client/storage/test/storage-cookies.html
 !devtools/client/storage/test/storage-overflow.html
 !devtools/client/storage/test/storage-search.html
 !devtools/client/storage/test/storage-unsecured-iframe.html
 !devtools/client/storage/test/storage-unsecured-iframe-usercontextid.html
 devtools/client/webaudioeditor/**
 devtools/client/webconsole/old/net/**
@@ -145,16 +135,17 @@ devtools/shared/webconsole/test/test_*.h
 # Soon to be removed
 devtools/client/commandline/**
 # Soon to be removed, the new/ directory is explicitly excluded below due to
 # also being an imported repository.
 devtools/client/debugger/**
 
 # Ignore devtools imported repositories
 devtools/client/debugger/new/**
+devtools/client/shared/components/reps/**
 
 # Ignore devtools preferences files
 devtools/client/preferences/**
 devtools/startup/devtools-startup-prefs.js
 
 # Ignore devtools third-party libs
 devtools/shared/jsbeautify/*
 devtools/shared/acorn/*
--- a/devtools/.eslintrc.js
+++ b/devtools/.eslintrc.js
@@ -31,72 +31,82 @@ module.exports = {
     "rules": {
       "no-return-assign": "off",
       "no-unused-vars": "off",
     }
   }, {
     "files": [
       "client/scratchpad/scratchpad-manager.jsm",
       "client/scratchpad/scratchpad.js",
+      "client/shared/*.jsm",
     ],
     "rules": {
       "camelcase": "off",
     }
   }, {
     "files": [
       "client/framework/**",
       "client/scratchpad/**",
+      "client/shared/*.jsm",
+      "client/shared/widgets/*.jsm",
     ],
     "rules": {
       "consistent-return": "off",
     }
   }, {
     "files": [
       "client/framework/**",
       "client/scratchpad/**",
+      "client/shared/AppCacheUtils.jsm",
     ],
     "rules": {
       "max-nested-callbacks": "off",
     }
   }, {
     "files": [
       "client/framework/**",
       "client/scratchpad/**",
+      "client/shared/*.jsm",
+      "client/shared/widgets/*.jsm",
     ],
     "rules": {
       "max-len": "off",
     }
   }, {
     "files": [
       "client/scratchpad/test/browser_scratchpad_inspect.js",
       "client/scratchpad/test/browser_scratchpad_inspect_primitives.js",
     ],
     "rules": {
       "no-labels": "off",
     }
   }, {
     "files": [
       "client/framework/**",
       "client/scratchpad/**",
+      "client/shared/*.jsm",
+      "client/shared/widgets/*.jsm",
     ],
     "rules": {
       "mozilla/no-aArgs": "off",
     }
   }, {
     "files": [
       "client/framework/test/**",
       "client/scratchpad/**",
     ],
     "rules": {
       "mozilla/var-only-at-top-level": "off",
     }
   }, {
     "files": [
       "client/framework/**",
       "client/scratchpad/**",
+      "client/shared/AppCacheUtils.jsm",
+      "client/shared/widgets/*.jsm",
     ],
     "rules": {
       "no-shadow": "off",
     }
   }, {
     "files": [
       "client/framework/**",
       "client/scratchpad/**",
--- a/devtools/client/shared/AppCacheUtils.jsm
+++ b/devtools/client/shared/AppCacheUtils.jsm
@@ -26,17 +26,16 @@
 "use strict";
 
 var { XPCOMUtils } = ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm", {});
 var { NetUtil } = ChromeUtils.import("resource://gre/modules/NetUtil.jsm", {});
 var { require } = ChromeUtils.import("resource://devtools/shared/Loader.jsm", {});
 
 var { gDevTools } = require("devtools/client/framework/devtools");
 var Services = require("Services");
-var promise = require("promise");
 
 this.EXPORTED_SYMBOLS = ["AppCacheUtils"];
 
 function AppCacheUtils(documentOrUri) {
   this._parseManifest = this._parseManifest.bind(this);
 
   if (documentOrUri) {
     if (typeof documentOrUri == "string") {
@@ -179,17 +178,17 @@ AppCacheUtils.prototype = {
     });
   },
 
   _getURIInfo: function ACU__getURIInfo(uri) {
     return new Promise((resolve, reject) => {
       let inputStream = Cc["@mozilla.org/scriptableinputstream;1"]
                           .createInstance(Ci.nsIScriptableInputStream);
       let buffer = "";
-      var channel = NetUtil.newChannel({
+      let channel = NetUtil.newChannel({
         uri: uri,
         loadUsingSystemPrincipal: true,
         securityFlags: Ci.nsILoadInfo.SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL
       });
 
       // Avoid the cache:
       channel.loadFlags |= Ci.nsIRequest.LOAD_BYPASS_CACHE;
       channel.loadFlags |= Ci.nsIRequest.INHIBIT_CACHING;
@@ -283,19 +282,17 @@ AppCacheUtils.prototype = {
 
     if (entries.length === 0) {
       throw new Error(l10n.GetStringFromName("noResults"));
     }
     return entries;
   },
 
   viewEntry: function ACU_viewEntry(key) {
-    let wm = Cc["@mozilla.org/appshell/window-mediator;1"]
-               .getService(Ci.nsIWindowMediator);
-    let win = wm.getMostRecentWindow(gDevTools.chromeWindowType);
+    let win = Services.wm.getMostRecentWindow(gDevTools.chromeWindowType);
     let url = "about:cache-entry?storage=appcache&context=&eid=&uri=" + key;
     win.openUILinkIn(url, "tab");
   },
 
   clearAll: function ACU_clearAll() {
     if (!Services.prefs.getBoolPref("browser.cache.disk.enable")) {
       throw new Error(l10n.GetStringFromName("cacheDisabled"));
     }
--- a/devtools/client/shared/DOMHelpers.jsm
+++ b/devtools/client/shared/DOMHelpers.jsm
@@ -81,18 +81,18 @@ DOMHelpers.prototype = {
         if (index == 0) {
           return svgDocument.documentElement; // the node's SVGElement
         }
         return null;
       }
     }
 
     let child = null;
-    if (previousSibling) // then we are walking
-      {
+    if (previousSibling) {
+      // then we are walking
       child = this.getNextSibling(previousSibling);
     } else {
       child = this.getFirstChild(node);
     }
 
     if (showTextNodesWithWhitespace) {
       return child;
     }
--- a/devtools/client/shared/widgets/AbstractTreeItem.jsm
+++ b/devtools/client/shared/widgets/AbstractTreeItem.jsm
@@ -1,17 +1,16 @@
 /* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
 /* vim: set ft=javascript ts=2 et sw=2 tw=80: */
 /* 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/. */
 "use strict";
 
 const { require, loader } = ChromeUtils.import("resource://devtools/shared/Loader.jsm", {});
-const { XPCOMUtils } = require("resource://gre/modules/XPCOMUtils.jsm");
 const { ViewHelpers } = require("devtools/client/shared/widgets/view-helpers");
 const { KeyCodes } = require("devtools/client/shared/keycodes");
 
 loader.lazyRequireGetter(this, "EventEmitter", "devtools/shared/event-emitter");
 
 this.EXPORTED_SYMBOLS = ["AbstractTreeItem"];
 
 /**
@@ -371,21 +370,20 @@ AbstractTreeItem.prototype = {
   /**
    * Shows all children of this item in the tree.
    */
   _showChildren: function() {
     // If this is the root item and we're not expanding any child nodes,
     // it is safe to append everything at once.
     if (this == this._rootItem && this.autoExpandDepth == 0) {
       this._appendChildrenBatch();
-    }
-    // Otherwise, append the child items and their descendants successively;
-    // if not, the tree will become garbled and nodes will intertwine,
-    // since all the tree items are sharing a single container node.
-    else {
+    } else {
+      // Otherwise, append the child items and their descendants successively;
+      // if not, the tree will become garbled and nodes will intertwine,
+      // since all the tree items are sharing a single container node.
       this._appendChildrenSuccessive();
     }
   },
 
   /**
    * Hides all children of this item in the tree.
    */
   _hideChildren: function() {
--- a/devtools/client/shared/widgets/SideMenuWidget.jsm
+++ b/devtools/client/shared/widgets/SideMenuWidget.jsm
@@ -168,17 +168,16 @@ SideMenuWidget.prototype = {
       this._selectedItem = null;
     }
   },
 
   /**
    * Removes all of the child nodes from this container.
    */
   removeAllItems: function() {
-    let parent = this._parent;
     let list = this._list;
 
     while (list.hasChildNodes()) {
       list.firstChild.remove();
     }
 
     this._selectedItem = null;
 
@@ -481,19 +480,18 @@ function SideMenuGroup(aWidget, aName, a
         checkboxTooltip: L10N.getStr("sideMenu.groupCheckbox.tooltip")
       });
       checkbox.className = "side-menu-widget-group-checkbox";
     }
 
     title.appendChild(name);
     target.appendChild(title);
     target.appendChild(list);
-  }
-  // Skip a few redundant nodes when no title is shown.
-  else {
+  } else {
+    // Skip a few redundant nodes when no title is shown.
     let target = this._target = this._list = this.document.createElement("vbox");
     target.className = "side-menu-widget-group side-menu-widget-group-list";
     target.setAttribute("merged-group-contents", "");
   }
 }
 
 SideMenuGroup.prototype = {
   get _orderedGroupElementsArray() {
@@ -591,19 +589,18 @@ function SideMenuItem(aGroup, aContents,
     container.appendChild(target);
 
     // Show a horizontal arrow towards the content.
     if (aOptions.showArrow) {
       let arrow = this._arrow = this.document.createElement("hbox");
       arrow.className = "side-menu-widget-item-arrow";
       container.appendChild(arrow);
     }
-  }
-  // Skip a few redundant nodes when no horizontal arrow or checkbox is shown.
-  else {
+  } else {
+    // Skip a few redundant nodes when no horizontal arrow or checkbox is shown.
     let target = this._target = this._container = this.document.createElement("hbox");
     target.className = "side-menu-widget-item side-menu-widget-item-contents";
     target.setAttribute("merged-item-contents", "");
   }
 
   this._target.setAttribute("flex", "1");
   this.contents = aContents;
 }
--- a/devtools/client/shared/widgets/VariablesView.jsm
+++ b/devtools/client/shared/widgets/VariablesView.jsm
@@ -1158,23 +1158,21 @@ VariablesView.getterOrSetterEvalMacro = 
       // Wrap statements inside a function declaration if not already wrapped.
       if (!aCurrentString.startsWith("function")) {
         let header = "function(" + (type == "set" ? "value" : "") + ")";
         let body = "";
         // If there's a return statement explicitly written, always use the
         // standard function definition syntax
         if (aCurrentString.includes("return ")) {
           body = "{" + aCurrentString + "}";
-        }
-        // If block syntax is used, use the whole string as the function body.
-        else if (aCurrentString.startsWith("{")) {
+        } else if (aCurrentString.startsWith("{")) {
+          // If block syntax is used, use the whole string as the function body.
           body = aCurrentString;
-        }
-        // Prefer an expression closure.
-        else {
+        } else {
+          // Prefer an expression closure.
           body = "(" + aCurrentString + ")";
         }
         aCurrentString = header + body;
       }
 
       // Determine if a new getter or setter should be defined.
       let defineType = type == "get" ? "__defineGetter__" : "__defineSetter__";
 
@@ -1910,19 +1908,18 @@ Scope.prototype = {
       let currentObject = variable;
       let lowerCaseName = variable._nameString.toLowerCase();
       let lowerCaseValue = variable._valueString.toLowerCase();
 
       // Non-matched variables or properties require a corresponding attribute.
       if (!lowerCaseName.includes(aLowerCaseQuery) &&
           !lowerCaseValue.includes(aLowerCaseQuery)) {
         variable._matched = false;
-      }
-      // Variable or property is matched.
-      else {
+      } else {
+        // Variable or property is matched.
         variable._matched = true;
 
         // If the variable was ever expanded, there's a possibility it may
         // contain some matched properties, so make sure they're visible
         // ("expand downwards").
         if (variable._store.size) {
           variable.expand();
         }
@@ -2564,20 +2561,19 @@ Variable.prototype = extend(Scope.protot
       // Changing getter/setter names is never allowed.
       this.switch = null;
 
       // Getter/setter properties require special handling when it comes to
       // evaluation and deletion.
       if (this.ownerView.eval) {
         this.delete = VariablesView.getterOrSetterDeleteCallback;
         this.evaluationMacro = VariablesView.overrideValueEvalMacro;
-      }
-      // Deleting getters and setters individually is not allowed if no
-      // evaluation method is provided.
-      else {
+      } else {
+        // Deleting getters and setters individually is not allowed if no
+        // evaluation method is provided.
         this.delete = null;
         this.evaluationMacro = null;
       }
 
       let getter = this.addItem("get", { value: descriptor.get });
       let setter = this.addItem("set", { value: descriptor.set });
       getter.evaluationMacro = VariablesView.getterOrSetterEvalMacro;
       setter.evaluationMacro = VariablesView.getterOrSetterEvalMacro;
@@ -3334,20 +3330,22 @@ VariablesView.getGrip = function(aValue)
         return { type: "-0" };
       }
       return aValue;
     case "undefined":
       // document.all is also "undefined"
       if (aValue === undefined) {
         return { type: "undefined" };
       }
+      // fall through
     case "object":
       if (aValue === null) {
         return { type: "null" };
       }
+      // fall through
     case "function":
       return { type: "object",
                class: WebConsoleUtils.getObjectClassName(aValue) };
     default:
       console.error("Failed to provide a grip for value of " + typeof value +
                     ": " + aValue);
       return null;
   }
@@ -3402,16 +3400,17 @@ VariablesView.getString = function(aGrip
     case "string":
       return VariablesView.stringifiers.byType.string(aGrip, aOptions);
     case "boolean":
       return aGrip ? "true" : "false";
     case "number":
       if (!aGrip && 1 / aGrip === -Infinity) {
         return "-0";
       }
+      // fall through
     default:
       return aGrip + "";
   }
 };
 
 /**
  * The VariablesView stringifiers are used by VariablesView.getString(). These
  * are organized by object type, object class and by object actor preview kind.
--- a/devtools/client/shared/widgets/VariablesViewController.jsm
+++ b/devtools/client/shared/widgets/VariablesViewController.jsm
@@ -504,16 +504,17 @@ VariablesViewController.prototype = {
       callback: this.addExpander
     });
   },
 
   _populateFromEntries: function(target, grip) {
     let objGrip = grip.obj;
     let objectClient = this._getObjectClient(objGrip);
 
+    // eslint-disable-next-line new-cap
     return new promise((resolve, reject) => {
       objectClient.enumEntries((response) => {
         if (response.error) {
           // Older server might not support the enumEntries method
           console.warn(response.error + ": " + response.message);
           resolve();
         } else {
           let sliceGrip = {
@@ -822,19 +823,18 @@ var StackFrameUtils = this.StackFrameUti
    *         The scope's label.
    */
   getScopeLabel: function(aEnv) {
     let name = "";
 
     // Name the outermost scope Global.
     if (!aEnv.parent) {
       name = L10N.getStr("globalScopeLabel");
-    }
-    // Otherwise construct the scope name.
-    else {
+    } else {
+      // Otherwise construct the scope name.
       name = aEnv.type.charAt(0).toUpperCase() + aEnv.type.slice(1);
     }
 
     let label = L10N.getFormatStr("scopeLabel", name);
     switch (aEnv.type) {
       case "with":
       case "object":
         label += " [" + aEnv.object.class + "]";