Bug 1335813 - Enable eslint no-undef for toolkit, apart from components/ and content/, and fix various issues. r?jaws draft
authorMark Banner <standard8@mozilla.com>
Tue, 31 Jan 2017 13:17:03 +0000
changeset 469175 a054bab6d80ab75c69781cb0cf24d5df3b2a1859
parent 469123 f3d187bd0733b1182dffc97b5dfe623e18f92a44
child 544117 ade8b2bc4c5d1db64ec44cc3792a2d990de0d093
push id43639
push usermbanner@mozilla.com
push dateWed, 01 Feb 2017 20:07:02 +0000
reviewersjaws
bugs1335813
milestone54.0a1
Bug 1335813 - Enable eslint no-undef for toolkit, apart from components/ and content/, and fix various issues. r?jaws MozReview-Commit-ID: LpXm7TbwvDb
browser/.eslintrc.js
testing/mochitest/browser.eslintrc.js
testing/xpcshell/xpcshell.eslintrc.js
toolkit/.eslintrc.js
toolkit/components/.eslintrc.js
toolkit/content/.eslintrc.js
toolkit/crashreporter/test/unit/crasher_subprocess_tail.js
toolkit/crashreporter/test/unit/test_crashreporter_appmem.js
toolkit/modules/GMPInstallManager.jsm
toolkit/modules/ObjectUtils.jsm
toolkit/modules/Promise-backend.js
toolkit/modules/ZipUtils.jsm
toolkit/modules/moz.build
toolkit/modules/tests/MockDocument.jsm
toolkit/modules/tests/PromiseTestUtils.jsm
toolkit/modules/tests/browser/browser_InlineSpellChecker.js
toolkit/modules/tests/browser/testremotepagemanager.html
toolkit/modules/tests/modules/.eslintrc.js
toolkit/modules/tests/modules/MockDocument.jsm
toolkit/modules/tests/modules/PromiseTestUtils.jsm
toolkit/modules/tests/xpcshell/test_ObjectUtils.js
toolkit/modules/tests/xpcshell/test_sqlite.js
toolkit/mozapps/installer/js-compare-ast.js
--- a/browser/.eslintrc.js
+++ b/browser/.eslintrc.js
@@ -1,11 +1,12 @@
 "use strict";
 
 module.exports = {
   "extends": [
     "../toolkit/.eslintrc.js"
   ],
 
   "rules": {
-    "no-shadow": "error"
+    "no-shadow": "error",
+    "no-undef": "off"
   }
 };
