Bug 1361760 - Enable some Mozilla ESLint recommended rules for dom/indexedDB/test/unit. r?bevis draft
authorMark Banner <standard8@mozilla.com>
Tue, 25 Apr 2017 21:53:00 +0100
changeset 580256 8c8b7eb5f00bfd9b0c49bfb3d2db58ae913d8795
parent 580040 baf05f61bc14fdf45511bc1165ce76daa08c5c0f
child 580257 174e670659fd9f96ed9a9390d97722fb1c836e73
push id59483
push userbmo:standard8@mozilla.com
push dateThu, 18 May 2017 08:56:48 +0000
reviewersbevis
bugs1361760
milestone55.0a1
Bug 1361760 - Enable some Mozilla ESLint recommended rules for dom/indexedDB/test/unit. r?bevis MozReview-Commit-ID: CM8apJcdRVs
dom/indexedDB/test/unit/.eslintrc.js
dom/indexedDB/test/unit/GlobalObjectsChild.js
dom/indexedDB/test/unit/GlobalObjectsSandbox.js
dom/indexedDB/test/unit/test_add_put.js
dom/indexedDB/test/unit/test_autoIncrement.js
dom/indexedDB/test/unit/test_complex_keyPaths.js
dom/indexedDB/test/unit/test_cursor_update_updates_indexes.js
dom/indexedDB/test/unit/test_database_onclose.js
dom/indexedDB/test/unit/test_filehandle_append_read_data.js
dom/indexedDB/test/unit/test_globalObjects_other.js
dom/indexedDB/test/unit/test_index_empty_keyPath.js
dom/indexedDB/test/unit/test_setVersion_throw.js
dom/indexedDB/test/unit/test_transaction_error.js
dom/indexedDB/test/unit/test_unique_index_update.js
dom/indexedDB/test/unit/xpcshell-head-child-process.js
dom/indexedDB/test/unit/xpcshell-head-parent-process.js
tools/lint/eslint/eslint-plugin-mozilla/lib/configs/recommended.js
tools/lint/eslint/eslint-plugin-mozilla/lib/helpers.js
new file mode 100644
--- /dev/null
+++ b/dom/indexedDB/test/unit/.eslintrc.js
@@ -0,0 +1,31 @@
+"use strict";
+
+module.exports = {
+  "extends": [
+    "plugin:mozilla/recommended",
+    "plugin:mozilla/xpcshell-test",
+  ],
+  "plugins": [
+    "mozilla"
+  ],
+  "rules": {
+    "brace-style": "off",
+    "comma-spacing": "off",
+    "func-call-spacing": "off",
+    "key-spacing": "off",
+    "keyword-spacing": "off",
+    "no-extra-semi": "off",
+    "no-lonely-if": "off",
+    "no-mixed-spaces-and-tabs": "off",
+    "no-multi-spaces": "off",
+    "no-shadow": "off",
+    "no-trailing-spaces": "off",
+    "no-unused-vars": "off",
+    "object-shorthand": "off",
+    "quotes": "off",
+    "spaced-comment": "off",
+    "space-before-blocks": "off",
+    "space-before-function-paren": "off",
+    "space-infix-ops": "off"
+  }
+};
--- a/dom/indexedDB/test/unit/GlobalObjectsChild.js
+++ b/dom/indexedDB/test/unit/GlobalObjectsChild.js
@@ -1,13 +1,15 @@
 /**
  * Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/
  */
 
