Bug 1439142 - Fix eslint errors for complexity and no-compare-against-boolean-literals in calendar. r=philipp
authorMakeMyDay <makemyday@gmx-topmail.de>
Sat, 17 Feb 2018 23:09:02 +0100
changeset 31138 51c1c477a92610012d7dfadc66a4065f9e994150
parent 31137 4644f1f698d895f4f0fdc3db53e891f5479f9868
child 31139 d491a134fae3d7c8629a4d70a4f3d583ddaa7e72
push id383
push userclokep@gmail.com
push dateMon, 07 May 2018 21:52:48 +0000
reviewersphilipp
bugs1439142
Bug 1439142 - Fix eslint errors for complexity and no-compare-against-boolean-literals in calendar. r=philipp
calendar/.eslintrc.js
calendar/base/content/calendar-common-sets.js
calendar/base/content/calendar-management.js
calendar/base/content/calendar-task-view.js
calendar/base/content/widgets/calendar-widgets.xml
calendar/base/content/widgets/minimonth.xml
calendar/base/modules/calExtract.jsm
calendar/lightning/content/lightning-item-iframe.js
calendar/test/mozmill/shared-modules/test-calendar-utils.js
calendar/test/mozmill/shared-modules/test-timezone-utils.js
--- a/calendar/.eslintrc.js
+++ b/calendar/.eslintrc.js
@@ -21,17 +21,17 @@ module.exports = {
 
         // Enforce spacing before and after comma
         "comma-spacing": [2, { before: false, after: true }],
 
         // Enforce one true comma style.
         "comma-style": [2, "last"],
 
         // We should get better at complexity, but at the moment it is what it is
-        "complexity": [2, 81],
+        "complexity": [2, 90],
 
         // Enforce curly brace conventions for all control statements.
         "curly": 2,
 
         // Enforce the spacing around the * in generator functions.
         "generator-star-spacing": [2, "after"],
 
         // Require space before/after arrow function's arrow
--- a/calendar/base/content/calendar-common-sets.js
+++ b/calendar/base/content/calendar-common-sets.js
@@ -278,18 +278,17 @@ var calendarController = {
                                       cal.dtz.getDefaultStartDate(currentView().selectedDay));
                 break;
             case "calendar_new_event_context_command": {
                 let newStart = currentView().selectedDateTime;
                 if (!newStart) {
                     newStart = cal.dtz.getDefaultStartDate(currentView().selectedDay);
                 }
                 createEventWithDialog(getSelectedCalendar(), newStart,
-                                      null, null, null,
-                                      newStart.isDate == true);
+                                      null, null, null, newStart.isDate);
                 break;
             }
             case "calendar_modify_event_command":
                 editSelectedEvents();
                 break;
             case "calendar_modify_focused_item_command": {
                 let focusedElement = document.commandDispatcher.focusedElement;
                 if (!focusedElement && this.defaultController && !this.isCalendarInForeground()) {
--- a/calendar/base/content/calendar-management.js
+++ b/calendar/base/content/calendar-management.js
@@ -174,17 +174,17 @@ function calendarListTooltipShowing(even
         let currentStatus = calendar.getProperty("currentStatus");
         if (!Components.isSuccessCode(currentStatus)) {
             tooltipText = cal.calGetString("calendar", "tooltipCalendarDisabled", [calendar.name]);
         } else if (calendar.readOnly) {
             tooltipText = cal.calGetString("calendar", "tooltipCalendarReadOnly", [calendar.name]);
         }
     }
     setElementValue("calendar-list-tooltip", tooltipText, "label");
-    return (tooltipText != false);
+    return (tooltipText !== false);
 }
 
 /**
  * A handler called to set up the context menu on the calendar list.
  *
  * @param event         The DOM event that caused the context menu to open.
  * @return              Returns true if the context menu should be shown.
  */
--- a/calendar/base/content/calendar-task-view.js
+++ b/calendar/base/content/calendar-task-view.js
@@ -48,17 +48,17 @@ var taskDetailsView = {
                     }
                 }
                 if (displayElement("calendar-task-details-organizer-row", name && name.length)) {
                     document.getElementById("calendar-task-details-organizer").value = name;
                 }
             }
 
             let priority = 0;