--- a/testing/mochitest/browser.eslintrc.js
+++ b/testing/mochitest/browser.eslintrc.js
@@ -33,16 +33,17 @@ module.exports = {
     "getRootDirectory": false,
     "getTestFilePath": false,
     "gTestPath": false,
     "info": false,
     "ignoreAllUncaughtExceptions": false,
     "is": false,
     "isnot": false,
     "ok": false,
+    "PromiseDebugging": false,
     "privateNoteIntentionalCrash": false,
     "registerCleanupFunction": false,
     "requestLongerTimeout": false,
     "SpecialPowers": false,
     "TestUtils": false,
     "thisTestLeaksUncaughtRejectionsAndShouldBeFixed": false,
     "todo": false,
     "todo_is": false,
--- a/testing/xpcshell/xpcshell.eslintrc.js
+++ b/testing/xpcshell/xpcshell.eslintrc.js
@@ -47,16 +47,17 @@ module.exports = {
     "less": false,
     "lessOrEqual": false,
     "load": false,
     "mozinfo": false,
     "notDeepEqual": false,
     "notEqual": false,
     "notStrictEqual": false,
     "ok": false,
+    "PromiseDebugging": false,
     "runningInParent": false,
     "run_next_test": false,
     "run_test": false,
     "run_test_in_child": false,
     // Defined in XPCShellImpl.
     "sendCommand": false,
     "strictEqual": false,
     "throws": false,
--- a/toolkit/.eslintrc.js
+++ b/toolkit/.eslintrc.js
@@ -164,17 +164,17 @@ module.exports = {
 
     // Disallow sparse arrays
     "no-sparse-arrays": "error",
 
     // No trailing whitespace
     "no-trailing-spaces": "error",
 
     // No using undeclared variables
-    // "no-undef": "error",
+    "no-undef": "error",
 
     // Error on newline where a semicolon is needed
     "no-unexpected-multiline": "error",
 
     // No unreachable statements
     "no-unreachable": "error",
 
     // Disallow control flow statements in finally blocks
--- a/toolkit/components/.eslintrc.js
+++ b/toolkit/components/.eslintrc.js
@@ -1,6 +1,7 @@
 "use strict";
 
 module.exports = {
   "rules": {
+    "no-undef": "off"
   }
 };
new file mode 100644
--- /dev/null
+++ b/toolkit/content/.eslintrc.js
@@ -0,0 +1,7 @@
+"use strict";
+
+module.exports = {
+  "rules": {
+    "no-undef": "off"
+  }
+};
--- a/toolkit/crashreporter/test/unit/crasher_subprocess_tail.js
+++ b/toolkit/crashreporter/test/unit/crasher_subprocess_tail.js
@@ -1,8 +1,10 @@
+/* import-globals-from crasher_subprocess_head.js */
+
 // Let the event loop process a bit before crashing.
 if (shouldDelay) {
   let shouldCrashNow = false;
   let thr = Components.classes["@mozilla.org/thread-manager;1"]
                           .getService().currentThread;
   thr.dispatch({ run: () => { shouldCrashNow = true; } },
                Components.interfaces.nsIThread.DISPATCH_NORMAL);
 
--- a/toolkit/crashreporter/test/unit/test_crashreporter_appmem.js
+++ b/toolkit/crashreporter/test/unit/test_crashreporter_appmem.js
@@ -1,11 +1,11 @@
 function run_test() {
   do_crash(function() {
-	     appAddr = CrashTestUtils.saveAppMemory();
-	     crashReporter.registerAppMemory(appAddr, 32);
-           },
-	   function(mdump, extra) {
-             do_check_true(mdump.exists());
-             do_check_true(mdump.fileSize > 0);
-             do_check_true(CrashTestUtils.dumpCheckMemory(mdump.path));
-           });
+    let appAddr = CrashTestUtils.saveAppMemory();
+    crashReporter.registerAppMemory(appAddr, 32);
+  },
+  function(mdump, extra) {
+    do_check_true(mdump.exists());
+    do_check_true(mdump.fileSize > 0);
+    do_check_true(CrashTestUtils.dumpCheckMemory(mdump.path));
+  });
 }
--- a/toolkit/modules/GMPInstallManager.jsm
+++ b/toolkit/modules/GMPInstallManager.jsm
@@ -133,16 +133,17 @@ GMPInstallManager.prototype = {
    *         The promise will reject with an error object:
    *           target: The XHR request object
    *           status: The HTTP status code
    *           type: A string to represent the type of error
    *                 downloaderr, verifyerr or previouserrorencountered
    */
   installAddon(gmpAddon) {
     if (this._deferred) {
+        let log = getScopedLogger("GMPInstallManager.installAddon");
         log.error("previous error encountered");
         return Promise.reject({type: "previouserrorencountered"});
     }
     this.gmpDownloader = new GMPDownloader(gmpAddon);
     return this.gmpDownloader.start();
   },
   _getTimeSinceLastCheck() {
     let now = Math.round(Date.now() / 1000);
--- a/toolkit/modules/ObjectUtils.jsm
+++ b/toolkit/modules/ObjectUtils.jsm
@@ -15,16 +15,18 @@ this.EXPORTED_SYMBOLS = [
 const {classes: Cc, interfaces: Ci, results: Cr, utils: Cu} = Components;
 
 Cu.import("resource://gre/modules/XPCOMUtils.jsm", this);
 
 // Used only to cause test failures.
 XPCOMUtils.defineLazyModuleGetter(this, "Promise",
   "resource://gre/modules/Promise.jsm");
 
+var pSlice = Array.prototype.slice;
+
 this.ObjectUtils = {
   /**
    * This tests objects & values for deep equality.
    *
    * We check using the most exact approximation of equality between two objects
    * to keep the chance of false positives to a minimum.
    * `JSON.stringify` is not designed to be used for this purpose; objects may
    * have ambiguous `toJSON()` implementations that would influence the test.
--- a/toolkit/modules/Promise-backend.js
+++ b/toolkit/modules/Promise-backend.js
@@ -34,16 +34,21 @@
 // the chrome module. Otherwise, this file is loaded as a subscript, and we can
 // obtain an instance of Cu from Components directly.
 //
 // If the file is loaded as a CommonJS module on a worker thread, the instance
 // of Cu obtained from the chrome module will be null. The reason for this is
 // that Components is not defined in worker threads, so no instance of Cu can
 // be obtained.
 
+// As this can be loaded in several ways, allow require and module to be defined.
+/* global module:false require:false */
+// This is allowed in workers.
+/* global setImmediate:false */
+
 var Cu = this.require ? require("chrome").Cu : Components.utils;
 var Cc = this.require ? require("chrome").Cc : Components.classes;
 var Ci = this.require ? require("chrome").Ci : Components.interfaces;
 // If we can access Components, then we use it to capture an async
 // parent stack trace; see scheduleWalkerLoop.  However, as it might
 // not be available (see above), users of this must check it first.
 var Components_ = this.require ? require("chrome").components : Components;
 
--- a/toolkit/modules/ZipUtils.jsm
+++ b/toolkit/modules/ZipUtils.jsm
@@ -52,23 +52,23 @@ function saveStreamAsync(aPath, aStream,
                createInstance(Ci.nsIBinaryInputStream);
   source.setInputStream(input);
 
 
   function readFailed(error) {
     try {
       aStream.close();
     } catch (e) {
-      logger.error("Failed to close JAR stream for " + aPath);
+      Cu.reportError("Failed to close JAR stream for " + aPath);
     }
 
     aFile.close().then(function() {
       deferred.reject(error);
     }, function(e) {
-      logger.error("Failed to close file for " + aPath);
+      Cu.reportError("Failed to close file for " + aPath);
       deferred.reject(error);
     });
   }
 
   function readData() {
     try {
       let count = Math.min(source.available(), EXTRACTION_BUFFER);
       let data = new Uint8Array(count);
--- a/toolkit/modules/moz.build
+++ b/toolkit/modules/moz.build
@@ -5,18 +5,18 @@
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 XPCSHELL_TESTS_MANIFESTS += ['tests/xpcshell/xpcshell.ini']
 BROWSER_CHROME_MANIFESTS += ['tests/browser/browser.ini']
 MOCHITEST_MANIFESTS += ['tests/mochitest/mochitest.ini']
 MOCHITEST_CHROME_MANIFESTS += ['tests/chrome/chrome.ini']
 
 TESTING_JS_MODULES += [
-    'tests/MockDocument.jsm',
-    'tests/PromiseTestUtils.jsm',
+    'tests/modules/MockDocument.jsm',
+    'tests/modules/PromiseTestUtils.jsm',
     'tests/xpcshell/TestIntegration.jsm',
 ]
 
 SPHINX_TREES['toolkit_modules'] = 'docs'
 
 EXTRA_JS_MODULES += [
     'addons/MatchPattern.jsm',
     'addons/WebNavigation.jsm',
--- a/toolkit/modules/tests/browser/browser_InlineSpellChecker.js
+++ b/toolkit/modules/tests/browser/browser_InlineSpellChecker.js
@@ -1,12 +1,14 @@
+var InlineSpellChecker;
+
 function test() {
   let tempScope = {};
   Components.utils.import("resource://gre/modules/InlineSpellChecker.jsm", tempScope);
-  let InlineSpellChecker = tempScope.InlineSpellChecker;
+  InlineSpellChecker = tempScope.InlineSpellChecker;
 
   ok(InlineSpellChecker, "InlineSpellChecker class exists");
   for (var fname in tests) {
     tests[fname]();
   }
 }
 
 var tests = {
--- a/toolkit/modules/tests/browser/testremotepagemanager.html
+++ b/toolkit/modules/tests/browser/testremotepagemanager.html
@@ -1,13 +1,15 @@
 <!DOCTYPE HTML>
 
 <html>
 <head>
 <script type="text/javascript">
+/* global addMessageListener, sendAsyncMessage, removeMessageListener */
+
 addMessageListener("Ping", function(message) {
   sendAsyncMessage("Pong", {
     str: message.data.str,
     counter: message.data.counter + 1
   });
 });
 
 addMessageListener("Ping2", function(message) {
new file mode 100644
--- /dev/null
+++ b/toolkit/modules/tests/modules/.eslintrc.js
@@ -0,0 +1,7 @@
+"use strict";
+
+module.exports = {
+  "extends": [
+    "../../../../testing/xpcshell/xpcshell.eslintrc.js"
+  ]
+};
rename from toolkit/modules/tests/MockDocument.jsm
rename to toolkit/modules/tests/modules/MockDocument.jsm
rename from toolkit/modules/tests/PromiseTestUtils.jsm
rename to toolkit/modules/tests/modules/PromiseTestUtils.jsm
--- a/toolkit/modules/tests/PromiseTestUtils.jsm
+++ b/toolkit/modules/tests/modules/PromiseTestUtils.jsm
@@ -1,16 +1,19 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
 /*
  * Detects and reports unhandled rejections during test runs. Test harnesses
  * will fail tests in this case, unless the test whitelists itself.
  */
 
+// For this test we allow the global Assert to be modified.
+/* global Assert:true */
+
 "use strict";
 
 this.EXPORTED_SYMBOLS = [
   "PromiseTestUtils",
 ];
 
 const { classes: Cc, interfaces: Ci, utils: Cu, results: Cr } = Components;
 
--- a/toolkit/modules/tests/xpcshell/test_ObjectUtils.js
+++ b/toolkit/modules/tests/xpcshell/test_ObjectUtils.js
@@ -96,9 +96,18 @@ add_task(function* test_deepEqual() {
   let c = {};
   c.b = c;
 
   try {
     Assert.ok(!deepEqual(b, c));
   } catch (e) {
     Assert.ok(true, "Didn't recurse infinitely.");
   }
+
+  let e = {a: 3, b: 4};
+  let f = {b: 4, a: 3};
+
+  function checkEquiv() {
+    return arguments;
+  }
+
+  Assert.ok(deepEqual(checkEquiv(e, f), checkEquiv(f, e)));
 });
--- a/toolkit/modules/tests/xpcshell/test_sqlite.js
+++ b/toolkit/modules/tests/xpcshell/test_sqlite.js
@@ -845,17 +845,16 @@ add_task(function* test_direct() {
   statement.executeAsync({
     handleResult(resultSet) {
     },
 
     handleError(error) {
       print("Error when executing SQL (" + error.result + "): " +
             error.message);
       print("Original error: " + error.error);
-      errors.push(error);
       deferred.reject();
     },
 
     handleCompletion(reason) {
       print("Completed.");
       deferred.resolve();
     }
   });
--- a/toolkit/mozapps/installer/js-compare-ast.js
+++ b/toolkit/mozapps/installer/js-compare-ast.js
@@ -7,16 +7,19 @@
  * The script exits with a 0 status code if both files parse properly and the
  * ASTs of both files are identical modulo location differences. The script
  * exits with status code 1 if any of these conditions don't hold.
  *
  * This script is used as part of packaging to verify minified JavaScript files
  * are identical to their original files.
  */
 
+// Available to the js shell.
+/* global snarf, scriptArgs, quit */
+
 "use strict";
 
 function ast(filename) {
   return JSON.stringify(Reflect.parse(snarf(filename), {loc: 0}));
 }
 
 if (scriptArgs.length !== 2) {
   throw "usage: js js-compare-ast.js FILE1.js FILE2.js";