Bug 1403959, part 3 - Manually fix some xpcom/ eslint failures and enable it. r=froydnj draft
authorAndrew McCreight <continuation@gmail.com>
Thu, 28 Sep 2017 16:12:52 -0700
changeset 682635 b075e7284d98d5bb7588abbe4f837a00fb79fff0
parent 682634 d0d3e4049436e4652072cd10b8e74fac4de9d97a
child 736391 61539977fb7577bb59480828541c93454a654519
push id85101
push userbmo:continuation@gmail.com
push dateWed, 18 Oct 2017 16:06:58 +0000
reviewersfroydnj
bugs1403959
milestone58.0a1
Bug 1403959, part 3 - Manually fix some xpcom/ eslint failures and enable it. r=froydnj Renames are because another location also defined that variable. Unused definitions are eliminated. The .eslintrc.js file makes eslint expect XPCShell global variables. MozReview-Commit-ID: Fafm5o45bme
.eslintignore
xpcom/string/crashtests/394275-1.html
xpcom/tests/unit/.eslintrc.js
xpcom/tests/unit/test_bug121341.js
xpcom/tests/unit/test_bug364285-1.js
xpcom/tests/unit/test_bug476919.js
xpcom/tests/unit/test_bug478086.js
xpcom/tests/unit/test_bug656331.js
xpcom/tests/unit/test_iniProcessor.js
xpcom/tests/unit/test_nsIMutableArray.js
xpcom/tests/unit/test_pipe.js
xpcom/tests/unit/test_seek_multiplex.js
xpcom/tests/unit/test_storagestream.js
--- a/.eslintignore
+++ b/.eslintignore
@@ -25,17 +25,16 @@ netwerk/**
 parser/**
 python/**
 rdf/**
 servo/**
 tools/update-packaging/**
 uriloader/**
 view/**
 widget/**
-xpcom/**
 
 # We currently have no js files in these directories, so we ignore them by
 # default to aid ESLint's performance.
 build/**
 config/**
 db/**
 gradle/**
 hal/**
--- a/xpcom/string/crashtests/394275-1.html
+++ b/xpcom/string/crashtests/394275-1.html
@@ -1,9 +1,9 @@
 <html>
 <body>
 <script>
-style = document.createElement("style");
-document.documentElement.appendChild(style);
-style.textContent = "tz\uDAB2 ";
+style = document.createElement("style"); // eslint-disable-line no-undef
+document.documentElement.appendChild(style); // eslint-disable-line no-undef
+style.textContent = "tz\uDAB2 "; // eslint-disable-line no-undef
 </script>
 </body>
 </html>
new file mode 100644
--- /dev/null
+++ b/xpcom/tests/unit/.eslintrc.js
@@ -0,0 +1,7 @@
+"use strict";
+
+module.exports = {
+  "extends": [
+    "plugin:mozilla/xpcshell-test"
+  ]
+};
--- a/xpcom/tests/unit/test_bug121341.js
+++ b/xpcom/tests/unit/test_bug121341.js
@@ -49,21 +49,21 @@ function run_test() {
   value = properties.getStringProperty("10a\u1234b");
   do_check_eq(value, "c\uCDEFd");
 
   value = properties.getStringProperty("11");
   do_check_eq(value, "\uABCD");
 
   dataFile = do_get_file("data/bug121341-2.properties");
 
-  var channel = NetUtil.newChannel({
+  var channel2 = NetUtil.newChannel({
     uri: ios.newFileURI(dataFile, null, null),
     loadUsingSystemPrincipal: true
   });
-  inp = channel.open2();
+  inp = channel2.open2();
 
   var properties2 = Components.classes["@mozilla.org/persistent-properties;1"].
                     createInstance(Components.interfaces.nsIPersistentProperties);
   try {
     properties2.load(inp);
     do_throw("load() didn't fail");
   } catch (e) {
   }
--- a/xpcom/tests/unit/test_bug364285-1.js
+++ b/xpcom/tests/unit/test_bug364285-1.js
@@ -8,27 +8,27 @@ var nameArray = [
  "\u65E5\u672C\u8A9E",                              // Japanese
  "\u4E2D\u6587",                                    // Chinese
  "\uD55C\uAD6D\uC5B4",                              // Korean
  "\uD801\uDC0F\uD801\uDC2D\uD801\uDC3B\uD801\uDC2B" // Deseret
 ];
 
 function getTempDir() {
     var dirService = Cc["@mozilla.org/file/directory_service;1"]
-	.getService(Ci.nsIProperties);
+        .getService(Ci.nsIProperties);
     return dirService.get("TmpD", Ci.nsIFile);
 }
 
 function create_file(fileName) {
     var outFile = getTempDir();
     outFile.append(fileName);
     outFile.createUnique(outFile.NORMAL_FILE_TYPE, 0o600);
 
     var stream = Cc["@mozilla.org/network/file-output-stream;1"]
-	.createInstance(Ci.nsIFileOutputStream);
+        .createInstance(Ci.nsIFileOutputStream);
     stream.init(outFile, 0x02 | 0x08 | 0x20, 0o600, 0);
     stream.write("foo", 3);
     stream.close();
 
     do_check_eq(outFile.leafName.substr(0, fileName.length), fileName);
 
     return outFile;
 }
@@ -37,11 +37,11 @@ function test_create(fileName) {
     var file1 = create_file(fileName);
     var file2 = create_file(fileName);
     file1.remove(false);
     file2.remove(false);
 }
 
 function run_test() {
     for (var i = 0; i < nameArray.length; ++i) {
-	test_create(nameArray[i]);
+        test_create(nameArray[i]);
     }
 }
--- a/xpcom/tests/unit/test_bug476919.js
+++ b/xpcom/tests/unit/test_bug476919.js
@@ -1,11 +1,13 @@
 var Cc = Components.classes;
 var Ci = Components.interfaces;
 
+/* global __LOCATION__ */
+
 function run_test() {
   // skip this test on Windows
   if (mozinfo.os != "win") {
     var testDir = __LOCATION__.parent;
     // create a test file, then symlink it, then check that we think it's a symlink
     var targetFile = testDir.clone();
     targetFile.append("target.txt");
     if (!targetFile.exists())
--- a/xpcom/tests/unit/test_bug478086.js
+++ b/xpcom/tests/unit/test_bug478086.js
@@ -8,17 +8,17 @@ function run_test() {
 
   // copied from http://mxr.mozilla.org/mozilla-central/source/image/test/unit/test_imgtools.js#135
   // nsIXULRuntime.OS doesn't seem to be available in xpcshell, so we'll use
   // this as a kludgy way to figure out if we're running on Windows.
   if (mozinfo.os == "win") {
     root.initWithPath("\\\\.");
   } else {
     return; // XXX disabled, since this causes intermittent failures on Mac (bug 481369).
-    root.initWithPath("/");
+    // root.initWithPath("/");
   }
   var drives = root.directoryEntries;
   do_check_true(drives.hasMoreElements());
   while (drives.hasMoreElements()) {
     var newPath = drives.getNext().QueryInterface(nsIFile).path;
     do_check_eq(newPath.indexOf("\0"), -1);
   }
 }
--- a/xpcom/tests/unit/test_bug656331.js
+++ b/xpcom/tests/unit/test_bug656331.js
@@ -1,10 +1,12 @@
 Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
 
+/* global registerAppManifest */
+
 var Cc = Components.classes;
 var Ci = Components.interfaces;
 
 function info(s) {
   dump("TEST-INFO | test_bug656331.js | " + s + "\n");
 }
 
 var gMessageExpected = /Native module.*has version 3.*expected/;
--- a/xpcom/tests/unit/test_iniProcessor.js
+++ b/xpcom/tests/unit/test_iniProcessor.js
@@ -8,17 +8,17 @@ var factory;
 function parserForFile(filename) {
     let parser = null;
     try {
         let file = do_get_file(filename);
         do_check_true(!!file);
         parser = factory.createINIParser(file);
         do_check_true(!!parser);
     } catch (e) {
-	dump("INFO | caught error: " + e);
+        dump("INFO | caught error: " + e);
         // checkParserOutput will handle a null parser when it's expected.
     }
     return parser;
 
 }
 
 function checkParserOutput(parser, expected) {
     // If the expected output is null, we expect the parser to have
--- a/xpcom/tests/unit/test_nsIMutableArray.js
+++ b/xpcom/tests/unit/test_nsIMutableArray.js
@@ -44,18 +44,18 @@ function test_insert_at_beginning() {
   var str = new SupportsString();
   str.data = "hello";
   arr.insertElementAt(str, 0, false);
   do_check_eq(6, arr.length);
   var obj = arr.queryElementAt(0, Ci.nsISupportsString);
   do_check_eq(str, obj);
   // check the data of all the other objects
   for (let i = 1; i < arr.length; i++) {
-    let obj = arr.queryElementAt(i, Ci.nsISupportsString);
-    do_check_eq("element " + (i - 1), obj.data);
+    let obj2 = arr.queryElementAt(i, Ci.nsISupportsString);
+    do_check_eq("element " + (i - 1), obj2.data);
   }
 }
 
 function test_replace_element() {
   var arr = create_n_element_array(5);
   // just a sanity check
   do_check_eq(5, arr.length);
   var str = new SupportsString();
--- a/xpcom/tests/unit/test_pipe.js
+++ b/xpcom/tests/unit/test_pipe.js
@@ -16,16 +16,17 @@ function run_test() {
   test_ends_are_threadsafe();
 }
 
 function test_not_initialized() {
   var p = Cc["@mozilla.org/pipe;1"]
             .createInstance(Ci.nsIPipe);
   try {
     var dummy = p.outputStream;
+    dump("dummy: " + dummy + "\n");
     throw Cr.NS_ERROR_FAILURE;
   } catch (e) {
     if (e.result != Cr.NS_ERROR_NOT_INITIALIZED)
       do_throw("using a pipe before initializing it should throw NS_ERROR_NOT_INITIALIZED");
   }
 }
 
 function test_ends_are_threadsafe() {
--- a/xpcom/tests/unit/test_seek_multiplex.js
+++ b/xpcom/tests/unit/test_seek_multiplex.js
@@ -12,21 +12,16 @@ const data = "0123456789";
 // Number of streams in the multiplex stream.
 const count = 10;
 
 function test_multiplex_streams() {
   var MultiplexStream = CC("@mozilla.org/io/multiplex-input-stream;1",
                            "nsIMultiplexInputStream");
   do_check_eq(1, 1);
 
-  var BinaryInputStream = Components.Constructor("@mozilla.org/binaryinputstream;1",
-                                                 "nsIBinaryInputStream");
-  var BinaryOutputStream = Components.Constructor("@mozilla.org/binaryoutputstream;1",
-                                                  "nsIBinaryOutputStream",
-                                                  "setOutputStream");
   var multiplex = new MultiplexStream();
   for (var i = 0; i < count; ++i) {
     let s = Cc["@mozilla.org/io/string-input-stream;1"]
               .createInstance(Ci.nsIStringInputStream);
     s.setData(data, data.length);
 
     multiplex.appendStream(s);
   }
@@ -129,42 +124,37 @@ function test_multiplex_streams() {
   seekable.seek(Ci.nsISeekableStream.NS_SEEK_SET, data.length * count);
   do_check_eq(seekable.tell(), 100);
   seekable.seek(Ci.nsISeekableStream.NS_SEEK_CUR, -2 * data.length * count);
   do_check_eq(seekable.tell(), 0);
 }
 
 function test_multiplex_bug797871() {
 
-  var data = "1234567890123456789012345678901234567890";
+  var data2 = "1234567890123456789012345678901234567890";
 
   var MultiplexStream = CC("@mozilla.org/io/multiplex-input-stream;1",
                            "nsIMultiplexInputStream");
   do_check_eq(1, 1);
 
-  var BinaryInputStream = Components.Constructor("@mozilla.org/binaryinputstream;1",
-                                                 "nsIBinaryInputStream");
-  var BinaryOutputStream = Components.Constructor("@mozilla.org/binaryoutputstream;1",
-                                                  "nsIBinaryOutputStream",
-                                                  "setOutputStream");
   var multiplex = new MultiplexStream();
   let s = Cc["@mozilla.org/io/string-input-stream;1"]
             .createInstance(Ci.nsIStringInputStream);
-  s.setData(data, data.length);
+  s.setData(data2, data2.length);
 
   multiplex.appendStream(s);
 
   var seekable = multiplex.QueryInterface(Ci.nsISeekableStream);
   var sis = Cc["@mozilla.org/scriptableinputstream;1"]
               .createInstance(Ci.nsIScriptableInputStream);
   sis.init(seekable);
 
   seekable.seek(Ci.nsISeekableStream.NS_SEEK_SET, 8);
   do_check_eq(seekable.tell(), 8);
-  readData = sis.read(2);
+  sis.read(2);
   do_check_eq(seekable.tell(), 10);
 
   seekable.seek(Ci.nsISeekableStream.NS_SEEK_SET, 20);
   do_check_eq(seekable.tell(), 20);
 }
 
 function run_test() {
   test_multiplex_streams();
--- a/xpcom/tests/unit/test_storagestream.js
+++ b/xpcom/tests/unit/test_storagestream.js
@@ -1,14 +1,16 @@
 /* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
 /* vim:set ts=2 sw=2 sts=2 et: */
 /* 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/. */
 
+/* eslint no-unused-vars: ["error", { "varsIgnorePattern": "unusedVariable" }] */
+
 var Cc = Components.classes;
 var Ci = Components.interfaces;
 var Cr = Components.results;
 
 function run_test() {
   test1();
   test2();
   test3();
@@ -19,17 +21,17 @@ function run_test() {
  * Checks that getting an input stream from a storage stream which has never had
  * anything written to it throws a not-initialized exception.
  */
 function test1() {
   var ss = Cc["@mozilla.org/storagestream;1"]
              .createInstance(Ci.nsIStorageStream);
   ss.init(1024, 1024, null);
 
-  var out = ss.getOutputStream(0);
+  var unusedVariable = ss.getOutputStream(0);
   var inp2 = ss.newInputStream(0);
   do_check_eq(inp2.available(), 0);
   do_check_true(inp2.isNonBlocking());
 
   var sis =
       Cc["@mozilla.org/scriptableinputstream;1"]
         .createInstance(Ci.nsIScriptableInputStream);
   sis.init(inp2);
@@ -54,17 +56,17 @@ function test1() {
 function test2() {
   var ss = Cc["@mozilla.org/storagestream;1"]
              .createInstance(Ci.nsIStorageStream);
   ss.init(1024, 1024, null);
 
   var out = ss.getOutputStream(0);
   out.write("", 0);
   try {
-    var inp2 = ss.newInputStream(0);
+    ss.newInputStream(0);
   } catch (e) {
     do_throw("shouldn't throw exception when new input stream created");
   }
 }
 
 /**
  * Checks that reading any non-zero amount of data from a storage stream
  * which has had 0 bytes written to it explicitly works correctly.
@@ -82,17 +84,17 @@ function test3() {
     do_throw("newInputStream(0) shouldn't throw if write() is called: " + e);
   }
 
   do_check_true(inp.isNonBlocking(), "next test expects a non-blocking stream");
 
   try {
     var threw = false;
     var bis = BIS(inp);
-    var dummy = bis.readByteArray(5);
+    bis.readByteArray(5);
   } catch (e) {
     if (e.result != Cr.NS_BASE_STREAM_WOULD_BLOCK)
       do_throw("wrong error thrown: " + e);
     threw = true;
   }
   do_check_true(threw,
                 "should have thrown (nsStorageInputStream is nonblocking)");
 }