+/* import-globals-from xpcshell-head-parent-process.js */
+
 function ok(cond, msg) {
   dump("ok(" + cond + ", \"" + msg + "\")");
   do_check_true(!!cond, Components.stack.caller);
 }
 
 function finishTest()
 {
   do_execute_soon(function() {
--- a/dom/indexedDB/test/unit/GlobalObjectsSandbox.js
+++ b/dom/indexedDB/test/unit/GlobalObjectsSandbox.js
@@ -1,13 +1,15 @@
 /**
  * Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/
  */
 
+/* import-globals-from xpcshell-head-parent-process.js */
+
 function runTest() {
   const name = "Splendid Test";
 
   let keyRange = IDBKeyRange.only(42);
   ok(keyRange, "Got keyRange");
 
   let request = indexedDB.open(name, 1);
   request.onerror = function(event) {
--- a/dom/indexedDB/test/unit/test_add_put.js
+++ b/dom/indexedDB/test/unit/test_add_put.js
@@ -31,21 +31,21 @@ function* testSteps()
 
             // Create store
             if (db.objectStoreNames.contains("mystore"))
               db.deleteObjectStore("mystore");
             let store = db.createObjectStore("mystore",
                                              { autoIncrement: autoincrement,
                                                keyPath: (keypath ? "id" : null) });
 
-            test = " for test " + JSON.stringify({ autoincrement: autoincrement,
-                                                   keypath: keypath,
-                                                   method: method,
-                                                   explicit: explicit === undefined ? "undefined" : explicit,
-                                                   existing: existing });
+            let test = " for test " + JSON.stringify({ autoincrement: autoincrement,
+                                                       keypath: keypath,
+                                                       method: method,
+                                                       explicit: explicit === undefined ? "undefined" : explicit,
+                                                       existing: existing });
 
             // Insert "existing" data if needed
             if (existing) {
               if (keypath)
                 store.add({ existing: "data", id: 5 }).onsuccess = grabEventAndContinueHandler;
               else
                 store.add({ existing: "data" }, 5).onsuccess = grabEventAndContinueHandler;
 
@@ -59,17 +59,17 @@ function* testSteps()
             if (keypath === true) {
               value.id = 5;
             }
             else if (keypath === "invalid") {
               value.id = /x/;
             }
 
             // Which arguments are passed to function
-            args = [value];
+            let args = [value];
             if (explicit === true) {
               args.push(5);
             }
             else if (explicit === undefined) {
               args.push(undefined);
             }
             else if (explicit === "invalid") {
               args.push(/x/);
@@ -133,17 +133,17 @@ function* testSteps()
                JSON.stringify(value),
                "read back should return correct value" + test);
           }
         }
       }
     }
   }
 
-  
+
   function expectedResult(method, keypath, explicit, autoincrement, existing) {
     if (keypath && explicit)
       return "throw";
     if (!keypath && !explicit && !autoincrement)
       return "throw";
     if (keypath == "invalid")
       return "throw";
     if (keypath == "missing" && !autoincrement)
--- a/dom/indexedDB/test/unit/test_autoIncrement.js
+++ b/dom/indexedDB/test/unit/test_autoIncrement.js
@@ -197,17 +197,17 @@ function* testSteps()
     genCheck(c2, { explicit: 10, id: c2 }, "tenth store2" + test);
   c2++;
   yield undefined;
 
 
   // Test separate transactions doesn't generate overlapping numbers
   test = " for test non-overlapping counts";
   trans = db.transaction("store1", RW);
-  trans2 = db.transaction("store1", RW);
+  let trans2 = db.transaction("store1", RW);
   trans2.objectStore("store1").put({ over: 2 }).onsuccess =
     genCheck(c1 + 1, { over: 2 }, "first" + test,
              { trans: trans2 });
   trans.objectStore("store1").put({ over: 1 }).onsuccess =
     genCheck(c1, { over: 1 }, "second" + test,
              { trans: trans });
   c1 += 2;
   yield undefined; yield undefined;
--- a/dom/indexedDB/test/unit/test_complex_keyPaths.js
+++ b/dom/indexedDB/test/unit/test_complex_keyPaths.js
@@ -95,17 +95,17 @@ function* testSteps()
         is(e.code, DOMException.SYNTAX_ERR, "expect a syntax error" + test);
         continue;
       }
     }
 
     let store = stores[indexName];
 
     try {
-      request = store.add(info.value);
+      var request = store.add(info.value);
       ok("key" in info, "successfully created request to insert value" + test);
     } catch (e) {
       ok(!("key" in info), "threw when attempted to insert" + test);
       ok(e instanceof DOMException, "Got a DOMException" + test);
       is(e.name, "DataError", "expect a DataError" + test);
       is(e.code, 0, "expect zero" + test);
       continue;
     }
