diff --git a/.eslintrc.js b/.eslintrc.js index 3d890dcfc8e9..b3ca14ff51e5 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -336,5 +336,13 @@ module.exports = { "rules": { "no-async-promise-executor": "off", } + },{ + "files": [ + "toolkit/**", + "browser/**", + ], + "rules": { + "mozilla/prefer-boolean-length-check": "error", + } }] }; diff --git a/browser/actors/PageStyleChild.jsm b/browser/actors/PageStyleChild.jsm index d05acd9c654c..76149e7d31dc 100644 --- a/browser/actors/PageStyleChild.jsm +++ b/browser/actors/PageStyleChild.jsm @@ -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; diff --git a/browser/actors/PluginChild.jsm b/browser/actors/PluginChild.jsm index e3bbe02f6a25..05b5040a6b9a 100644 --- a/browser/actors/PluginChild.jsm +++ b/browser/actors/PluginChild.jsm @@ -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); @@ -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(); @@ -803,7 +803,7 @@ class PluginChild extends JSWindowActorChild { Ci.nsIObjectLoadingContent.TYPE_PLUGIN ); - if (plugins.length == 0) { + if (!plugins.length) { this.removeNotification(); return; } diff --git a/browser/base/content/aboutNetError.js b/browser/base/content/aboutNetError.js index 89b320543681..c89f7e760d72 100644 --- a/browser/base/content/aboutNetError.js +++ b/browser/base/content/aboutNetError.js @@ -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) { diff --git a/browser/base/content/browser-addons.js b/browser/base/content/browser-addons.js index 6ec1f988651a..6ecf3b5b866b 100644 --- a/browser/base/content/browser-addons.js +++ b/browser/base/content/browser-addons.js @@ -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) { @@ -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"); @@ -450,7 +450,7 @@ var gXPInstallObserver = { PopupNotifications.remove(notifications, true); - return notifications.length > 0; + return !!notifications.length; }, logWarningFullScreenInstallBlocked() { diff --git a/browser/base/content/browser-fullScreenAndPointerLock.js b/browser/base/content/browser-fullScreenAndPointerLock.js index 7e6309e917e4..28779f2d1809 100644 --- a/browser/base/content/browser-fullScreenAndPointerLock.js +++ b/browser/base/content/browser-fullScreenAndPointerLock.js @@ -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"); @@ -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"); } } diff --git a/browser/base/content/browser-pageActions.js b/browser/base/content/browser-pageActions.js index ff33127353c7..1d0e011dbd22 100644 --- a/browser/base/content/browser-pageActions.js +++ b/browser/base/content/browser-pageActions.js @@ -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; } diff --git a/browser/base/content/browser-siteProtections.js b/browser/base/content/browser-siteProtections.js index a1709e5e57d5..01a7ab4d8aba 100644 --- a/browser/base/content/browser-siteProtections.js +++ b/browser/base/content/browser-siteProtections.js @@ -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"); diff --git a/browser/base/content/browser-sync.js b/browser/base/content/browser-sync.js index 1e64fe448b40..d6b13705e8c5 100644 --- a/browser/base/content/browser-sync.js +++ b/browser/base/content/browser-sync.js @@ -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, diff --git a/browser/base/content/browser-tabsintitlebar.js b/browser/base/content/browser-tabsintitlebar.js index 2ede43f3eeb3..2e42ed100657 100644 --- a/browser/base/content/browser-tabsintitlebar.js +++ b/browser/base/content/browser-tabsintitlebar.js @@ -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") { diff --git a/browser/base/content/browser.js b/browser/base/content/browser.js index 576e1351415b..19ef05d5daa1 100644 --- a/browser/base/content/browser.js +++ b/browser/base/content/browser.js @@ -3882,7 +3882,7 @@ function BrowserReloadWithFlags(reloadFlags) { } } - if (unchangedRemoteness.length == 0) { + if (!unchangedRemoteness.length) { return; } @@ -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"); diff --git a/browser/base/content/nsContextMenu.js b/browser/base/content/nsContextMenu.js index 8a0bceb8c671..2d93901aa231 100644 --- a/browser/base/content/nsContextMenu.js +++ b/browser/base/content/nsContextMenu.js @@ -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" ); diff --git a/browser/base/content/pageinfo/security.js b/browser/base/content/pageinfo/security.js index 4c357425dee2..09419c37fb83 100644 --- a/browser/base/content/pageinfo/security.js +++ b/browser/base/content/pageinfo/security.js @@ -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, diff --git a/browser/base/content/tabbrowser.js b/browser/base/content/tabbrowser.js index 917333c0780e..16eb089a7c74 100644 --- a/browser/base/content/tabbrowser.js +++ b/browser/base/content/tabbrowser.js @@ -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( @@ -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 diff --git a/browser/base/content/test/forms/browser_selectpopup.js b/browser/base/content/test/forms/browser_selectpopup.js index e35978866bd6..55cfaf78d1da 100644 --- a/browser/base/content/test/forms/browser_selectpopup.js +++ b/browser/base/content/test/forms/browser_selectpopup.js @@ -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); diff --git a/browser/base/content/test/general/browser_contentAreaClick.js b/browser/base/content/test/general/browser_contentAreaClick.js index 60b934bce1b0..5fb8132012f9 100644 --- a/browser/base/content/test/general/browser_contentAreaClick.js +++ b/browser/base/content/test/general/browser_contentAreaClick.js @@ -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 { diff --git a/browser/base/content/test/general/browser_contentSearchUI.js b/browser/base/content/test/general/browser_contentSearchUI.js index 3c3e4049e3f1..6c8db64bdef1 100644 --- a/browser/base/content/test/general/browser_contentSearchUI.js +++ b/browser/base/content/test/general/browser_contentSearchUI.js @@ -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; diff --git a/browser/base/content/test/performance/browser_startup_content_mainthreadio.js b/browser/base/content/test/performance/browser_startup_content_mainthreadio.js index 836e991cbea7..e97a164479d4 100644 --- a/browser/base/content/test/performance/browser_startup_content_mainthreadio.js +++ b/browser/base/content/test/performance/browser_startup_content_mainthreadio.js @@ -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" diff --git a/browser/base/content/test/performance/browser_startup_flicker.js b/browser/base/content/test/performance/browser_startup_flicker.js index 41e508540e42..5f70ba786641 100644 --- a/browser/base/content/test/performance/browser_startup_flicker.js +++ b/browser/base/content/test/performance/browser_startup_flicker.js @@ -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; diff --git a/browser/base/content/test/plugins/head.js b/browser/base/content/test/plugins/head.js index 366efc00d2da..246e8c5cfbcd 100644 --- a/browser/base/content/test/plugins/head.js +++ b/browser/base/content/test/plugins/head.js @@ -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; } }); diff --git a/browser/base/content/test/popupNotifications/browser_popupNotification_4.js b/browser/base/content/test/popupNotifications/browser_popupNotification_4.js index 796508eec975..27375a172d0c 100644 --- a/browser/base/content/test/popupNotifications/browser_popupNotification_4.js +++ b/browser/base/content/test/popupNotifications/browser_popupNotification_4.js @@ -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( diff --git a/browser/base/content/test/popupNotifications/browser_popupNotification_5.js b/browser/base/content/test/popupNotifications/browser_popupNotification_5.js index 1302f8bb8ff9..11598445518d 100644 --- a/browser/base/content/test/popupNotifications/browser_popupNotification_5.js +++ b/browser/base/content/test/popupNotifications/browser_popupNotification_5.js @@ -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" ); diff --git a/browser/base/content/test/popupNotifications/head.js b/browser/base/content/test/popupNotifications/head.js index a619c93b63da..4ae7657fe00f 100644 --- a/browser/base/content/test/popupNotifications/head.js +++ b/browser/base/content/test/popupNotifications/head.js @@ -69,7 +69,7 @@ function goNext() { } async function runNextTest() { - if (tests.length == 0) { + if (!tests.length) { executeSoon(finish); return; } @@ -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"), @@ -330,7 +330,7 @@ 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, {}); @@ -338,7 +338,7 @@ function triggerMainCommand(popup) { 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); diff --git a/browser/base/content/test/webextensions/browser_permissions_local_file.js b/browser/base/content/test/webextensions/browser_permissions_local_file.js index 689438f3c6f9..d675979ab0f2 100644 --- a/browser/base/content/test/webextensions/browser_permissions_local_file.js +++ b/browser/base/content/test/webextensions/browser_permissions_local_file.js @@ -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" ); diff --git a/browser/base/content/test/webextensions/head.js b/browser/base/content/test/webextensions/head.js index 000da75fa966..2e85d845bd30 100644 --- a/browser/base/content/test/webextensions/head.js +++ b/browser/base/content/test/webextensions/head.js @@ -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"), diff --git a/browser/base/content/test/webrtc/browser_devices_get_user_media_paused.js b/browser/base/content/test/webrtc/browser_devices_get_user_media_paused.js index 16c29c81da5c..963078858bef 100644 --- a/browser/base/content/test/webrtc/browser_devices_get_user_media_paused.js +++ b/browser/base/content/test/webrtc/browser_devices_get_user_media_paused.js @@ -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; diff --git a/browser/base/content/utilityOverlay.js b/browser/base/content/utilityOverlay.js index 7c868ef75262..246a99eae8ff 100644 --- a/browser/base/content/utilityOverlay.js +++ b/browser/base/content/utilityOverlay.js @@ -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 diff --git a/browser/components/about/AboutPrivateBrowsingHandler.jsm b/browser/components/about/AboutPrivateBrowsingHandler.jsm index ff38c7f0d14f..58d9370435b2 100644 --- a/browser/components/about/AboutPrivateBrowsingHandler.jsm +++ b/browser/components/about/AboutPrivateBrowsingHandler.jsm @@ -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; diff --git a/browser/components/aboutlogins/tests/browser/browser_loginListChanges.js b/browser/components/aboutlogins/tests/browser/browser_loginListChanges.js index 21758d297cd6..5a1c9281c944 100644 --- a/browser/components/aboutlogins/tests/browser/browser_loginListChanges.js +++ b/browser/components/aboutlogins/tests/browser/browser_loginListChanges.js @@ -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"); }); @@ -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( diff --git a/browser/components/contextualidentity/test/browser/file_reflect_cookie_into_title.html b/browser/components/contextualidentity/test/browser/file_reflect_cookie_into_title.html index b04f3fd5ca81..849916d28a0a 100644 --- a/browser/components/contextualidentity/test/browser/file_reflect_cookie_into_title.html +++ b/browser/components/contextualidentity/test/browser/file_reflect_cookie_into_title.html @@ -4,7 +4,7 @@ title not set