From a0fd02b723d92acf7032f1bf285d43b17cb858f7 Mon Sep 17 00:00:00 2001 From: Mark Banner Date: Mon, 9 Apr 2018 11:14:01 +0100 Subject: [PATCH] Bug 1452575 - Enable ESLint for devtools/client/shared/**/*.jsm. r=jryans MozReview-Commit-ID: G7g94FkBbhp --HG-- extra : rebase_source : 4dac1e2422ca429d28a58a020317d3daf417d9a6 --- .eslintignore | 11 +------- devtools/.eslintrc.js | 10 ++++++++ devtools/client/shared/AppCacheUtils.jsm | 7 ++---- devtools/client/shared/DOMHelpers.jsm | 4 +-- .../shared/widgets/AbstractTreeItem.jsm | 10 +++----- .../client/shared/widgets/SideMenuWidget.jsm | 11 +++----- .../client/shared/widgets/VariablesView.jsm | 25 +++++++++---------- .../widgets/VariablesViewController.jsm | 6 ++--- 8 files changed, 38 insertions(+), 46 deletions(-) diff --git a/.eslintignore b/.eslintignore index 9173be2df528..e02d302d64f5 100644 --- a/.eslintignore +++ b/.eslintignore @@ -106,20 +106,10 @@ 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 @@ -150,6 +140,7 @@ devtools/client/debugger/** # Ignore devtools imported repositories devtools/client/debugger/new/** +devtools/client/shared/components/reps/** # Ignore devtools preferences files devtools/client/preferences/** diff --git a/devtools/.eslintrc.js b/devtools/.eslintrc.js index b37ca6ec9554..2ca546f4affc 100644 --- a/devtools/.eslintrc.js +++ b/devtools/.eslintrc.js @@ -36,6 +36,7 @@ module.exports = { "files": [ "client/scratchpad/scratchpad-manager.jsm", "client/scratchpad/scratchpad.js", + "client/shared/*.jsm", ], "rules": { "camelcase": "off", @@ -44,6 +45,8 @@ module.exports = { "files": [ "client/framework/**", "client/scratchpad/**", + "client/shared/*.jsm", + "client/shared/widgets/*.jsm", ], "rules": { "consistent-return": "off", @@ -52,6 +55,7 @@ module.exports = { "files": [ "client/framework/**", "client/scratchpad/**", + "client/shared/AppCacheUtils.jsm", ], "rules": { "max-nested-callbacks": "off", @@ -60,6 +64,8 @@ module.exports = { "files": [ "client/framework/**", "client/scratchpad/**", + "client/shared/*.jsm", + "client/shared/widgets/*.jsm", ], "rules": { "max-len": "off", @@ -76,6 +82,8 @@ module.exports = { "files": [ "client/framework/**", "client/scratchpad/**", + "client/shared/*.jsm", + "client/shared/widgets/*.jsm", ], "rules": { "mozilla/no-aArgs": "off", @@ -92,6 +100,8 @@ module.exports = { "files": [ "client/framework/**", "client/scratchpad/**", + "client/shared/AppCacheUtils.jsm", + "client/shared/widgets/*.jsm", ], "rules": { "no-shadow": "off", diff --git a/devtools/client/shared/AppCacheUtils.jsm b/devtools/client/shared/AppCacheUtils.jsm index b34a33f4e04a..30bfd66f55b1 100644 --- a/devtools/client/shared/AppCacheUtils.jsm +++ b/devtools/client/shared/AppCacheUtils.jsm @@ -31,7 +31,6 @@ 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"]; @@ -184,7 +183,7 @@ AppCacheUtils.prototype = { 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 @@ -288,9 +287,7 @@ AppCacheUtils.prototype = { }, 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"); }, diff --git a/devtools/client/shared/DOMHelpers.jsm b/devtools/client/shared/DOMHelpers.jsm index 9c9c962f4279..b8e6bc6f665d 100644 --- a/devtools/client/shared/DOMHelpers.jsm +++ b/devtools/client/shared/DOMHelpers.jsm @@ -86,8 +86,8 @@ DOMHelpers.prototype = { } let child = null; - if (previousSibling) // then we are walking - { + if (previousSibling) { + // then we are walking child = this.getNextSibling(previousSibling); } else { child = this.getFirstChild(node); diff --git a/devtools/client/shared/widgets/AbstractTreeItem.jsm b/devtools/client/shared/widgets/AbstractTreeItem.jsm index 8d7bf17b92b8..e40b37bdeca4 100644 --- a/devtools/client/shared/widgets/AbstractTreeItem.jsm +++ b/devtools/client/shared/widgets/AbstractTreeItem.jsm @@ -6,7 +6,6 @@ "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"); @@ -376,11 +375,10 @@ AbstractTreeItem.prototype = { // 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(); } }, diff --git a/devtools/client/shared/widgets/SideMenuWidget.jsm b/devtools/client/shared/widgets/SideMenuWidget.jsm index a5ceef0f1e47..3b617bcfdc03 100644 --- a/devtools/client/shared/widgets/SideMenuWidget.jsm +++ b/devtools/client/shared/widgets/SideMenuWidget.jsm @@ -173,7 +173,6 @@ SideMenuWidget.prototype = { * Removes all of the child nodes from this container. */ removeAllItems: function() { - let parent = this._parent; let list = this._list; while (list.hasChildNodes()) { @@ -486,9 +485,8 @@ function SideMenuGroup(aWidget, aName, aOptions = {}) { 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", ""); @@ -596,9 +594,8 @@ function SideMenuItem(aGroup, aContents, aAttachment = {}, aOptions = {}) { 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", ""); diff --git a/devtools/client/shared/widgets/VariablesView.jsm b/devtools/client/shared/widgets/VariablesView.jsm index 0de9a83c52d6..099e75478cbb 100644 --- a/devtools/client/shared/widgets/VariablesView.jsm +++ b/devtools/client/shared/widgets/VariablesView.jsm @@ -1163,13 +1163,11 @@ VariablesView.getterOrSetterEvalMacro = function(aItem, aCurrentString, aPrefix // 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; @@ -1915,9 +1913,8 @@ Scope.prototype = { 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 @@ -2569,10 +2566,9 @@ Variable.prototype = extend(Scope.prototype, { 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; } @@ -3339,10 +3335,12 @@ VariablesView.getGrip = function(aValue) { 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) }; @@ -3407,6 +3405,7 @@ VariablesView.getString = function(aGrip, aOptions = {}) { if (!aGrip && 1 / aGrip === -Infinity) { return "-0"; } + // fall through default: return aGrip + ""; } diff --git a/devtools/client/shared/widgets/VariablesViewController.jsm b/devtools/client/shared/widgets/VariablesViewController.jsm index 78cd4a4ecc09..dd0048b53e9c 100644 --- a/devtools/client/shared/widgets/VariablesViewController.jsm +++ b/devtools/client/shared/widgets/VariablesViewController.jsm @@ -509,6 +509,7 @@ VariablesViewController.prototype = { 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) { @@ -827,9 +828,8 @@ var StackFrameUtils = this.StackFrameUtils = { // 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); }