Bug 1328805 - Enable the no-cond-assign rule for eslint and fix the six resulting errors mostly by wrapping the assignment with parentheses to explicitly state that the assignment is intentional with exception for advanced.js where assignment was not intended. r?mossop draft
authorJared Wein <jwein@mozilla.com>
Thu, 05 Jan 2017 01:03:08 -0500
changeset 456219 e0a4e5e782a4
parent 456218 1212f952dce1
child 541165 69d5f066eeb5
push id40431
push userbmo:jaws@mozilla.com
push dateThu, 05 Jan 2017 06:03:38 +0000
reviewersmossop
bugs1328805
milestone53.0a1
Bug 1328805 - Enable the no-cond-assign rule for eslint and fix the six resulting errors mostly by wrapping the assignment with parentheses to explicitly state that the assignment is intentional with exception for advanced.js where assignment was not intended. r?mossop MozReview-Commit-ID: EZytfzGoMLR
browser/components/preferences/in-content/advanced.js
toolkit/.eslintrc.js
toolkit/components/aboutperformance/content/aboutPerformance.js
toolkit/components/contentprefs/tests/unit_cps2/head.js
toolkit/components/places/ClusterLib.js
toolkit/content/aboutSupport.js
toolkit/mozapps/extensions/test/xpcshell/test_plugins.js
--- a/browser/components/preferences/in-content/advanced.js
+++ b/browser/components/preferences/in-content/advanced.js
@@ -223,17 +223,17 @@ var gAdvancedPane = {
     return checkbox.checked ? 1 : 0;
   },
 
   /**
    * When the user toggles the layers.acceleration.disabled pref,
    * sync its new value to the gfx.direct2d.disabled pref too.
    */
   updateHardwareAcceleration() {
-    if (AppConstants.platform = "win") {
+    if (AppConstants.platform == "win") {
       var fromPref = document.getElementById("layers.acceleration.disabled");
       var toPref = document.getElementById("gfx.direct2d.disabled");
       toPref.value = fromPref.value;
     }
   },
 
   // DATA CHOICES TAB
 
--- a/toolkit/.eslintrc.js
+++ b/toolkit/.eslintrc.js
@@ -55,16 +55,19 @@ module.exports = {
     "linebreak-style": ["error", "unix"],
 
     // Always require parenthesis for new calls
     // "new-parens": "error",
 
     // Use [] instead of Array()
     // "no-array-constructor": "error",
 
+    // Disallow assignment operators in conditional statements
+    "no-cond-assign": "error",
+
     // Disallow the use of debugger
     "no-debugger": "error",
 
     // Disallow deleting variables
     "no-delete-var": "error",
 
     // No duplicate arguments in function declarations
     "no-dupe-args": "error",
--- a/toolkit/components/aboutperformance/content/aboutPerformance.js
+++ b/toolkit/components/aboutperformance/content/aboutPerformance.js
@@ -1011,17 +1011,17 @@ var SubprocessMonitor = {
           SubprocessMonitor.queueUpdate();
           return;
         }
         let resultTable = document.getElementById("subprocess-reports");
         let recycle = [];
         // We first iterate the table to check if summaries exist for rowPids,
         // if yes, update them and delete the pid's summary or else hide the row
         // for recycling it. Start at row 1 instead of 0 (to skip the header row).
-        for (let i = 1, row; row = resultTable.rows[i]; i++) {
+        for (let i = 1, row; (row = resultTable.rows[i]); i++) {
           let rowPid = row.dataset.pid;
           let summary = summaries[rowPid];
           if (summary) {
             // Now we update the values in the row, which is hardcoded for now,
             // but we might want to make this more adaptable in the future.
             SubprocessMonitor.updateRow(row, summaries, rowPid);
             delete summaries[rowPid];
           } else {
--- a/toolkit/components/contentprefs/tests/unit_cps2/head.js
+++ b/toolkit/components/contentprefs/tests/unit_cps2/head.js
@@ -336,17 +336,17 @@ function dbOK(expectedRows) {
 
   db.executeAsync([stmt], 1, {
     handleCompletion(reason) {
       arraysOfArraysOK(actualRows, expectedRows);
       next();
     },
     handleResult(results) {
       let row = null;
-      while (row = results.getNextRow()) {
+      while ((row = results.getNextRow())) {
         actualRows.push(cols.map(c => row.getResultByName(c)));
       }
     },
     handleError(err) {
       do_throw(err);
     }
   });
   stmt.finalize();
--- a/toolkit/components/places/ClusterLib.js
+++ b/toolkit/components/places/ClusterLib.js
@@ -79,18 +79,17 @@ HierarchicalClustering.prototype = {
 
         if (dist < distances[i][neighbors[i]]) {
           neighbors[i] = j;
         }
       }
     }
 
     // merge the next two closest clusters until none of them are close enough
-    let next = null, i = 0;
-    for (; next = this.closestClusters(clusters, distances, neighbors); i++) {
+    for (let next = null, i = 0; (next = this.closestClusters(clusters, distances, neighbors)); i++) {
       if (snapshotCallback && (i % snapshotGap) == 0) {
         snapshotCallback(clusters);
       }
       this.mergeClusters(clusters, distances, neighbors, clustersByKey,
                          clustersByKey[next[0]], clustersByKey[next[1]]);
     }
     return clusters;
   },
--- a/toolkit/content/aboutSupport.js
+++ b/toolkit/content/aboutSupport.js
@@ -452,18 +452,18 @@ var snapshotFormatters = {
         let trs = [];
         for (let entry of feature.log) {
           if (entry.type == "default" && entry.status == "available")
             continue;
 
           let contents;
           if (entry.message.length > 0 && entry.message[0] == "#") {
             // This is a failure ID. See nsIGfxInfo.idl.
-            let m;
-            if (m = /#BLOCKLIST_FEATURE_FAILURE_BUG_(\d+)/.exec(entry.message)) {
+            let m = /#BLOCKLIST_FEATURE_FAILURE_BUG_(\d+)/.exec(entry.message);
+            if (m) {
               let bugSpan = $.new("span");
               bugSpan.textContent = strings.GetStringFromName("blocklistedBug") + "; ";
 
               let bugHref = $.new("a");
               bugHref.href = "https://bugzilla.mozilla.org/show_bug.cgi?id=" + m[1];
               bugHref.textContent = strings.formatStringFromName("bugLink", [m[1]], 1);
 
               contents = [bugSpan, bugHref];
--- a/toolkit/mozapps/extensions/test/xpcshell/test_plugins.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_plugins.js
@@ -67,17 +67,17 @@ function get_test_plugin() {
 
 function getFileSize(aFile) {
   if (!aFile.isDirectory())
     return aFile.fileSize;
 
   let size = 0;
   let entries = aFile.directoryEntries.QueryInterface(AM_Ci.nsIDirectoryEnumerator);
   let entry;
-  while (entry = entries.nextFile)
+  while ((entry = entries.nextFile))
     size += getFileSize(entry);
   entries.close();
   return size;
 }
 
 function getPluginLastModifiedTime(aPluginFile) {
   // On OS X we use the bundle contents last modified time as using
   // the package directories modified date may be outdated.