Bug 1425244 - Enable ESLint rule no-lonely-if for accessible/tests/mochitest/. r?surkov draft
authorMark Banner <standard8@mozilla.com>
Mon, 11 Dec 2017 13:42:17 +0000
changeset 711861 4282e5f1038f07390b0adff9e7451220512eaa39
parent 711860 326c098b0054fa2e12d536945268f8175da3b95a
child 711862 4f59fb2daf90838d6e0a8d2d2b02ce36b14f3f17
push id93179
push userbmo:standard8@mozilla.com
push dateThu, 14 Dec 2017 22:08:47 +0000
reviewerssurkov
bugs1425244
milestone59.0a1
Bug 1425244 - Enable ESLint rule no-lonely-if for accessible/tests/mochitest/. r?surkov MozReview-Commit-ID: DILOcLjsaoF
accessible/tests/mochitest/.eslintrc.js
accessible/tests/mochitest/events.js
accessible/tests/mochitest/events/test_focus_general.html
accessible/tests/mochitest/jsat/jsatcommon.js
--- a/accessible/tests/mochitest/.eslintrc.js
+++ b/accessible/tests/mochitest/.eslintrc.js
@@ -6,17 +6,16 @@ module.exports = {
   ],
   "rules": {
     "mozilla/no-cpows-in-tests": "error",
     "mozilla/reject-importGlobalProperties": "error",
 
     // XXX These are rules that are enabled in the recommended configuration, but
     // disabled here due to failures when initially implemented. They should be
     // removed (and hence enabled) at some stage.
-    "no-lonely-if": "off",
     "no-nested-ternary": "off",
     "no-new-object": "off",
     "no-redeclare": "off",
     "no-shadow": "off",
     "no-undef": "off",
     "space-unary-ops": "off",
   }
 };
--- a/accessible/tests/mochitest/events.js
+++ b/accessible/tests/mochitest/events.js
@@ -331,22 +331,20 @@ function eventQueue(aEventType) {
                 var checker = eventSeq[idx];
 
                 var typeStr = eventQueue.getEventTypeAsString(checker);
                 var msg = "Test with ID = '" + this.getEventID(checker) +
                   "' succeed. ";
 
                 if (checker.unexpected) {
                   ok(true, msg + `There's no unexpected '${typeStr}' event.`);
+                } else if (checker.todo) {
+                  todo(false, `Todo event '${typeStr}' was caught`);
                 } else {
-                  if (checker.todo) {
-                    todo(false, `Todo event '${typeStr}' was caught`);
-                  } else {
-                    ok(true, `${msg} Event '${typeStr}' was handled.`);
-                  }
+                  ok(true, `${msg} Event '${typeStr}' was handled.`);
                 }
               }
             }
           }
         }
 
         // We don't have completely matched scenario. Report each failure/success
         // for every scenario.
@@ -1996,16 +1994,17 @@ var gA11yEventObserver =
 function listenA11yEvents(aStartToListen) {
   if (aStartToListen) {
     // Add observer when adding the first applicant only.
     if (!(gA11yEventApplicantsCount++))
       Services.obs.addObserver(gA11yEventObserver, "accessible-event");
   } else {
     // Remove observer when there are no more applicants only.
     // '< 0' case should not happen, but just in case: removeObserver() will throw.
+    // eslint-disable-next-line no-lonely-if
     if (--gA11yEventApplicantsCount <= 0)
       Services.obs.removeObserver(gA11yEventObserver, "accessible-event");
   }
 }
 
 function addA11yEventListener(aEventType, aEventHandler) {
   if (!(aEventType in gA11yEventListeners))
     gA11yEventListeners[aEventType] = [];
--- a/accessible/tests/mochitest/events/test_focus_general.html
+++ b/accessible/tests/mochitest/events/test_focus_general.html
@@ -101,20 +101,19 @@
         gQueue.push(new toggleTopMenu(editableDoc, new topMenuChecker()));
         gQueue.push(new toggleTopMenu(editableDoc, new focusChecker(editableDoc)));
       }
       gQueue.push(new synthContextMenu(editableDoc, new contextMenuChecker()));
       gQueue.push(new synthDownKey(editableDoc, new focusContextMenuItemChecker()));
       gQueue.push(new synthEscapeKey(editableDoc, new focusChecker(editableDoc)));
       if (SEAMONKEY) {
         todo(false, "shift tab from editable document fails on (Windows) SeaMonkey! (Bug 718235)");
+      } else if (LINUX || MAC) {
+        todo(false, "shift tab from editable document fails on linux and Mac, bug 746519!");
       } else {
-      if (LINUX || MAC)
-        todo(false, "shift tab from editable document fails on linux and Mac, bug 746519!");
-      else
         gQueue.push(new synthShiftTab("link", new focusChecker("link")));
       } // ! SEAMONKEY
 
       gQueue.push(new synthFocus("a", new imageMapChecker("a")));
       gQueue.push(new synthFocus("b", new imageMapChecker("b")));
 
       gQueue.invoke(); // Will call SimpleTest.finish();
     }
--- a/accessible/tests/mochitest/jsat/jsatcommon.js
+++ b/accessible/tests/mochitest/jsat/jsatcommon.js
@@ -495,23 +495,21 @@ ExpectedMessage.prototype.lazyCompare = 
     var expected = aExpected[attr];
     var received = aReceived[attr];
     if (typeof expected === "object") {
       var [childMatches, childDelta] = this.lazyCompare(received, expected);
       if (!childMatches) {
         delta.push(attr + " [ " + childDelta + " ]");
         matches = false;
       }
-    } else {
-      if (received !== expected) {
-        delta.push(
-          attr + " [ expected " + JSON.stringify(expected) +
-          " got " + JSON.stringify(received) + " ]");
-        matches = false;
-      }
+    } else if (received !== expected) {
+      delta.push(
+        attr + " [ expected " + JSON.stringify(expected) +
+        " got " + JSON.stringify(received) + " ]");
+      matches = false;
     }
   }
 
   var msg = delta.length ? delta.join(" ") : "Structures lazily match";
   return [matches, msg + " -- " + aInfo];
 };
 
 ExpectedMessage.prototype.is = function(aReceived, aInfo) {