@@ -180,28 +180,28 @@ function* testSteps()
       } catch (e) {
         ok("exception" in info, "should throw" + test);
         is(e.name, "SyntaxError", "expect a SyntaxError" + test);
         ok(e instanceof DOMException, "Got a DOM Exception" + test);
         is(e.code, DOMException.SYNTAX_ERR, "expect a syntax error" + test);
         continue;
       }
     }
-    
+
     let index = indexes[indexName];
 
     request = store.add(info.value, 1);
     if ("key" in info) {
       index.getKey(info.key).onsuccess = grabEventAndContinueHandler;
-      e = yield undefined;
+      let e = yield undefined;
       is(e.target.result, 1, "found value when reading" + test);
     }
     else {
       index.count().onsuccess = grabEventAndContinueHandler;
-      e = yield undefined;
+      let e = yield undefined;
       is(e.target.result, 0, "should be empty" + test);
     }
 
     store.clear().onsuccess = grabEventAndContinueHandler;
     yield undefined;
   }
 
   // Autoincrement and complex key paths
--- a/dom/indexedDB/test/unit/test_cursor_update_updates_indexes.js
+++ b/dom/indexedDB/test/unit/test_cursor_update_updates_indexes.js
@@ -21,21 +21,21 @@ function* testSteps()
       entry: { data: START_DATA } },
   ];
 
   for (let i = 0; i < objectStoreInfo.length; i++) {
     // Create our object stores.
     let info = objectStoreInfo[i];
 
     ok(true, "1");
-    request = indexedDB.open(name, i + 1);
+    let request = indexedDB.open(name, i + 1);
     request.onerror = errorHandler;
     request.onupgradeneeded = grabEventAndContinueHandler;
     request.onsuccess = grabEventAndContinueHandler;
-    event = yield undefined;
+    let event = yield undefined;
 
     let db = event.target.result;
 
     ok(true, "2");
     let objectStore = info.hasOwnProperty("options") ?
                       db.createObjectStore(info.name, info.options) :
                       db.createObjectStore(info.name);
 
@@ -90,9 +90,8 @@ function* testSteps()
     // Wait for success
     yield undefined;
 
     db.close();
   }
 
   finishTest();
 }
-
--- a/dom/indexedDB/test/unit/test_database_onclose.js
+++ b/dom/indexedDB/test/unit/test_database_onclose.js
@@ -210,17 +210,17 @@ function* testSteps()
     }
   }
 
   clearAllDatabases(() => {
     info("clearAllDatabases is done.");
     continueToNextStep();
   });
 