-            if (item.calendar.getProperty("capabilities.priority.supported") != false) {
+            if (item.calendar.getProperty("capabilities.priority.supported")) {
                 priority = parseInt(item.priority, 10);
             }
             displayElement("calendar-task-details-priority-label", priority > 0);
             displayElement("calendar-task-details-priority-low", priority >= 6 && priority <= 9);
             displayElement("calendar-task-details-priority-normal", priority == 5);
             displayElement("calendar-task-details-priority-high", priority >= 1 && priority <= 4);
 
             let status = item.getProperty("STATUS");
--- a/calendar/base/content/widgets/calendar-widgets.xml
+++ b/calendar/base/content/widgets/calendar-widgets.xml
@@ -406,17 +406,17 @@
             let modeIndex = -1;
             let display = aVisible;
             let collapsedInMode = false;
             if (this.hasAttribute("collapsedinmodes")) {
                 collapsedModes = this.getAttribute("collapsedinmodes").split(",");
                 modeIndex = collapsedModes.indexOf(this.currentMode);
                 collapsedInMode = modeIndex > -1;
             }
-            if (aVisible === true && pushModeCollapsedAttribute == false) {
+            if (aVisible === true && !pushModeCollapsedAttribute) {
                 display = (aVisible === true) && (!collapsedInMode);
             }
 
             setBooleanAttribute(this, "collapsed", !display || !this.isVisibleInMode());
             if (pushModeCollapsedAttribute) {
                 if (!display) {
                     if (modeIndex == -1) {
                         collapsedModes.push(this.currentMode);
--- a/calendar/base/content/widgets/minimonth.xml
+++ b/calendar/base/content/widgets/minimonth.xml
@@ -461,17 +461,17 @@
           // Add pref observer
           let branch = Services.prefs.getBranch("");
           branch.addObserver("calendar.", this);
       ]]></constructor>
 
       <destructor><![CDATA[
           ChromeUtils.import("resource://gre/modules/Services.jsm");
 
-          if (this.mObservesComposite == true) {
+          if (this.mObservesComposite) {
               cal.view.getCompositeCalendar(window).removeObserver(this);
           }
 
           // Remove pref observer
           let branch = Services.prefs.getBranch("");
           branch.removeObserver("calendar.", this);
       ]]></destructor>
 
@@ -1018,23 +1018,23 @@
                 }
             }
         ]]></body>
       </method>
 
       <method name="_setFreeBusy">
         <parameter name="aFreeBusy"/>
         <body><![CDATA[
-            if (aFreeBusy == true) {
-                if (this.mObservesComposite == false) {
+            if (aFreeBusy) {
+                if (!this.mObservesComposite) {
                     cal.view.getCompositeCalendar(window).addObserver(this);
                     this.mObservesComposite = true;
                     this.getItems();
                 }
-            } else if (this.mObservesComposite == true) {
+            } else if (this.mObservesComposite) {
                 cal.view.getCompositeCalendar(window).removeObserver(this);
                 this.mObservesComposite = false;
             }
         ]]></body>
       </method>
 
       <method name="removeAttribute">
         <parameter name="aAttr"/>
--- a/calendar/base/modules/calExtract.jsm
+++ b/calendar/base/modules/calExtract.jsm
@@ -110,17 +110,17 @@ Extractor.prototype = {
         let nonAscii = sum / cnt || 0;
         cal.LOG("[calExtract] Average non-ascii charcode: " + nonAscii);
         return nonAscii;
     },
 
     setLanguage: function() {
         let path;
 
-        if (this.fixedLang == true) {
+        if (this.fixedLang) {
             if (this.checkBundle(this.fallbackLocale)) {
                 cal.LOG("[calExtract] Fixed locale was used to choose " +
                         this.fallbackLocale + " patterns.");
             } else {
                 cal.LOG("[calExtract] " + this.fallbackLocale +
                         " patterns were not found. Using en-US instead");
                 this.fallbackLocale = "en-US";
             }
@@ -843,69 +843,69 @@ Extractor.prototype = {
 
         cal.LOG("[calExtract] Start picked: " + JSON.stringify(guess));
         return guess;
     },
 
     /**
     * Guesses end time from list of guessed datetimes relative to start time
     *
-    * @param start     start time to consider when guessing
-    * @param isTask    whether start time should be guessed for task or event
-    * @return          datetime object for end time
+    * @param start         start time to consider when guessing
+    * @param doGuessStart  whether start time should be guessed for task or event
+    * @return              datetime object for end time
     */
-    guessEnd: function(start, isTask) {
+    guessEnd: function(start, doGuessStart) {
         let guess = {};
         let endTimes = this.collected.filter(val => val.relation == "end");
         let durations = this.collected.filter(val => val.relation == "duration");
         if (endTimes.length == 0 && durations.length == 0) {
             return {};
         } else {
             for (let val in endTimes) {
                 cal.LOG("[calExtract] End: " + JSON.stringify(endTimes[val]));
             }
 
             let wDay = endTimes.filter(val => val.day != null);
             let wDayNA = wDay.filter(val => val.ambiguous === undefined);
             let wMinute = endTimes.filter(val => val.minute != null);
             let wMinuteNA = wMinute.filter(val => val.ambiguous === undefined);
 
             // first set non-ambiguous dates
-            let pos = isTask == true ? 0 : wDayNA.length - 1;
+            let pos = doGuessStart ? 0 : wDayNA.length - 1;
             if (wDayNA.length != 0) {
                 guess.year = wDayNA[pos].year;
                 guess.month = wDayNA[pos].month;
                 guess.day = wDayNA[pos].day;
             // then ambiguous dates
             } else if (wDay.length != 0) {
-                pos = isTask == true ? 0 : wDay.length - 1;
+                pos = doGuessStart ? 0 : wDay.length - 1;
                 guess.year = wDay[pos].year;
                 guess.month = wDay[pos].month;
                 guess.day = wDay[pos].day;
             }
 
             // then non-ambiguous times
             if (wMinuteNA.length != 0) {
-                pos = isTask == true ? 0 : wMinuteNA.length - 1;
+                pos = doGuessStart ? 0 : wMinuteNA.length - 1;
                 guess.hour = wMinuteNA[pos].hour;
                 guess.minute = wMinuteNA[pos].minute;
                 if (guess.day == null || guess.day == start.day) {
                     if (wMinuteNA[pos].hour < start.hour ||
                            (wMinuteNA[pos].hour == start.hour &&
                             wMinuteNA[pos].minute < start.minute)) {
                         let nextDay = new Date(start.year, start.month - 1, start.day);
                         nextDay.setTime(nextDay.getTime() + 60 * 60 * 24 * 1000);
                         guess.year = nextDay.getFullYear();
                         guess.month = nextDay.getMonth() + 1;
                         guess.day = nextDay.getDate();
                     }
                 }
             // and ambiguous times
             } else if (wMinute.length != 0) {
-                pos = isTask == true ? 0 : wMinute.length - 1;
+                pos = doGuessStart ? 0 : wMinute.length - 1;
                 guess.hour = wMinute[pos].hour;
                 guess.minute = wMinute[pos].minute;
                 if (guess.day == null || guess.day == start.day) {
                     if (wMinute[pos].hour < start.hour ||
                            (wMinute[pos].hour == start.hour &&
                             wMinute[pos].minute < start.minute)) {
                         let nextDay = new Date(start.year, start.month - 1, start.day);
                         nextDay.setTime(nextDay.getTime() + 60 * 60 * 24 * 1000);
@@ -961,17 +961,17 @@ Extractor.prototype = {
             if (guessTime <= startTime) {
                 guess.year = null;
                 guess.month = null;
                 guess.day = null;
                 guess.hour = null;
                 guess.minute = null;
             }
 
-            if (guess.year != null && guess.minute == null && isTask) {
+            if (guess.year != null && guess.minute == null && doGuessStart) {
                 guess.hour = 0;
                 guess.minute = 0;
             }
 
             cal.LOG("[calExtract] End picked: " + JSON.stringify(guess));
             return guess;
         }
     },
--- a/calendar/lightning/content/lightning-item-iframe.js
+++ b/calendar/lightning/content/lightning-item-iframe.js
@@ -510,17 +510,17 @@ function onCancel(aIframeId, aPreventClo
 
     if (!gConfirmCancel || (gConfirmCancel && onCommandCancel())) {
         dispose();
         // Don't allow closing the dialog when the user inputs a wrong
         // date then closes the dialog and answers with "Save" in
         // the "Save Event" dialog.  Don't allow closing the dialog if
         // the main window is being closed but the tabs in it are not.
 
-        if (!gWarning && aPreventClose != true) {
+        if (!gWarning && !aPreventClose) {
             sendMessage({ command: "closeWindowOrTab", iframeId: aIframeId });
         }
         return !gWarning;
     }
     return false;
 }
 
 /**
@@ -747,17 +747,17 @@ function loadDialog(aItem) {
                                       ((itemProp === null)
                                        ? Preferences.get("calendar.itip.notify", true)
                                        : (itemProp == "TRUE")));
             let undiscloseProp = aItem.getProperty("X-MOZ-SEND-INVITATIONS-UNDISCLOSED");
             undiscloseCheckbox.checked = (undiscloseProp === null)
                                          ? false // default value as most common within organizations
                                          : (undiscloseProp == "TRUE");
             // disable checkbox, if notifyCheckbox is not checked
-            undiscloseCheckbox.disabled = (notifyCheckbox.checked == false);
+            undiscloseCheckbox.disabled = !notifyCheckbox.checked;
         }
         // this may also be a server exposed calendar property from exchange servers - if so, this
         // probably should overrule the client-side config option
         let disallowCounterProp = aItem.getProperty("X-MICROSOFT-DISALLOW-COUNTER");
         disallowcounterCheckbox.checked = disallowCounterProp == "TRUE";
         // if we're in reschedule mode, it's pointless to enable the control
         disallowcounterCheckbox.disabled = !!window.counterProposal;
 
--- a/calendar/test/mozmill/shared-modules/test-calendar-utils.js
+++ b/calendar/test/mozmill/shared-modules/test-calendar-utils.js
@@ -320,17 +320,17 @@ function invokeEventDialog(controller, c
     }, MID_SLEEP);
 
     let eventWindow = mozmill.utils.getWindows("Calendar:EventDialog")[0];
     let eventController = new mozmill.controller.MozMillController(eventWindow);
     let iframe = eventController.window.document.getElementById("lightning-item-panel-iframe");
 
     eventController.waitFor(() => {
         return iframe.contentWindow.onLoad &&
-               iframe.contentWindow.onLoad.hasLoaded == true;
+               iframe.contentWindow.onLoad.hasLoaded;
     }, "event-dialog did not load in time", 10000);
 
     // We can't use a full mozmill controller on an iframe, but we need
     // something for helpersForController.
     let mockIframeController = { window: iframe.contentWindow };
 
     body(eventController, mockIframeController);
 
@@ -529,17 +529,17 @@ function handleNewCalendarWizard(wizard,
             anon({"class":"textbox-input-box"})/anon({"anonid":"input"})
         `), data.network.location);
 
         // choose offline support
         if (data.network.offline == undefined) {
             data.network.offline = true;
         }
         wizard.check(wizardId("cache"), data.network.offline);
-        wizard.waitFor(() => dlgButton("next").disabled == false);
+        wizard.waitFor(() => !dlgButton("next").disabled);
         dlgButton("next").doCommand();
     } else {
         // local calendar is default
         dlgButton("next").doCommand();
     }
     // set calendar Name
     wizard.waitForElement(wizardId("calendar-name"));
     // not on all platforms setting the value activates the next button
@@ -554,17 +554,17 @@ function handleNewCalendarWizard(wizard,
     }
     wizard.check(wizardId("fire-alarms"), data.showReminders);
 
     // set eMail Account
     if (data.eMail == undefined) {
         data.eMail = "none";
     }
     menulistSelect(wizardId("email-identity-menulist"), data.eMail, wizard);
-    wizard.waitFor(() => dlgButton("next").disabled == false);
+    wizard.waitFor(() => !dlgButton("next").disabled);
     dlgButton("next").doCommand();
 
     // finish
     dlgButton("finish").doCommand();
 }
 
 /**
  * Retrieves array of all calendar-event-box elements in node
--- a/calendar/test/mozmill/shared-modules/test-timezone-utils.js
+++ b/calendar/test/mozmill/shared-modules/test-timezone-utils.js
@@ -117,12 +117,12 @@ function verify(controller, dates, timez
 
             if (day != undefined && day == 1) {
                 viewBack(controller, 1);
             }
 
             if (day != undefined && day == -1) {
                 viewForward(controller, 1);
             }
-            controller.assertJS(found == true);
+            controller.assertJS(found);
         }
     }
 }