Bug 1451378 - Enable ESLint rule no-undef for more test files in devtools. r?jdescottes draft
authorMark Banner <standard8@mozilla.com>
Wed, 04 Apr 2018 16:56:30 +0100
changeset 777460 af11d21e1ae59b3ac7237771d4849bac03c01765
parent 777163 ff0efa4132f0efd78af0910762aec7dcc1a8de66
push id105216
push userbmo:standard8@mozilla.com
push dateWed, 04 Apr 2018 20:09:15 +0000
reviewersjdescottes
bugs1451378
milestone61.0a1
Bug 1451378 - Enable ESLint rule no-undef for more test files in devtools. r?jdescottes MozReview-Commit-ID: 6q43u1m0hLI
devtools/.eslintrc.js
devtools/client/memory/test/browser/.eslintrc.js
devtools/client/memory/test/browser/browser_memory_displays_01.js
devtools/client/memory/test/browser/browser_memory_filter_01.js
devtools/client/memory/test/browser/browser_memory_individuals_01.js
devtools/client/memory/test/browser/browser_memory_keyboard-snapshot-list.js
devtools/client/memory/test/browser/browser_memory_keyboard.js
devtools/client/memory/test/browser/browser_memory_simple_01.js
devtools/client/memory/test/browser/head.js
devtools/client/memory/test/chrome/.eslintrc.js
devtools/client/memory/test/unit/.eslintrc.js
devtools/client/memory/test/unit/head.js
devtools/server/tests/browser/.eslintrc.js
devtools/server/tests/browser/browser_actor_error.js
devtools/server/tests/browser/browser_storage_cookies-duplicate-names.js
devtools/server/tests/browser/browser_storage_dynamic_windows.js
devtools/server/tests/browser/browser_storage_listings.js
devtools/server/tests/browser/doc_force_cc.html
devtools/server/tests/browser/doc_force_gc.html
devtools/server/tests/browser/error-actor.js
devtools/server/tests/browser/storage-helpers.js
devtools/shared/heapsnapshot/tests/unit/head_heapsnapshot.js
tools/lint/eslint/eslint-plugin-mozilla/lib/configs/recommended.js
tools/lint/eslint/eslint-plugin-mozilla/lib/configs/xpcshell-test.js
tools/lint/eslint/eslint-plugin-mozilla/lib/environments/jsm.js
--- a/devtools/.eslintrc.js
+++ b/devtools/.eslintrc.js
@@ -11,22 +11,18 @@ module.exports = {
     "module": true,
     "reportError": true,
     "require": true,
   },
   "overrides": [{
     // XXX Bug 1230193. We're still working on enabling no-undef for these test
     // directories.
     "files": [
-      "client/memory/test/**",
-      "server/tests/browser/**",
       "server/tests/mochitest/**",
-      "shared/heapsnapshot/tests/unit/**",
       "shared/tests/unit/**",
-      "shared/webconsole/test/**",
     ],
     "rules": {
       "no-undef": "off",
     }
   }],
   "rules": {
     // These are the rules that have been configured so far to match the
     // devtools coding style.
--- a/devtools/client/memory/test/browser/.eslintrc.js
+++ b/devtools/client/memory/test/browser/.eslintrc.js
@@ -1,17 +1,9 @@
 "use strict";
 
 module.exports = {
   // Extend from the shared list of defined globals for mochitests.
   "extends": "../../../../.eslintrc.mochitests.js",
-  "globals": {
-    "addTab": true,
-    "censusState": true,
-    "refreshTab": true,
-    "removeTab": true,
-    "waitForTime": true,
-    "waitUntilState": true
-  },
   "rules": {
     "no-unused-vars": ["error", { "vars": "local", "args": "none" }],
   }
 };
--- a/devtools/client/memory/test/browser/browser_memory_displays_01.js
+++ b/devtools/client/memory/test/browser/browser_memory_displays_01.js
@@ -2,17 +2,17 @@
    http://creativecommons.org/publicdomain/zero/1.0/ */
 "use strict";
 
 /**
  * Tests that the heap tree renders rows based on the display
  */
 
 const TEST_URL = "http://example.com/browser/devtools/client/memory/test/browser/doc_steady_allocation.html";
-const { viewState, censusState } = require("devtools/client/memory/constants");
+const { viewState } = require("devtools/client/memory/constants");
 const { changeView } = require("devtools/client/memory/actions/view");
 
 this.test = makeMemoryTest(TEST_URL, async function({ tab, panel }) {
   const { gStore, document } = panel.panelWin;
 
   const { dispatch } = panel.panelWin.gStore;
 
   function $$(selector) {
--- a/devtools/client/memory/test/browser/browser_memory_filter_01.js
+++ b/devtools/client/memory/test/browser/browser_memory_filter_01.js
@@ -3,17 +3,16 @@
 
 // Sanity test that we can show allocation stack displays in the tree.
 
 "use strict";
 
 const {
   dominatorTreeState,
   viewState,
-  censusState,
 } = require("devtools/client/memory/constants");
 const { changeViewAndRefresh, changeView } = require("devtools/client/memory/actions/view");
 
 const TEST_URL = "http://example.com/browser/devtools/client/memory/test/browser/doc_steady_allocation.html";
 
 this.test = makeMemoryTest(TEST_URL, async function({ tab, panel }) {
   const heapWorker = panel.panelWin.gHeapAnalysesClient;
   const store = panel.panelWin.gStore;
--- a/devtools/client/memory/test/browser/browser_memory_individuals_01.js
+++ b/devtools/client/memory/test/browser/browser_memory_individuals_01.js
@@ -4,17 +4,16 @@
 // Sanity test that we can show census group individuals, and then go back to
 // the previous view.
 
 "use strict";
 
 const {
   individualsState,
   viewState,
-  censusState,
 } = require("devtools/client/memory/constants");
 const { changeView } = require("devtools/client/memory/actions/view");
 
 const TEST_URL = "http://example.com/browser/devtools/client/memory/test/browser/doc_steady_allocation.html";
 
 this.test = makeMemoryTest(TEST_URL, async function({ tab, panel }) {
   const store = panel.panelWin.gStore;
   const { dispatch } = store;
--- a/devtools/client/memory/test/browser/browser_memory_keyboard-snapshot-list.js
+++ b/devtools/client/memory/test/browser/browser_memory_keyboard-snapshot-list.js
@@ -1,18 +1,17 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
 // Test that using ACCEL+UP/DOWN, the user can navigate between snapshots.
 
 "use strict";
 
 const {
-  viewState,
-  censusState
+  viewState
 } = require("devtools/client/memory/constants");
 const {
   takeSnapshotAndCensus
 } = require("devtools/client/memory/actions/snapshot");
 const { changeView } = require("devtools/client/memory/actions/view");
 
 const TEST_URL = "http://example.com/browser/devtools/client/memory/test/browser/doc_steady_allocation.html";
 
--- a/devtools/client/memory/test/browser/browser_memory_keyboard.js
+++ b/devtools/client/memory/test/browser/browser_memory_keyboard.js
@@ -2,17 +2,16 @@
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
 // Bug 1246570 - Check that when pressing on LEFT arrow, the parent tree node
 // gets focused.
 
 "use strict";
 
 const {
-  censusState,
   viewState
 } = require("devtools/client/memory/constants");
 const {
   takeSnapshotAndCensus
 } = require("devtools/client/memory/actions/snapshot");
 const { changeView } = require("devtools/client/memory/actions/view");
 
 const TEST_URL = "http://example.com/browser/devtools/client/memory/test/browser/doc_steady_allocation.html";
--- a/devtools/client/memory/test/browser/browser_memory_simple_01.js
+++ b/devtools/client/memory/test/browser/browser_memory_simple_01.js
@@ -3,17 +3,17 @@
 
 "use strict";
 
 /**
  * Tests taking snapshots and default states.
  */
 
 const TEST_URL = "http://example.com/browser/devtools/client/memory/test/browser/doc_steady_allocation.html";
-const { viewState, censusState } = require("devtools/client/memory/constants");
+const { viewState } = require("devtools/client/memory/constants");
 const { changeView } = require("devtools/client/memory/actions/view");
 
 this.test = makeMemoryTest(TEST_URL, async function({ tab, panel }) {
   const { gStore, document } = panel.panelWin;
   const { getState, dispatch } = gStore;
 
   dispatch(changeView(viewState.CENSUS));
 
--- a/devtools/client/memory/test/browser/head.js
+++ b/devtools/client/memory/test/browser/head.js
@@ -1,24 +1,26 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
 "use strict";
 
 // Load the shared test helpers into this compartment.
+/* import-globals-from ../../../shared/test/shared-head.js */
 Services.scriptloader.loadSubScript(
   "chrome://mochitests/content/browser/devtools/client/shared/test/shared-head.js",
   this);
 
 // Load the shared Redux helpers into this compartment.
+/* import-globals-from ../../../shared/test/shared-redux-head.js */
 Services.scriptloader.loadSubScript(
   "chrome://mochitests/content/browser/devtools/client/shared/test/shared-redux-head.js",
   this);
 
-var { censusDisplays, snapshotState: states } = require("devtools/client/memory/constants");
+var { censusDisplays, censusState, snapshotState: states } = require("devtools/client/memory/constants");
 var { L10N } = require("devtools/client/memory/utils");
 
 Services.prefs.setBoolPref("devtools.memory.enabled", true);
 
 /**
  * Open the memory panel for the given tab.
  */
 this.openMemoryPanel = async function(tab) {
--- a/devtools/client/memory/test/chrome/.eslintrc.js
+++ b/devtools/client/memory/test/chrome/.eslintrc.js
@@ -1,14 +1,9 @@
 "use strict";
 
 module.exports = {
   // Extend from the shared list of defined globals for mochitests.
   "extends": "../../../../.eslintrc.mochitests.js",
-  "globals": {
-    "SimpleTest": true,
-    "ok": true,
-    "requestAnimationFrame": true
-  },
   "rules": {
     "no-unused-vars": ["error", { "vars": "local", "args": "none" }],
   }
 };
--- a/devtools/client/memory/test/unit/.eslintrc.js
+++ b/devtools/client/memory/test/unit/.eslintrc.js
@@ -1,12 +1,11 @@
 "use strict";
 
 module.exports = {
   // Extend from the shared list of defined globals for mochitests.
   "extends": "../../../../.eslintrc.xpcshell.js",
   "rules": {
     "no-unused-vars": ["error", {
       "vars": "local",
-      "varsIgnorePattern": "^run_test$"
     }]
   }
 };
--- a/devtools/client/memory/test/unit/head.js
+++ b/devtools/client/memory/test/unit/head.js
@@ -1,13 +1,16 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
 "use strict";
 
+// via xpcshell.ini
+/* import-globals-from ../../../shared/test/shared-redux-head.js */
+
 var { require } = ChromeUtils.import("resource://devtools/shared/Loader.jsm", {});
 
 var Services = require("Services");
 var DevToolsUtils = require("devtools/shared/DevToolsUtils");
 var flags = require("devtools/shared/flags");
 flags.testing = true;
 flags.wantLogging = true;
 flags.wantVerbose = false;
--- a/devtools/server/tests/browser/.eslintrc.js
+++ b/devtools/server/tests/browser/.eslintrc.js
@@ -1,6 +1,6 @@
 "use strict";
 
 module.exports = {
   // Extend from the common devtools mochitest eslintrc config.
-  "extends": "../../../.eslintrc.xpcshell.js"
+  "extends": "../../../.eslintrc.mochitests.js"
 };
--- a/devtools/server/tests/browser/browser_actor_error.js
+++ b/devtools/server/tests/browser/browser_actor_error.js
@@ -21,18 +21,17 @@ async function test() {
 
   let transport = DebuggerServer.connectPipe();
   gClient = new DebuggerClient(transport);
   await gClient.connect();
 
   let { errorActor } = await gClient.listTabs();
   ok(errorActor, "Found the error actor.");
 
-  try {
-    await gClient.request({ to: globalActor, type: "error" });
-    ok(false, "The request is expected to fail.");
-  } catch (e) {
-    ok(true, "The request failed as expected, and was caught by the client");
-  }
+  await Assert.rejects(gClient.request({ to: errorActor, type: "error" }),
+    err => err.error == "unknownError" &&
+           /error occurred while processing 'error/.test(err.message),
+    "The request should be rejected");
+
   await gClient.close();
 
   finish();
 }
--- a/devtools/server/tests/browser/browser_storage_cookies-duplicate-names.js
+++ b/devtools/server/tests/browser/browser_storage_cookies-duplicate-names.js
@@ -3,16 +3,17 @@
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
 "use strict";
 
 // Test that the storage panel is able to display multiple cookies with the same
 // name (and different paths).
 
 const {StorageFront} = require("devtools/shared/fronts/storage");
+/* import-globals-from storage-helpers.js */
 Services.scriptloader.loadSubScript("chrome://mochitests/content/browser/devtools/server/tests/browser/storage-helpers.js", this);
 
 const TESTDATA = {
   "http://test1.example.org": [
     {
       name: "name",
       value: "value1",
       expires: 0,
--- a/devtools/server/tests/browser/browser_storage_dynamic_windows.js
+++ b/devtools/server/tests/browser/browser_storage_dynamic_windows.js
@@ -1,15 +1,16 @@
 /* vim: set ft=javascript ts=2 et sw=2 tw=80: */
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
 "use strict";
 
 const { StorageFront } = require("devtools/shared/fronts/storage");
+/* import-globals-from storage-helpers.js */
 Services.scriptloader.loadSubScript(
   "chrome://mochitests/content/browser/devtools/server/tests/browser/storage-helpers.js",
   this);
 
 // beforeReload references an object representing the initialized state of the
 // storage actor.
 const beforeReload = {
   cookies: {
--- a/devtools/server/tests/browser/browser_storage_listings.js
+++ b/devtools/server/tests/browser/browser_storage_listings.js
@@ -1,15 +1,16 @@
 /* vim: set ft=javascript ts=2 et sw=2 tw=80: */
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
 "use strict";
 
 const {StorageFront} = require("devtools/shared/fronts/storage");
+/* import-globals-from storage-helpers.js */
 Services.scriptloader.loadSubScript("chrome://mochitests/content/browser/devtools/server/tests/browser/storage-helpers.js", this);
 
 const storeMap = {
   cookies: {
     "http://test1.example.org": [
       {
         name: "c1",
         value: "foobar",
--- a/devtools/server/tests/browser/doc_force_cc.html
+++ b/devtools/server/tests/browser/doc_force_cc.html
@@ -7,16 +7,17 @@
     <meta charset="utf-8"/>
     <title>Performance tool + cycle collection test page</title>
   </head>
 
   <body>
     <script type="text/javascript">
     "use strict";
 
+    /* global test */
     window.test = function() {
       document.body.expando1 = { cycle: document.body };
       SpecialPowers.Cu.forceCC();
 
       document.body.expando2 = { cycle: document.body };
       SpecialPowers.Cu.forceCC();
 
       document.body.expando3 = { cycle: document.body };
--- a/devtools/server/tests/browser/doc_force_gc.html
+++ b/devtools/server/tests/browser/doc_force_gc.html
@@ -8,16 +8,17 @@
     <title>Performance tool + garbage collection test page</title>
   </head>
 
   <body>
     <script type="text/javascript">
     "use strict";
 
     var x = 1;
+    /* global test */
     window.test = function() {
       SpecialPowers.Cu.forceGC();
       document.body.style.borderTop = x + "px solid red";
       x = 1 ^ x;
       // flush pending reflows
       document.body.innerHeight;
 
       // Prevent this script from being garbage collected.
--- a/devtools/server/tests/browser/error-actor.js
+++ b/devtools/server/tests/browser/error-actor.js
@@ -1,15 +1,17 @@
 /* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
 /* vim: set ft=javascript ts=2 et sw=2 tw=80: */
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
 "use strict";
 
+/* global DebuggerServer */
+
 /**
  * Test actor designed to check that clients are properly notified of errors when calling
  * methods on old style actors.
  */
 function ErrorActor(conn, tab) {
   this.conn = conn;
   this.tab = tab;
 }
--- a/devtools/server/tests/browser/storage-helpers.js
+++ b/devtools/server/tests/browser/storage-helpers.js
@@ -1,11 +1,14 @@
 /* Any copyright is dedicated to the Public Domain.
    http://creativecommons.org/publicdomain/zero/1.0/ */
 
+// This file assumes head.js is loaded in the global scope.
+/* import-globals-from head.js */
+
 /* exported openTabAndSetupStorage, clearStorage */
 
 "use strict";
 
 /**
  * This generator function opens the given url in a new tab, then sets up the
  * page by waiting for all cookies, indexedDB items etc. to be created.
  *
--- a/devtools/shared/heapsnapshot/tests/unit/head_heapsnapshot.js
+++ b/devtools/shared/heapsnapshot/tests/unit/head_heapsnapshot.js
@@ -106,17 +106,17 @@ function getFilePath(name, allowMissing 
   let filePrePath = "file://";
   if ("nsILocalFileWin" in Ci &&
       file instanceof Ci.nsILocalFileWin) {
     filePrePath += "/";
   }
 
   path = path.slice(filePrePath.length);
 
-  if (sePlatformPathSeparator && path.match(/^\w:/)) {
+  if (usePlatformPathSeparator && path.match(/^\w:/)) {
     path = path.replace(/\//g, "\\");
   }
 
   return path;
 }
 
 function saveNewHeapSnapshot(opts = { runtime: true }) {
   const filePath = ChromeUtils.saveHeapSnapshot(opts);
@@ -330,17 +330,17 @@ function assertDiff(breakdown, first, se
  */
 function assertLabelAndShallowSize(breakdown, givenDescription,
   expectedShallowSize, expectedLabel) {
   dumpn("Computing label and shallow size from node description:");
   dumpn("Breakdown: " + JSON.stringify(breakdown, null, 4));
   dumpn("Given description: " + JSON.stringify(givenDescription, null, 4));
 
   const visitor = new LabelAndShallowSizeVisitor();
-  CensusUtils.walk(breakdown, description, visitor);
+  CensusUtils.walk(breakdown, givenDescription, visitor);
 
   dumpn("Expected shallow size: " + expectedShallowSize);
   dumpn("Actual shallow size: " + visitor.shallowSize());
   equal(visitor.shallowSize(), expectedShallowSize, "Shallow size should be correct");
 
   dumpn("Expected label: " + JSON.stringify(expectedLabel, null, 4));
   dumpn("Actual label: " + JSON.stringify(visitor.label(), null, 4));
   assertStructurallyEquivalent(visitor.label(), expectedLabel);
@@ -430,17 +430,17 @@ function assertDeduplicatedPaths({ targe
       if (edge.from === expectedEdge.from &&
           edge.to === expectedEdge.to &&
           edge.name === expectedEdge.name) {
         count++;
       }
     }
     equal(count, 1,
       "should have exactly one matching edge for the expected edge = "
-      + JSON.stringify(edge));
+      + JSON.stringify(expectedEdge));
   }
 }
 
 function assertCountToBucketBreakdown(breakdown, expected) {
   dumpn("count => bucket breakdown");
   dumpn("Initial breakdown = ", JSON.stringify(breakdown, null, 2));
   dumpn("Expected results = ", JSON.stringify(expected, null, 2));
 
--- a/tools/lint/eslint/eslint-plugin-mozilla/lib/configs/recommended.js
+++ b/tools/lint/eslint/eslint-plugin-mozilla/lib/configs/recommended.js
@@ -19,16 +19,17 @@ module.exports = {
     "ChromeWorker": false,
     "Ci": false,
     "Components": false,
     "Cr": false,
     "Cu": false,
     "DOMRequest": false,
     "Debugger": false,
     "DedicatedWorkerGlobalScope": false,
+    "DominatorTree": false,
     "HeapSnapshot": false,
     "IDBFileRequest": false,
     "IDBLocaleAwareKeyRange": false,
     "IDBMutableFile": false,
     "ImageDocument": false,
     "InstallTrigger": false,
     // Specific to Firefox
     // eslint-disable-next-line max-len
@@ -50,16 +51,17 @@ module.exports = {
     "WebExtensionContentScript": false,
     "WebExtensionPolicy": false,
     "WebrtcGlobalInformation": false,
     // Non-standard, specific to Firefox.
     "XULElement": false,
     "console": true,
     "dump": true,
     "openDialog": false,
+    "saveStack": false,
     "sizeToContent": false,
     // Specific to Firefox
     // eslint-disable-next-line max-len
     // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/uneval
     "uneval": false
   },
 
   "overrides": [{
--- a/tools/lint/eslint/eslint-plugin-mozilla/lib/configs/xpcshell-test.js
+++ b/tools/lint/eslint/eslint-plugin-mozilla/lib/configs/xpcshell-test.js
@@ -4,16 +4,19 @@
 module.exports = {
   // All globals made available in the test environment.
   "globals": {
     "Assert": false,
     "PromiseDebugging": false,
     "_TEST_FILE": false,
     "add_task": false,
     "add_test": false,
+    // Test-only function.
+    "allocationMarker": false,
+    "byteSize": false,
     "deepEqual": false,
     "do_await_remote_message": false,
     "do_check_instanceof": false,
     "do_get_cwd": false,
     "do_get_file": false,
     "do_get_idle": false,
     "do_get_profile": false,
     "do_get_tempdir": false,
@@ -24,16 +27,17 @@ module.exports = {
     "do_report_unexpected_exception": false,
     "do_send_remote_message": false,
     "do_test_finished": false,
     "do_test_pending": false,
     "do_throw": false,
     "do_timeout": false,
     "equal": false,
     "executeSoon": false,
+    "gc": false,
     // XPCShell specific function, see XPCShellEnvironment.cpp
     "gczeal": false,
     "greater": false,
     "greaterOrEqual": false,
     "info": false,
     "less": false,
     "lessOrEqual": false,
     "load": false,
--- a/tools/lint/eslint/eslint-plugin-mozilla/lib/environments/jsm.js
+++ b/tools/lint/eslint/eslint-plugin-mozilla/lib/environments/jsm.js
@@ -30,17 +30,16 @@ module.exports = {
     "AddonManagerPermissions": false,
     "ChannelWrapper": false,
     "ChromeUtils": false,
     "ChromeWorker": false,
     "DOMError": false,
     "DOMException": false,
     "DOMRequest": false,
     "DOMStringList": false,
-    "DominatorTree": false,
     "ErrorEvent": false,
     "Event": false,
     "EventTarget": false,
     "FileReader": false,
     "HeapSnapshot": false,
     "IDBCursor": false,
     "IDBCursorWithValue": false,
     "IDBDatabase": false,