Bug 1501931 - Enable ESLint for parser/ (manual fixes) r=Standard8,mrbkap
authorreimu <r2hkri@gmail.com>
Thu, 06 Dec 2018 20:30:32 +0000
changeset 449548 7c02d6c28133994b30e2dd8ee3ae43e3d0cbd23f
parent 449547 f456b3dd43c03e83efad3b4d4af480f720e764f5
child 449549 8a74a0cfd788e50d2bff25844644c970d1cb5437
push id35171
push userrmaries@mozilla.com
push dateFri, 07 Dec 2018 09:27:28 +0000
treeherdermozilla-central@6725a7f43bae [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersStandard8, mrbkap
bugs1501931
milestone65.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1501931 - Enable ESLint for parser/ (manual fixes) r=Standard8,mrbkap Depends on D11920 Differential Revision: https://phabricator.services.mozilla.com/D11921
.eslintignore
parser/htmlparser/tests/mochitest/file_bug688580.js
parser/htmlparser/tests/mochitest/file_defer_bug1104732.js
parser/htmlparser/tests/mochitest/file_img_picture_preload.html
parser/htmlparser/tests/mochitest/parser_datreader.js
parser/htmlparser/tests/mochitest/parser_web_testrunner.js
parser/htmlparser/tests/mochitest/test_bug339350.xhtml
parser/htmlparser/tests/mochitest/test_bug396568.html
parser/htmlparser/tests/mochitest/test_bug460437.xhtml
parser/htmlparser/tests/mochitest/test_bug566879.html
parser/htmlparser/tests/mochitest/test_bug715739.html
parser/htmlparser/tests/mochitest/test_compatmode.html
parser/xml/test/unit/test_parser.js
parser/xml/test/unit/test_sanitizer.js
--- a/.eslintignore
+++ b/.eslintignore
@@ -26,17 +26,16 @@ gfx/tests/chrome/**
 gfx/tests/mochitest/**
 image/**
 layout/**
 modules/**
 netwerk/cookie/test/browser/**
 netwerk/test/browser/**
 netwerk/test/mochitests/**
 netwerk/test/unit*/**
-parser/**
 tools/update-packaging/**
 uriloader/exthandler/**
 uriloader/exthandler/tests/mochitest/**
 widget/headless/tests/**
 widget/tests/**
 
 # We currently have no js files in these directories, so we ignore them by
 # default to aid ESLint's performance.
--- a/parser/htmlparser/tests/mochitest/file_bug688580.js
+++ b/parser/htmlparser/tests/mochitest/file_bug688580.js
@@ -1,4 +1,5 @@
+/* globals state:true */
 is(document.readyState, "interactive", "readyState should be interactive during defer.");
 is(state, "readyState interactive", "Bad state upon defer");
 state = "defer";
 
--- a/parser/htmlparser/tests/mochitest/file_defer_bug1104732.js
+++ b/parser/htmlparser/tests/mochitest/file_defer_bug1104732.js
@@ -1,3 +1,4 @@
+/* globals state:true */
 is(document.readyState, "interactive", "readyState should be interactive during defer.");
 state = "defer";
 
--- a/parser/htmlparser/tests/mochitest/file_img_picture_preload.html
+++ b/parser/htmlparser/tests/mochitest/file_img_picture_preload.html
@@ -38,17 +38,17 @@
     // the preloader)
     var preloadedImages = [];
     while (preloadedImages.length < EXPECTED_PRELOADS) {
       var request = new XMLHttpRequest();
       request.open("GET", "./file_img_picture_preload.sjs?status", false);
       request.send(null);
       is(request.status, 200, "Getting status from sjs helper should succeed");
       if (request.status === 200) {
-        var preloadedImages = JSON.parse(request.responseText);
+        preloadedImages = JSON.parse(request.responseText);
       }
     }
 
     // Ensure the DOM is still blocked on us before proceeding
     is(document.querySelector("img"), null, "No <img> elements should exist yet");
   </script>
 
   <!-- All images below will be checked, use sources of the format
@@ -141,17 +141,17 @@
         preloadByName[split[0]] = split[1];
       }
 
       // Check all images, ensure each one had a preload
       var images = document.querySelectorAll("img");
       for (var img of images) {
         var imgName = img.id;
         if (img.currentSrc) {
-          var split = img.currentSrc.split("?")[1].split(":");
+          split = img.currentSrc.split("?")[1].split(":");
           is(split[0], imgName,
              "image " + imgName + " source matches element id");
           is(split[1], preloadByName[imgName],
              "image " + imgName + " source should match preloaded source");
           // Remove from array
           delete preloadByName[imgName];
         } else {
           // img loaded nothing
--- a/parser/htmlparser/tests/mochitest/parser_datreader.js
+++ b/parser/htmlparser/tests/mochitest/parser_datreader.js
@@ -31,32 +31,32 @@ function trimString(s) {
  * of error messages.
  *
  * @param A string containing a single testcase
  */
 function parseTestcase(testcase) {
   var lines = testcase.split("\n");
 
   /* check that the first non-empty, non-comment line is #data */
-  for (var line of lines) {
+  for (let line of lines) {
     if (!line || startsWith(line, "##")) {
       continue;
     }
     if (line == "#data")
       break;
     log(lines);
     throw "Unknown test format.";
   }
 
   var input = [];
   var output = [];
   var errors = [];
   var fragment = [];
   var currentList = input;
-  for (var line of lines) {
+  for (let line of lines) {
     if (startsWith(line, "##todo")) {
       todo(false, line.substring(6));
       continue;
     }
     if (!(startsWith(line, "#error") ||
           startsWith(line, "#document") ||
           startsWith(line, "#document-fragment") ||
           startsWith(line, "#data"))) {
@@ -141,17 +141,17 @@ function addLevels(walker, buf, indent) 
             buf += "svg ";
           } else if ("http://www.w3.org/1999/xhtml" != ns) {
             buf += "otherns ";
           }
           buf += walker.currentNode.localName + ">";
           if (walker.currentNode.hasAttributes()) {
             var valuesByName = {};
             var attrs = walker.currentNode.attributes;
-            for (var i = 0; i < attrs.length; ++i) {
+            for (let i = 0; i < attrs.length; ++i) {
               var localName = attrs[i].localName;
               var name;
               var attrNs = attrs[i].namespaceURI;
               if (null == attrNs) {
                 name = localName;
               } else if ("http://www.w3.org/XML/1998/namespace" == attrNs) {
                 name = "xml " + localName;
               } else if ("http://www.w3.org/1999/xlink" == attrNs) {
@@ -159,17 +159,17 @@ function addLevels(walker, buf, indent) 
               } else if ("http://www.w3.org/2000/xmlns/" == attrNs) {
                 name = "xmlns " + localName;
               } else {
                 name = "otherns " + localName;
               }
               valuesByName[name] = attrs[i].value;
             }
             var keys = Object.keys(valuesByName).sort();
-            for (var i = 0; i < keys.length; ++i) {
+            for (let i = 0; i < keys.length; ++i) {
               buf += "\n" + indent + "  " + keys[i] +
                      "=\"" + valuesByName[keys[i]] + "\"";
             }
           }
           break;
         case Node.DOCUMENT_TYPE_NODE:
           buf += "<!DOCTYPE " + walker.currentNode.name;
           if (walker.currentNode.publicId || walker.currentNode.systemId) {
--- a/parser/htmlparser/tests/mochitest/parser_web_testrunner.js
+++ b/parser/htmlparser/tests/mochitest/parser_web_testrunner.js
@@ -10,16 +10,20 @@
  * and it will load each of those dat files into an array, then run
  * the test parser on each and run the tests by assigning the input
  * data to an iframe's url.
  *
  * Your test document should have an element with id "display" and
  * an iframe with id "testframe".
  */
 
+/* import-globals-from ./parser_datreader.js */
+/* import-globals-from ./html5_tree_construction_exceptions.js */
+/* globals parserDatFiles */
+
 var functionsToRunAsync = [];
 
 window.addEventListener("message", function(event) {
   if (event.source == window && event.data == "async-run") {
     event.stopPropagation();
     var fn = functionsToRunAsync.shift();
     fn();
   }
@@ -82,29 +86,29 @@ function makeFragmentTestChecker(input,
                                          fragment.substring(4));
     } else if (fragment.startsWith("math ")) {
       context = document.createElementNS("http://www.w3.org/1998/Math/MathML",
                                          fragment.substring(5));
     } else {
       context = document.createElementNS("http://www.w3.org/1999/xhtml",
                                          fragment);
     }
+    // eslint-disable-next-line no-unsanitized/property
     context.innerHTML = input;
     var domAsString = fragmentToTestOutput(context);
     is(domAsString, expected, "HTML5 expected success. " + new Date());
     if (domAsString != expected) {
       writeErrorSummary(input, expected, domAsString, false);
     }
     nextTest(testframe);
   };
 }
 
 var testcases;
 function nextTest(testframe) {
-  var test = 0;
   var {done, value} = testcases.next();
   if (done) {
     SimpleTest.finish();
     return;
   }
   var [input, output, errors, fragment] = value;
   if (fragment) {
     asyncRun(makeFragmentTestChecker(input,
--- a/parser/htmlparser/tests/mochitest/test_bug339350.xhtml
+++ b/parser/htmlparser/tests/mochitest/test_bug339350.xhtml
@@ -32,29 +32,30 @@ https://bugzilla.mozilla.org/show_bug.cg
   <td><div id="t1"/></td>
   <td><div id="t2"/></td>
   <td><div id="t3"/></td>
   </tr>
   </table>
 </div>
 <pre id="test">
 <script type="text/javascript">
-var text1 = 'foo bar';
-var text2 = 'foo [bar]';
-var text3 = 'foo {bar}';
+/* eslint-disable no-unsanitized/property */
+var text1 = "foo bar";
+var text2 = "foo [bar]";
+var text3 = "foo {bar}";
 
-<!-- This is the long way to write this stuff, 
-     you can use MochiKit functions too -->
-document.getElementById('i1').innerHTML = text1;
-document.getElementById('i2').innerHTML = text2;
-document.getElementById('i3').innerHTML = text3;
+// This is the long way to write this stuff,
+// you can use MochiKit functions too
+document.getElementById("i1").innerHTML = text1;
+document.getElementById("i2").innerHTML = text2;
+document.getElementById("i3").innerHTML = text3;
 
-document.getElementById('t1').appendChild(document.createTextNode(text1));
-document.getElementById('t2').appendChild(document.createTextNode(text2));
-document.getElementById('t3').appendChild(document.createTextNode(text3));
+document.getElementById("t1").appendChild(document.createTextNode(text1));
+document.getElementById("t2").appendChild(document.createTextNode(text2));
+document.getElementById("t3").appendChild(document.createTextNode(text3));
 
 <!-- The is() function is one way to add a test -->
-is(document.getElementById('i2').innerHTML, text2, "XHTML innerHTML with trailing brackets ']]'");
+is(document.getElementById("i2").innerHTML, text2, "XHTML innerHTML with trailing brackets ']]'");
 
 </script>
 </pre>
 </body>
 </html>
--- a/parser/htmlparser/tests/mochitest/test_bug396568.html
+++ b/parser/htmlparser/tests/mochitest/test_bug396568.html
@@ -28,20 +28,21 @@ https://bugzilla.mozilla.org/show_bug.cg
 </div>
 <pre id="test">
 <script class="testbody" type="text/javascript">
 
 /** Test for Bug 396568 **/
 
  var reached = false;
  try {
+   // eslint-disable-next-line no-undef
    noSuchIdentifier;
    reached = true;
  } catch (e) {
-   is(e.lineNumber, 36, "Unexpected line number"); // this line number is dependent on the line number of noSuchIdentifier
+   is(e.lineNumber, 37, "Unexpected line number"); // this line number is dependent on the line number of noSuchIdentifier
  }
  is(reached, false, "Exception needed to be thrown");
 
 </script>
 </pre>
 </body>
 </html>
 
--- a/parser/htmlparser/tests/mochitest/test_bug460437.xhtml
+++ b/parser/htmlparser/tests/mochitest/test_bug460437.xhtml
@@ -10,16 +10,17 @@ https://bugzilla.mozilla.org/show_bug.cg
 <body>
 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=460437">Mozilla Bug 460437</a>
 <p id="display"><b id="test460437">orig</b></p>
 <div id="content" style="display: none">
   
 </div>
 <pre id="test">
 <script type="application/javascript">
+/* eslint-disable no-unsanitized/property */
 <![CDATA[
 
 SimpleTest.expectAssertions(1);
 
 /** Test for Bug 460437 **/
 
 var s = "<i>invalid</i";
 try {
--- a/parser/htmlparser/tests/mochitest/test_bug566879.html
+++ b/parser/htmlparser/tests/mochitest/test_bug566879.html
@@ -23,27 +23,30 @@ https://bugzilla.mozilla.org/show_bug.cg
 <select name=select id=select>
 <option value=foo>Foo</option>
 <option value=bar selected>Bar</option>
 </select>
 </form>  
 </div>
 <pre id="test">
 <script class="testbody" type="text/javascript">
+var initialState;
+
 function runTest() {
   initialState = document.getElementById("content").innerHTML;
   document.getElementById("textfield").value = "foo";
   document.getElementById("checkbox").checked = true;
   document.getElementById("radio2").checked = true;
   document.getElementById("textarea").value = "foo";
   document.getElementById("select").value = "foo";
   setTimeout(continuation1, 1);
 }
 
 function continuation1() {
+  // eslint-disable-next-line no-unsanitized/property
   document.getElementById("content").innerHTML = initialState;
   setTimeout(continuation2, 1);
 }
 
 function continuation2() {
   is(document.getElementById("textfield").value, "", "The text field should have gone back to its initial state.");
   ok(!document.getElementById("checkbox").checked, "The checkbox should have gone back to its initial state.");
   ok(!document.getElementById("radio2").checked, "The second radio button should have gone back to its initial state.");
--- a/parser/htmlparser/tests/mochitest/test_bug715739.html
+++ b/parser/htmlparser/tests/mochitest/test_bug715739.html
@@ -32,36 +32,37 @@ function textChildren(node) {
   }
   return s;
 }
 
 function tick() {
   runNumber++;
   var f = document.getElementsByTagName("iframe")[0];
   var d = f.contentDocument;
+  var text;
 
   if (runNumber == 1) {
     d.open();
     f.addEventListener("load", tick);
     d.write("X");
     d.write("\u003cscript>document.write('Y');\u003c/script>");
     d.write("Z");
     d.close();
     return;
   }
 
   if (runNumber == 2) {
-    var text = textChildren(d.body);
+    text = textChildren(d.body);
     is(text, "XYZ", "Wrong text before reload.");
     f.contentWindow.location.reload();
     return;
   }
 
   if (runNumber == 3) {
-    var text = textChildren(d.body);
+    text = textChildren(d.body);
     is(text, "XYZ", "Wrong text after reload.");
     SimpleTest.finish();
 
   }
 }
 
 </script>
 </pre>
--- a/parser/htmlparser/tests/mochitest/test_compatmode.html
+++ b/parser/htmlparser/tests/mochitest/test_compatmode.html
@@ -78,17 +78,17 @@ function insert_iframe(index, doctype) {
   elm.setAttribute("style", "display:none");
   document.getElementsByTagName("body")[0].appendChild(elm);
 }
 
 // //
 // Iterate over the tests
 //
 function doTest() {
-  for (i = 0; i < doctypes.length; i += 2) {
+  for (var i = 0; i < doctypes.length; i += 2) {
     insert_iframe(i, doctypes[i + 1]);
   }
 }
 
 // //
 // Run the compatbility mode tests.
 //
 SimpleTest.waitForExplicitFinish();
--- a/parser/xml/test/unit/test_parser.js
+++ b/parser/xml/test/unit/test_parser.js
@@ -24,20 +24,18 @@ function updateDocumentSourceMaps(src) {
     startDocument: function startDocument() {
     },
 
     endDocument: function endDocument() {
     },
 
     handleAttributes: function handleAttributes(aAttributes) {
       for (var i = 0; i < aAttributes.length; i++) {
-        var attrNamespaceURI = aAttributes.getURI(i);
         var attrLocalName = aAttributes.getLocalName(i);
         var attrNodeName = aAttributes.getQName(i);
-        var value = aAttributes.getValue(i);
         do_parse_check(attrLocalName, "Missing attribute local name");
         do_parse_check(attrNodeName, "Missing attribute node name");
       }
     },
 
     startElement: function startElement(aNamespaceURI, aLocalName, aNodeName, aAttributes) {
       do_parse_check(aLocalName, "Missing element local name (startElement)");
       do_parse_check(aNodeName, "Missing element node name (startElement)");
--- a/parser/xml/test/unit/test_sanitizer.js
+++ b/parser/xml/test/unit/test_sanitizer.js
@@ -1,11 +1,12 @@
 function run_test() {
   // vectors by the html5security project (https://code.google.com/p/html5security/ & Creative Commons 3.0 BY), see CC-BY-LICENSE for the full license
   load("results.js"); // gives us a `vectors' array
+  /* import-globals-from ./results.js */
 
   var ParserUtils =  Cc["@mozilla.org/parserutils;1"].getService(Ci.nsIParserUtils);
   var sanitizeFlags = ParserUtils.SanitizerCidEmbedsOnly | ParserUtils.SanitizerDropForms | ParserUtils.SanitizerDropNonCSSPresentation;
   // flags according to
   // http://mxr.mozilla.org/comm-central/source/mailnews/mime/src/mimemoz2.cpp#2218
   // and default settings