-  readRequestError = yield undefined;
+  let readRequestError = yield undefined;
   if (readRequestError) {
     txn.onerror = grabEventAndContinueHandler;
 
     event = yield undefined;
     is(event.type, "error", "Got an error event");
     is(event.target.error.name, "AbortError", "Expected AbortError was thrown.");
     event.preventDefault();
 
--- a/dom/indexedDB/test/unit/test_filehandle_append_read_data.js
+++ b/dom/indexedDB/test/unit/test_filehandle_append_read_data.js
@@ -1,13 +1,15 @@
 /**
  * Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/
  */
 
+/* import-globals-from ../file.js */
+
 var disableWorkerTest = "FileHandle doesn't work in workers yet";
 
 var testGenerator = testSteps();
 
 function* testSteps()
 {
   const name = this.window ? window.location.pathname : "Splendid Test";
 
--- a/dom/indexedDB/test/unit/test_globalObjects_other.js
+++ b/dom/indexedDB/test/unit/test_globalObjects_other.js
@@ -12,16 +12,17 @@ function* testSteps()
 
   function getSpec(filename) {
     let file = do_get_file(filename);
     let uri = ioService.newFileURI(file);
     return uri.spec;
   }
 
   // Test for IDBKeyRange and indexedDB availability in JS modules.
+  /* import-globals-from GlobalObjectsModule.jsm */
   Cu.import(getSpec("GlobalObjectsModule.jsm"));
   let test = new GlobalObjectsModule();
   test.ok = ok;
   test.finishTest = continueToNextStep;
   test.runTest();
   yield undefined;
 
   // Test for IDBKeyRange and indexedDB availability in JS components.
--- a/dom/indexedDB/test/unit/test_index_empty_keyPath.js
+++ b/dom/indexedDB/test/unit/test_index_empty_keyPath.js
@@ -40,36 +40,36 @@ function* testSteps()
   event = yield undefined; // testGenerator.send
 
   // Now create the index.
   objectStore.createIndex("set", "", { unique: true });
   yield undefined; // success
 
   let trans = db.transaction("data", "readwrite");
   objectStore = trans.objectStore("data");
-  index = objectStore.index("set");
+  let index = objectStore.index("set");
 
   request = index.get("bar");
   request.onerror = errorHandler;
   request.onsuccess = grabEventAndContinueHandler;
-  
+
   event = yield undefined;
 
   is(event.target.result, "bar", "Got correct result");
 
   request = objectStore.add("foopy", 4);
   request.onerror = errorHandler;
   request.onsuccess = grabEventAndContinueHandler;
 
   yield undefined;
 
   request = index.get("foopy");
   request.onerror = errorHandler;
   request.onsuccess = grabEventAndContinueHandler;
-  
+
   event = yield undefined;
 
   is(event.target.result, "foopy", "Got correct result");
 
   request = objectStore.add("foopy", 5);
   request.addEventListener("error", new ExpectError("ConstraintError", true));
   request.onsuccess = unexpectedSuccessHandler;
 
--- a/dom/indexedDB/test/unit/test_setVersion_throw.js
+++ b/dom/indexedDB/test/unit/test_setVersion_throw.js
@@ -34,16 +34,17 @@ function* testSteps()
   yield undefined;
 
   request = indexedDB.open(name, 2);
   request.onerror = grabEventAndContinueHandler;
   request.onsuccess = unexpectedSuccessHandler;
   request.onupgradeneeded = function(event) {
     info("Got upgradeneeded event for db 2");
     expectUncaughtException(true);
+    // eslint-disable-next-line no-undef
     trigger_js_exception_by_calling_a_nonexistent_function();
   };
   event = yield undefined;
 
   event.preventDefault();
 
   is(event.type, "error", "Got an error event for db 2");
   ok(event.target.error instanceof DOMError, "Request has a DOMError");
--- a/dom/indexedDB/test/unit/test_transaction_error.js
+++ b/dom/indexedDB/test/unit/test_transaction_error.js
@@ -84,16 +84,17 @@ function* testSteps() {
   transaction.onerror = grabEventAndContinueHandler;
   transaction.onabort = grabEventAndContinueHandler;
 
   objectStore = transaction.objectStore(objectStoreName);
 
   info("Adding duplicate entry without preventDefault()");
 
   if ("SimpleTest" in this) {
+    /* global SimpleTest */
     SimpleTest.expectUncaughtException();
   } else if ("DedicatedWorkerGlobalScope" in self &&
              self instanceof DedicatedWorkerGlobalScope) {
     let oldErrorFunction = self.onerror;
     self.onerror = function(message, file, line) {
       self.onerror = oldErrorFunction;
       oldErrorFunction = null;
 
--- a/dom/indexedDB/test/unit/test_unique_index_update.js
+++ b/dom/indexedDB/test/unit/test_unique_index_update.js
@@ -26,17 +26,17 @@ function* testSteps()
       objectStore.add({ id: i, index: i });
     }
   }
 
   event = yield undefined;
   is(event.type, "success", "expect a success event");
 
   for (let autoIncrement of [false, true]) {
-    objectStore = db.transaction(autoIncrement, "readwrite")
+    let objectStore = db.transaction(autoIncrement, "readwrite")
                     .objectStore(autoIncrement);
 
     request = objectStore.put({ id: 5, index: 6 });
     request.onsuccess = unexpectedSuccessHandler;
     request.addEventListener("error", new ExpectError("ConstraintError", true));
     event = yield undefined;
 
     event.preventDefault();
--- a/dom/indexedDB/test/unit/xpcshell-head-child-process.js
+++ b/dom/indexedDB/test/unit/xpcshell-head-child-process.js
@@ -10,16 +10,18 @@ function run_test() {
   const INDEXEDDB_PREF_EXPERIMENTAL = "dom.indexedDB.experimental";
 
   // IndexedDB needs a profile.
   do_get_profile();
 
   let thisTest = _TEST_FILE.toString().replace(/\\/g, "/");
   thisTest = thisTest.substring(thisTest.lastIndexOf("/") + 1);
 
+  // This is defined globally via xpcshell.
+  /* global _HEAD_FILES */
   _HEAD_FILES.push(do_get_file(INDEXEDDB_HEAD_FILE).path.replace(/\\/g, "/"));
 
 
   let prefs =
     Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefService)
                                             .getBranch(null);
   prefs.setBoolPref(INDEXEDDB_PREF_EXPERIMENTAL, true);
 
--- a/dom/indexedDB/test/unit/xpcshell-head-parent-process.js
+++ b/dom/indexedDB/test/unit/xpcshell-head-parent-process.js
@@ -1,13 +1,16 @@
 /**
  * Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/
  */
 
+// Tests using testGenerator are expected to define it themselves.
+/* global testGenerator */
+
 var { 'classes': Cc, 'interfaces': Ci, 'utils': Cu } = Components;
 
 if (!("self" in this)) {
   this.self = this;
 }
 
 const DOMException = Ci.nsIDOMDOMException;
 
--- a/tools/lint/eslint/eslint-plugin-mozilla/lib/configs/recommended.js
+++ b/tools/lint/eslint/eslint-plugin-mozilla/lib/configs/recommended.js
@@ -11,31 +11,35 @@ module.exports = {
     "BrowserFeedWriter": false,
     "CSSPrimitiveValue": false,
     "CSSValueList": false,
     // Specific to Firefox (Chrome code only).
     "ChromeUtils": false,
     "ChromeWindow": false,
     "ChromeWorker": false,
     "Components": false,
+    "DedicatedWorkerGlobalScope": false,
+    "IDBLocaleAwareKeyRange": false,
+    "IDBMutableFile": false,
     "ImageDocument": false,
     "InstallTrigger": false,
     // Specific to Firefox
     // eslint-disable-next-line max-len
     // https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/InternalError
     "InternalError": true,
     "KeyEvent": false,
     "MenuBoxObject": false,
     // Specific to Firefox (Chrome code only).
     "MozSelfSupport": false,
     "SharedArrayBuffer": false,
     "SimpleGestureEvent": false,
     // Note: StopIteration will likely be removed as part of removing legacy
     // generators, see bug 968038.
     "StopIteration": false,
+    "WebAssembly": false,
     // Non-standard, specific to Firefox.
     "XULElement": false,
     "dump": true,
     "openDialog": 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
--- a/tools/lint/eslint/eslint-plugin-mozilla/lib/helpers.js
+++ b/tools/lint/eslint/eslint-plugin-mozilla/lib/helpers.js
@@ -384,17 +384,18 @@ module.exports = {
       return [];
     }
 
     let filepath = this.cleanUpPath(scope.getFilename());
     let dir = path.dirname(filepath);
 
     let names =
       fs.readdirSync(dir)
-        .filter(name => name.startsWith("head") && name.endsWith(".js"))
+        .filter(name => (name.startsWith("head") ||
+                         name.startsWith("xpcshell-head")) && name.endsWith(".js"))
         .map(name => path.join(dir, name));
     return names;
   },
 
   /**
    * Gets all the test manifest data for a directory
    *
    * @param  {String} dir