Skip to content

Commit

Permalink
Bug 1578683 Turn on ESLint rule prefer-boolean-length-check for toolk…
Browse files Browse the repository at this point in the history
…it and browser r=Standard8

Differential Revision: https://phabricator.services.mozilla.com/D45629
  • Loading branch information
maheshwarimonika committed Sep 14, 2019
1 parent 55ac589 commit 9faceab
Show file tree
Hide file tree
Showing 302 changed files with 641 additions and 667 deletions.
8 changes: 8 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -336,5 +336,13 @@ module.exports = {
"rules": {
"no-async-promise-executor": "off",
}
},{
"files": [
"toolkit/**",
"browser/**",
],
"rules": {
"mozilla/prefer-boolean-length-check": "error",
}
}]
};
2 changes: 1 addition & 1 deletion browser/actors/PageStyleChild.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class PageStyleChild extends ActorChild {
}

// Skip any stylesheets that don't match the screen media type.
if (currentStyleSheet.media.length > 0) {
if (currentStyleSheet.media.length) {
let mediaQueryList = currentStyleSheet.media.mediaText;
if (!content.matchMedia(mediaQueryList).matches) {
continue;
Expand Down
6 changes: 3 additions & 3 deletions browser/actors/PluginChild.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ class PluginChild extends JSWindowActorChild {
return;
}
evt.preventDefault();
if (callbackArgs.length == 0) {
if (!callbackArgs.length) {
callbackArgs = [evt];
}
self[callbackName].apply(self, callbackArgs);
Expand All @@ -351,7 +351,7 @@ class PluginChild extends JSWindowActorChild {
}
if (evt.keyCode == evt.DOM_VK_RETURN) {
evt.preventDefault();
if (callbackArgs.length == 0) {
if (!callbackArgs.length) {
callbackArgs = [evt];
}
evt.preventDefault();
Expand Down Expand Up @@ -803,7 +803,7 @@ class PluginChild extends JSWindowActorChild {
Ci.nsIObjectLoadingContent.TYPE_PLUGIN
);

if (plugins.length == 0) {
if (!plugins.length) {
this.removeNotification();
return;
}
Expand Down
2 changes: 1 addition & 1 deletion browser/base/content/aboutNetError.js
Original file line number Diff line number Diff line change
Expand Up @@ -863,7 +863,7 @@ function setTechnicalDetailsOnCertError() {

if (failedCertInfo.isDomainMismatch) {
let subjectAltNames = failedCertInfo.subjectAltNames.split(",");
subjectAltNames = subjectAltNames.filter(name => name.length > 0);
subjectAltNames = subjectAltNames.filter(name => !!name.length);
let numSubjectAltNames = subjectAltNames.length;

if (numSubjectAltNames != 0) {
Expand Down
6 changes: 3 additions & 3 deletions browser/base/content/browser-addons.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ var gXPInstallObserver = {
i => i.addon.signedState <= AddonManager.SIGNEDSTATE_MISSING
);
let someUnsigned =
unsigned.length > 0 && unsigned.length < installInfo.installs.length;
!!unsigned.length && unsigned.length < installInfo.installs.length;

options.eventCallback = aEvent => {
switch (aEvent) {
Expand Down Expand Up @@ -361,7 +361,7 @@ var gXPInstallObserver = {
);
notification.setAttribute("warning", "true");
options.learnMoreURL += "unsigned-addons";
} else if (unsigned.length == 0) {
} else if (!unsigned.length) {
// All add-ons are verified or don't need to be verified
messageString = gNavigatorBundle.getString("addonConfirmInstall.message");
notification.removeAttribute("warning");
Expand Down Expand Up @@ -450,7 +450,7 @@ var gXPInstallObserver = {

PopupNotifications.remove(notifications, true);

return notifications.length > 0;
return !!notifications.length;
},

logWarningFullScreenInstallBlocked() {
Expand Down
4 changes: 2 additions & 2 deletions browser/base/content/browser-fullScreenAndPointerLock.js
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ var FullScreen = {
window.fullScreen &&
PopupNotifications.getNotification(
this._permissionNotificationIDs
).filter(n => !n.dismissed).length > 0
).filter(n => !n.dismissed).length
) {
this.exitDomFullScreen();
this._logWarningPermissionPromptFS("fullScreenCanceled");
Expand Down Expand Up @@ -513,7 +513,7 @@ var FullScreen = {
this._permissionNotificationIDs
).filter(n => !n.dismissed);
PopupNotifications.remove(notifications, true);
if (notifications.length > 0) {
if (notifications.length) {
this._logWarningPermissionPromptFS("promptCanceled");
}
}
Expand Down
2 changes: 1 addition & 1 deletion browser/base/content/browser-pageActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -1309,7 +1309,7 @@ BrowserPageActions.shareURL = {

// We cache the providers + the UI if the user selects the share
// panel multiple times while the panel is open.
if (this._cached && bodyNode.children.length > 0) {
if (this._cached && bodyNode.children.length) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion browser/base/content/browser-siteProtections.js
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ var TrackingProtection = {
// not detect trackers on the page using the basic list, we currently
// still show the panel. To reduce the confusion, tell the user that we have
// not detected any tracker.
if (fragment.childNodes.length == 0) {
if (!fragment.childNodes.length) {
let emptyBox = document.createXULElement("vbox");
let emptyImage = document.createXULElement("image");
emptyImage.classList.add("protections-popup-trackersView-empty-image");
Expand Down
2 changes: 1 addition & 1 deletion browser/base/content/browser-sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -795,7 +795,7 @@ var gSync = {

const state = UIState.get();
if (state.status == UIState.STATUS_SIGNED_IN) {
if (this.sendTabTargets.length > 0) {
if (this.sendTabTargets.length) {
this._appendSendTabDeviceList(
fragment,
createDeviceNodeFn,
Expand Down
2 changes: 1 addition & 1 deletion browser/base/content/browser-tabsintitlebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ var TabsInTitlebar;
let allowed =
this.systemSupported &&
!window.fullScreen &&
Object.keys(this._disallowed).length == 0;
!Object.keys(this._disallowed).length;
if (allowed) {
document.documentElement.setAttribute("tabsintitlebar", "true");
if (AppConstants.platform == "macosx") {
Expand Down
4 changes: 2 additions & 2 deletions browser/base/content/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -3882,7 +3882,7 @@ function BrowserReloadWithFlags(reloadFlags) {
}
}

if (unchangedRemoteness.length == 0) {
if (!unchangedRemoteness.length) {
return;
}

Expand Down Expand Up @@ -4687,7 +4687,7 @@ const BrowserSearch = {
}

var engines = gBrowser.selectedBrowser.engines;
if (engines && engines.length > 0) {
if (engines && engines.length) {
searchBar.setAttribute("addengines", "true");
} else {
searchBar.removeAttribute("addengines");
Expand Down
2 changes: 1 addition & 1 deletion browser/base/content/nsContextMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ nsContextMenu.prototype = {
const { gBrowser } = this.browser.ownerGlobal;

this.textSelected = this.selectionInfo.text;
this.isTextSelected = this.textSelected.length != 0;
this.isTextSelected = !!this.textSelected.length;
this.webExtBrowserType = this.browser.getAttribute(
"webextension-view-type"
);
Expand Down
2 changes: 1 addition & 1 deletion browser/base/content/pageinfo/security.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ var security = {
let usage = this.siteData.reduce((acc, site) => acc + site.usage, 0);
if (usage > 0) {
let size = DownloadUtils.convertByteUnits(usage);
let hasCookies = this.siteData.some(site => site.cookies.length > 0);
let hasCookies = this.siteData.some(site => !!site.cookies.length);
if (hasCookies) {
document.l10n.setAttributes(
siteDataLabel,
Expand Down
11 changes: 4 additions & 7 deletions browser/base/content/tabbrowser.js
Original file line number Diff line number Diff line change
Expand Up @@ -3320,11 +3320,7 @@
// Closing the tab and replacing it with a blank one is notably slower
// than closing the window right away. If the caller opts in, take
// the fast path.
if (
closeWindow &&
closeWindowFastpath &&
this._removingTabs.length == 0
) {
if (closeWindow && closeWindowFastpath && !this._removingTabs.length) {
// This call actually closes the window, unless the user
// cancels the operation. We are finished here in both cases.
this._windowIsClosing = window.closeWindow(
Expand Down Expand Up @@ -6279,8 +6275,9 @@ var TabContextMenu = {

// Disable "Close Tabs to the Right" if there are no tabs
// following it.
document.getElementById("context_closeTabsToTheEnd").disabled =
gBrowser.getTabsToTheEndFrom(this.contextTab).length == 0;
document.getElementById(
"context_closeTabsToTheEnd"
).disabled = !gBrowser.getTabsToTheEndFrom(this.contextTab).length;

// Disable "Close other Tabs" if there are no unpinned tabs.
let unpinnedTabsToClose = multiselectionContext
Expand Down
2 changes: 1 addition & 1 deletion browser/base/content/test/forms/browser_selectpopup.js
Original file line number Diff line number Diff line change
Expand Up @@ -797,7 +797,7 @@ async function performLargePopupTests(win) {
);

// Don't check the scroll position for the last step as the popup will be cut off.
if (positions.length > 0) {
if (positions.length) {
let cs = win.getComputedStyle(selectPopup);
let bpBottom =
parseFloat(cs.paddingBottom) + parseFloat(cs.borderBottomWidth);
Expand Down
4 changes: 2 additions & 2 deletions browser/base/content/test/general/browser_contentAreaClick.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,11 +291,11 @@ function runNextTest() {
gCurrentTest.setup();
}

if (gCurrentTest.targets.length == 0) {
if (!gCurrentTest.targets.length) {
info(gCurrentTest.desc + ": cleaning up...");
gCurrentTest.clean();

if (gTests.length > 0) {
if (gTests.length) {
gCurrentTest = gTests.shift();
gCurrentTest.setup();
} else {
Expand Down
4 changes: 2 additions & 2 deletions browser/base/content/test/general/browser_contentSearchUI.js
Original file line number Diff line number Diff line change
Expand Up @@ -746,10 +746,10 @@ function checkState(
s => s.type == "formHistory"
),

tableHidden: expectedSuggestions.length == 0,
tableHidden: !expectedSuggestions.length,

inputValue: expectedInputVal,
ariaExpanded: expectedSuggestions.length == 0 ? "false" : "true",
ariaExpanded: !expectedSuggestions.length ? "false" : "true",
};
if (expectedSelectedButtonIdx != undefined) {
expectedState.selectedButtonIndex = expectedSelectedButtonIdx;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ add_task(async function() {
// no I/O marker in that case, but it's good to keep the test running to check
// that we are still able to produce startup profiles.
is(
markers.length > 0,
!!markers.length,
!AppConstants.RELEASE_OR_BETA,
procName +
" startup profiles should have IO markers in builds that are not RELEASE_OR_BETA"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ add_task(async function() {
// Ensure all the frame data is in the test compartment to avoid traversing
// a cross compartment wrapper for each pixel.
let frames = Cu.cloneInto(startupRecorder.data.frames, {});
ok(frames.length > 0, "Should have captured some frames.");
ok(!!frames.length, "Should have captured some frames.");

let unexpectedRects = 0;
let alreadyFocused = false;
Expand Down
2 changes: 1 addition & 1 deletion browser/base/content/test/plugins/head.js
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ function promiseUpdatePluginBindings(browser) {
if (!elems || elems.length < 1) {
elems = doc.getElementsByTagName("object");
}
if (elems && elems.length > 0) {
if (elems && elems.length) {
elems[0].clientTop;
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ var tests = [
let anchor = win.document.getElementById("default-notification-icon");
win.PopupNotifications._reshowNotifications(anchor);
ok(
win.PopupNotifications.panel.children.length == 0,
!win.PopupNotifications.panel.children.length,
"no notification displayed in new window"
);
ok(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ var tests = [
let anchor = win.document.getElementById("default-notification-icon");
win.PopupNotifications._reshowNotifications(anchor);
ok(
win.PopupNotifications.panel.children.length == 0,
!win.PopupNotifications.panel.children.length,
"no notification displayed in new window"
);

Expand Down
8 changes: 4 additions & 4 deletions browser/base/content/test/popupNotifications/head.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ function goNext() {
}

async function runNextTest() {
if (tests.length == 0) {
if (!tests.length) {
executeSoon(finish);
return;
}
Expand Down Expand Up @@ -246,7 +246,7 @@ function checkPopup(popup, notifyObj) {
"main action highlight matches"
);
}
if (notifyObj.secondaryActions && notifyObj.secondaryActions.length > 0) {
if (notifyObj.secondaryActions && notifyObj.secondaryActions.length) {
let secondaryAction = notifyObj.secondaryActions[0];
is(
notification.getAttribute("secondarybuttonlabel"),
Expand Down Expand Up @@ -330,15 +330,15 @@ function waitForNotificationPanelHidden() {

function triggerMainCommand(popup) {
let notifications = popup.childNodes;
ok(notifications.length > 0, "at least one notification displayed");
ok(!!notifications.length, "at least one notification displayed");
let notification = notifications[0];
info("Triggering main command for notification " + notification.id);
EventUtils.synthesizeMouseAtCenter(notification.button, {});
}

function triggerSecondaryCommand(popup, index) {
let notifications = popup.childNodes;
ok(notifications.length > 0, "at least one notification displayed");
ok(!!notifications.length, "at least one notification displayed");
let notification = notifications[0];
info("Triggering secondary command for notification " + notification.id);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ add_task(async function test_install_extension_from_local_file() {

// Make sure we got some data.
ok(
snapshot.parent && snapshot.parent.length > 0,
snapshot.parent && !!snapshot.parent.length,
"Got parent telemetry events in the snapshot"
);

Expand Down
2 changes: 1 addition & 1 deletion browser/base/content/test/webextensions/head.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ function checkNotification(panel, checkIcon, permissions) {
permissions.length,
`Permissions list has ${permissions.length} entries`
);
if (permissions.length == 0) {
if (!permissions.length) {
is(header.getAttribute("hidden"), "true", "Permissions header is hidden");
is(
learnMoreLink.getAttribute("hidden"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function stopClonedTracks(audio, video) {
clones.filter(t => t.kind == "video").forEach(t => t.stop());
}
let liveClones = clones.filter(t => t.readyState == "live");
if (liveClones.length == 0) {
if (!liveClones.length) {
delete content.wrappedJSObject.gClones;
} else {
content.wrappedJSObject.gClones = liveClones;
Expand Down
2 changes: 1 addition & 1 deletion browser/base/content/utilityOverlay.js
Original file line number Diff line number Diff line change
Expand Up @@ -888,7 +888,7 @@ function eventMatchesKey(aEvent, aKey) {
aEvent.getModifierState(modifier)
);
// Check if aEvent has a modifier and aKey doesn't
if (eventModifiers.length > 0 && keyModifiers.length == 0) {
if (eventModifiers.length && !keyModifiers.length) {
return false;
}
// Check whether aKey's modifiers match aEvent's modifiers
Expand Down
2 changes: 1 addition & 1 deletion browser/components/about/AboutPrivateBrowsingHandler.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ var AboutPrivateBrowsingHandler = {
let searchAlias = "";
let searchAliases =
Services.search.defaultEngine.wrappedJSObject.__internalAliases;
if (searchAliases && searchAliases.length > 0) {
if (searchAliases && searchAliases.length) {
searchAlias = `${searchAliases[0]} `;
}
let urlBar = aMessage.target.browser.ownerGlobal.gURLBar;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ add_task(async function test_login_removed() {
await ContentTask.spawn(browser, login, async removedLogin => {
let loginList = Cu.waiveXrays(content.document.querySelector("login-list"));
let loginRemoved = await ContentTaskUtils.waitForCondition(() => {
return loginList._loginGuidsSortedOrder.length == 0;
return !loginList._loginGuidsSortedOrder.length;
}, "Waiting for login to get removed");
ok(loginRemoved, "The login should be removed from the page");
});
Expand Down Expand Up @@ -121,7 +121,7 @@ add_task(async function test_all_logins_removed() {
await ContentTask.spawn(browser, null, async () => {
let loginList = Cu.waiveXrays(content.document.querySelector("login-list"));
let loginFound = await ContentTaskUtils.waitForCondition(() => {
return loginList._loginGuidsSortedOrder.length == 0;
return !loginList._loginGuidsSortedOrder.length;
}, "Waiting for logins to be cleared");
ok(loginFound, "Logins should be cleared");
ok(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<title>title not set</title>
<script>
// if we have a query string, use it to set the cookie and localStorage
if (window.location.search.length > 0) {
if (window.location.search.length) {
let context_name = window.location.search.substr(1);
document.cookie = "userContextId=" + context_name;
localStorage.setItem("userContext", context_name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"use strict";

// if we have a query string, use it to set storages
if (window.location.search.length > 0) {
if (window.location.search.length) {
let context_name = window.location.search.substr(1);
localStorage.setItem("userContext", context_name);
sessionStorage.setItem("userContext", context_name);
Expand Down
Loading

0 comments on commit 9faceab

Please sign in to comment.