Fix sonarjs prefer-single-boolean-return

This commit is contained in:
Bill Thornton 2022-10-06 01:13:06 -04:00
parent bb86ab7f27
commit b426b6e2bf
18 changed files with 52 additions and 187 deletions

View File

@ -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: {

View File

@ -166,11 +166,7 @@ function supportsHtmlMediaAutoplay() {
return true;
}
if (browser.mobile) {
return false;
}
return true;
return !!browser.mobile;
}
function supportsCue() {

View File

@ -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 {

View File

@ -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

View File

@ -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) {

View File

@ -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) {

View File

@ -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) {

View File

@ -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) {

View File

@ -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;
}
/**

View File

@ -23,11 +23,7 @@ import 'webcomponents.js/webcomponents-lite';
return true;
}
if (layoutManager.tv) {
return false;
}
return true;
return !layoutManager.tv;
}
function triggerChange(select) {

View File

@ -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');
}
}

View File

@ -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'));
}
}

View File

@ -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) {

View File

@ -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');
}
}

View File

@ -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() {

View File

@ -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) {

View File

@ -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) {

View File

@ -105,11 +105,7 @@ import dom from '../scripts/dom';
return false;
}
if (browser.tv) {
return true;
}
return false;
return !!browser.tv;
}
function onMouseInterval() {