From b426b6e2bfdf1647032f7bc80d6c95a0623ed34c Mon Sep 17 00:00:00 2001 From: Bill Thornton Date: Thu, 6 Oct 2022 01:13:06 -0400 Subject: [PATCH] Fix sonarjs prefer-single-boolean-return --- .eslintrc.js | 3 +- src/components/apphost.js | 6 +-- src/components/backdrop/backdrop.js | 19 ++------- src/components/focusManager.js | 17 ++------ src/components/htmlMediaHelper.js | 17 +++----- src/components/indicators/indicators.js | 12 ++---- src/components/itemHelper.js | 45 ++++++---------------- src/components/playback/playbackmanager.js | 24 +++--------- src/components/scrollManager.js | 6 +-- src/elements/emby-select/emby-select.js | 6 +-- src/plugins/bookPlayer/plugin.js | 6 +-- src/plugins/comicsPlayer/plugin.js | 6 +-- src/plugins/htmlAudioPlayer/plugin.js | 10 ++--- src/plugins/pdfPlayer/plugin.js | 6 +-- src/scripts/browser.js | 23 ++--------- src/scripts/browserDeviceProfile.js | 14 ++----- src/scripts/gamepadtokey.js | 13 +------ src/scripts/mouseManager.js | 6 +-- 18 files changed, 52 insertions(+), 187 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index effa0c7220..8f0e4bd8c3 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -76,8 +76,7 @@ module.exports = { 'sonarjs/cognitive-complexity': ['warn'], // TODO: Enable the following rules and fix issues 'sonarjs/no-duplicate-string': ['off'], - 'sonarjs/prefer-object-literal': ['off'], - 'sonarjs/prefer-single-boolean-return': ['off'] + 'sonarjs/prefer-object-literal': ['off'] }, settings: { react: { diff --git a/src/components/apphost.js b/src/components/apphost.js index 19b7d5233f..b75ca6a18a 100644 --- a/src/components/apphost.js +++ b/src/components/apphost.js @@ -166,11 +166,7 @@ function supportsHtmlMediaAutoplay() { return true; } - if (browser.mobile) { - return false; - } - - return true; + return !!browser.mobile; } function supportsCue() { diff --git a/src/components/backdrop/backdrop.js b/src/components/backdrop/backdrop.js index bcb4f5401a..d1af617da1 100644 --- a/src/components/backdrop/backdrop.js +++ b/src/components/backdrop/backdrop.js @@ -10,24 +10,13 @@ import './backdrop.scss'; /* eslint-disable indent */ function enableAnimation() { - if (browser.slow) { - return false; - } - - return true; + return !browser.slow; } function enableRotation() { - if (browser.tv) { - return false; - } - - // Causes high cpu usage - if (browser.firefox) { - return false; - } - - return true; + return !browser.tv + // Causes high cpu usage + && !browser.firefox; } class Backdrop { diff --git a/src/components/focusManager.js b/src/components/focusManager.js index 740ff7c07d..1eacc49e77 100644 --- a/src/components/focusManager.js +++ b/src/components/focusManager.js @@ -56,15 +56,8 @@ import scrollManager from './scrollManager'; }).join(',') + ',.focusable'; function isFocusable(elem) { - if (focusableTagNames.indexOf(elem.tagName) !== -1) { - return true; - } - - if (elem.classList && elem.classList.contains('focusable')) { - return true; - } - - return false; + return focusableTagNames.indexOf(elem.tagName) !== -1 + || (elem.classList?.contains('focusable')); } function normalizeFocusable(elem, originalElement) { @@ -97,11 +90,7 @@ import scrollManager from './scrollManager'; // Determines if a focusable element can be focused at a given point in time function isCurrentlyFocusableInternal(elem) { // http://stackoverflow.com/questions/19669786/check-if-element-is-visible-in-dom - if (elem.offsetParent === null) { - return false; - } - - return true; + return elem.offsetParent !== null; } // Determines if a focusable element can be focused at a given point in time diff --git a/src/components/htmlMediaHelper.js b/src/components/htmlMediaHelper.js index 8682cdb9da..f5eab29b93 100644 --- a/src/components/htmlMediaHelper.js +++ b/src/components/htmlMediaHelper.js @@ -26,12 +26,8 @@ import { Events } from 'jellyfin-apiclient'; function canPlayNativeHls() { const media = document.createElement('video'); - if (media.canPlayType('application/x-mpegURL').replace(/no/, '') || - media.canPlayType('application/vnd.apple.mpegURL').replace(/no/, '')) { - return true; - } - - return false; + return !!(media.canPlayType('application/x-mpegURL').replace(/no/, '') || + media.canPlayType('application/vnd.apple.mpegURL').replace(/no/, '')); } export function enableHlsJsPlayer(runTimeTicks, mediaType) { @@ -123,11 +119,10 @@ import { Events } from 'jellyfin-apiclient'; } export function isValidDuration(duration) { - if (duration && !isNaN(duration) && duration !== Number.POSITIVE_INFINITY && duration !== Number.NEGATIVE_INFINITY) { - return true; - } - - return false; + return duration + && !isNaN(duration) + && duration !== Number.POSITIVE_INFINITY + && duration !== Number.NEGATIVE_INFINITY; } function setCurrentTimeIfNeeded(element, seconds) { diff --git a/src/components/indicators/indicators.js b/src/components/indicators/indicators.js index 6fc483c3fd..cd621c2fcc 100644 --- a/src/components/indicators/indicators.js +++ b/src/components/indicators/indicators.js @@ -5,15 +5,9 @@ import './indicators.scss'; import 'material-design-icons-iconfont'; export function enableProgressIndicator(item) { - if (item.MediaType === 'Video' && item.Type !== 'TvChannel') { - return true; - } - - if (item.Type === 'AudioBook' || item.Type === 'AudioPodcast') { - return true; - } - - return false; + return (item.MediaType === 'Video' && item.Type !== 'TvChannel') + || item.Type === 'AudioBook' + || item.Type === 'AudioPodcast'; } export function getProgressHtml(pct, options) { diff --git a/src/components/itemHelper.js b/src/components/itemHelper.js index 2a181d3424..0aa9919875 100644 --- a/src/components/itemHelper.js +++ b/src/components/itemHelper.js @@ -117,11 +117,7 @@ export function canEdit(user, item) { } export function isLocalItem(item) { - if (item && item.Id && typeof item.Id === 'string' && item.Id.indexOf('local') === 0) { - return true; - } - - return false; + return item && item.Id && typeof item.Id === 'string' && item.Id.indexOf('local') === 0; } export function canIdentify (user, item) { @@ -148,11 +144,7 @@ export function canEditImages (user, item) { } if (itemType === 'UserView') { - if (user.Policy.IsAdministrator) { - return true; - } - - return false; + return user.Policy.IsAdministrator; } if (item.Type === 'Recording' && item.Status !== 'Completed') { @@ -218,29 +210,21 @@ export function canMarkPlayed (item) { } } - if (item.Type === 'Series' || - item.Type === 'Season' || - item.Type === 'BoxSet' || - item.MediaType === 'Book' || - item.MediaType === 'Recording') { - return true; - } - - return false; + return item.Type === 'Series' + || item.Type === 'Season' + || item.Type === 'BoxSet' + || item.MediaType === 'Book' + || item.MediaType === 'Recording'; } export function canRate (item) { - if (item.Type === 'Program' + return item.Type === 'Program' || item.Type === 'Timer' || item.Type === 'SeriesTimer' || item.Type === 'CollectionFolder' || item.Type === 'UserView' || item.Type === 'Channel' - || !item.UserData) { - return false; - } - - return true; + || !item.UserData; } export function canConvert (item, user) { @@ -271,11 +255,7 @@ export function canConvert (item, user) { return false; } - if (item.IsPlaceHolder) { - return false; - } - - return true; + return item.IsPlaceHolder; } export function canRefreshMetadata (item, user) { @@ -307,11 +287,8 @@ export function supportsMediaSourceSelection (item) { if (item.EnableMediaSourceDisplay === false) { return false; } - if (item.EnableMediaSourceDisplay == null && item.SourceType && item.SourceType !== 'Library') { - return false; - } - return true; + return item.EnableMediaSourceDisplay == null && item.SourceType && item.SourceType !== 'Library'; } export function sortTracks (trackA, trackB) { diff --git a/src/components/playback/playbackmanager.js b/src/components/playback/playbackmanager.js index 4259354d81..8b8bc63921 100644 --- a/src/components/playback/playbackmanager.js +++ b/src/components/playback/playbackmanager.js @@ -19,11 +19,7 @@ function enableLocalPlaylistManagement(player) { return false; } - if (player.isLocalPlayer) { - return true; - } - - return false; + return player.isLocalPlayer; } function bindToFullscreenChange(player) { @@ -225,11 +221,7 @@ function getParam(name, url) { } function isAutomaticPlayer(player) { - if (player.isLocalPlayer) { - return true; - } - - return false; + return player.isLocalPlayer; } function getAutomaticPlayers(instance, forceLocalPlayer) { @@ -244,10 +236,7 @@ function getAutomaticPlayers(instance, forceLocalPlayer) { } function isServerItem(item) { - if (!item.Id) { - return false; - } - return true; + return !!item.Id; } function enableIntros(item) { @@ -3007,11 +2996,8 @@ class PlaybackManager { function enablePlaybackRetryWithTranscoding(streamInfo, errorType, currentlyPreventsVideoStreamCopy, currentlyPreventsAudioStreamCopy) { // mediadecodeerror, medianotsupported, network, servererror - if (streamInfo.mediaSource.SupportsTranscoding && (!currentlyPreventsVideoStreamCopy || !currentlyPreventsAudioStreamCopy)) { - return true; - } - - return false; + return streamInfo.mediaSource.SupportsTranscoding + && (!currentlyPreventsVideoStreamCopy || !currentlyPreventsAudioStreamCopy); } function onPlaybackError(e, error) { diff --git a/src/components/scrollManager.js b/src/components/scrollManager.js index 53c09e37e5..72f5a69fb2 100644 --- a/src/components/scrollManager.js +++ b/src/components/scrollManager.js @@ -479,11 +479,7 @@ import layoutManager from './layoutManager'; * Returns true if smooth scroll must be used. */ function useSmoothScroll() { - if (browser.tizen) { - return true; - } - - return false; + return !!browser.tizen; } /** diff --git a/src/elements/emby-select/emby-select.js b/src/elements/emby-select/emby-select.js index e069687822..b576042821 100644 --- a/src/elements/emby-select/emby-select.js +++ b/src/elements/emby-select/emby-select.js @@ -23,11 +23,7 @@ import 'webcomponents.js/webcomponents-lite'; return true; } - if (layoutManager.tv) { - return false; - } - - return true; + return !layoutManager.tv; } function triggerChange(select) { diff --git a/src/plugins/bookPlayer/plugin.js b/src/plugins/bookPlayer/plugin.js index a4f49b8b6e..d0fcffa48a 100644 --- a/src/plugins/bookPlayer/plugin.js +++ b/src/plugins/bookPlayer/plugin.js @@ -339,11 +339,7 @@ export class BookPlayer { } canPlayItem(item) { - if (item.Path && item.Path.endsWith('epub')) { - return true; - } - - return false; + return item.Path && item.Path.endsWith('epub'); } } diff --git a/src/plugins/comicsPlayer/plugin.js b/src/plugins/comicsPlayer/plugin.js index 2d72abaa0b..d209069ad3 100644 --- a/src/plugins/comicsPlayer/plugin.js +++ b/src/plugins/comicsPlayer/plugin.js @@ -356,11 +356,7 @@ export class ComicsPlayer { } canPlayItem(item) { - if (item.Path && (item.Path.endsWith('cbz') || item.Path.endsWith('cbr'))) { - return true; - } - - return false; + return item.Path && (item.Path.endsWith('cbz') || item.Path.endsWith('cbr')); } } diff --git a/src/plugins/htmlAudioPlayer/plugin.js b/src/plugins/htmlAudioPlayer/plugin.js index 4d31e52cae..1873970e1b 100644 --- a/src/plugins/htmlAudioPlayer/plugin.js +++ b/src/plugins/htmlAudioPlayer/plugin.js @@ -41,13 +41,9 @@ function cancelFadeTimeout() { } function supportsFade() { - if (browser.tv) { - // Not working on tizen. - // We could possibly enable on other tv's, but all smart tv browsers tend to be pretty primitive - return false; - } - - return true; + // Not working on tizen. + // We could possibly enable on other tv's, but all smart tv browsers tend to be pretty primitive + return !browser.tv; } function requireHlsPlayer(callback) { diff --git a/src/plugins/pdfPlayer/plugin.js b/src/plugins/pdfPlayer/plugin.js index 5bdd5e0bdf..e1f59735d7 100644 --- a/src/plugins/pdfPlayer/plugin.js +++ b/src/plugins/pdfPlayer/plugin.js @@ -304,11 +304,7 @@ export class PdfPlayer { } canPlayItem(item) { - if (item.Path && item.Path.endsWith('pdf')) { - return true; - } - - return false; + return item.Path && item.Path.endsWith('pdf'); } } diff --git a/src/scripts/browser.js b/src/scripts/browser.js index 15e5cf6627..fe0601fc97 100644 --- a/src/scripts/browser.js +++ b/src/scripts/browser.js @@ -19,25 +19,14 @@ function isTv() { return true; } - if (isWeb0s()) { - return true; - } - - return false; + return isWeb0s(); } function isWeb0s() { const userAgent = navigator.userAgent.toLowerCase(); - if (userAgent.indexOf('netcast') !== -1) { - return true; - } - - if (userAgent.indexOf('web0s') !== -1) { - return true; - } - - return false; + return userAgent.indexOf('netcast') !== -1 + || userAgent.indexOf('web0s') !== -1; } function isMobile(userAgent) { @@ -84,11 +73,7 @@ function hasKeyboard(browser) { return true; } - if (browser.tv) { - return true; - } - - return false; + return !!browser.tv; } function iOSversion() { diff --git a/src/scripts/browserDeviceProfile.js b/src/scripts/browserDeviceProfile.js index 4ea95a09da..f68faf4e40 100644 --- a/src/scripts/browserDeviceProfile.js +++ b/src/scripts/browserDeviceProfile.js @@ -53,12 +53,8 @@ import browser from './browser'; } const media = document.createElement('video'); - if (media.canPlayType('application/x-mpegURL').replace(/no/, '') || - media.canPlayType('application/vnd.apple.mpegURL').replace(/no/, '')) { - return true; - } - - return false; + return !!(media.canPlayType('application/x-mpegURL').replace(/no/, '') || + media.canPlayType('application/vnd.apple.mpegURL').replace(/no/, '')); } function canPlayHlsWithMSE() { @@ -159,11 +155,7 @@ import browser from './browser'; return true; } - if (browser.edgeUwp) { - return true; - } - - return false; + return !!browser.edgeUwp; } function testCanPlayAv1(videoTestElement) { diff --git a/src/scripts/gamepadtokey.js b/src/scripts/gamepadtokey.js index d7916f1fef..40e33a7caf 100644 --- a/src/scripts/gamepadtokey.js +++ b/src/scripts/gamepadtokey.js @@ -168,12 +168,7 @@ function throttle(key) { const time = times[key] || 0; const now = new Date().getTime(); - if ((now - time) >= 200) { - //times[key] = now; - return true; - } - - return false; + return (now - time) >= 200; } function resetThrottle(key) { @@ -187,11 +182,7 @@ function allowInput() { return false; } - if (appHost.getWindowState() === 'Minimized') { - return false; - } - - return true; + return appHost.getWindowState() !== 'Minimized'; } function raiseEvent(name, key, keyCode) { diff --git a/src/scripts/mouseManager.js b/src/scripts/mouseManager.js index b00850a022..b6ba2e3ca2 100644 --- a/src/scripts/mouseManager.js +++ b/src/scripts/mouseManager.js @@ -105,11 +105,7 @@ import dom from '../scripts/dom'; return false; } - if (browser.tv) { - return true; - } - - return false; + return !!browser.tv; } function onMouseInterval() {