1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00

Merge pull request #4001 from thornbill/eslint-prefer-single-boolean-return

This commit is contained in:
Bill Thornton 2022-10-12 07:18:45 -04:00 committed by GitHub
commit 8d38f96ec4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 60 additions and 194 deletions

View file

@ -76,8 +76,7 @@ module.exports = {
'sonarjs/cognitive-complexity': ['warn'], 'sonarjs/cognitive-complexity': ['warn'],
// TODO: Enable the following rules and fix issues // TODO: Enable the following rules and fix issues
'sonarjs/no-duplicate-string': ['off'], 'sonarjs/no-duplicate-string': ['off'],
'sonarjs/prefer-object-literal': ['off'], 'sonarjs/prefer-object-literal': ['off']
'sonarjs/prefer-single-boolean-return': ['off']
}, },
settings: { settings: {
react: { react: {

View file

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

View file

@ -10,24 +10,13 @@ import './backdrop.scss';
/* eslint-disable indent */ /* eslint-disable indent */
function enableAnimation() { function enableAnimation() {
if (browser.slow) { return !browser.slow;
return false;
}
return true;
} }
function enableRotation() { function enableRotation() {
if (browser.tv) { return !browser.tv
return false; // Causes high cpu usage
} && !browser.firefox;
// Causes high cpu usage
if (browser.firefox) {
return false;
}
return true;
} }
class Backdrop { class Backdrop {

View file

@ -56,15 +56,8 @@ import scrollManager from './scrollManager';
}).join(',') + ',.focusable'; }).join(',') + ',.focusable';
function isFocusable(elem) { function isFocusable(elem) {
if (focusableTagNames.indexOf(elem.tagName) !== -1) { return focusableTagNames.indexOf(elem.tagName) !== -1
return true; || (elem.classList?.contains('focusable'));
}
if (elem.classList && elem.classList.contains('focusable')) {
return true;
}
return false;
} }
function normalizeFocusable(elem, originalElement) { 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 // Determines if a focusable element can be focused at a given point in time
function isCurrentlyFocusableInternal(elem) { function isCurrentlyFocusableInternal(elem) {
// http://stackoverflow.com/questions/19669786/check-if-element-is-visible-in-dom // http://stackoverflow.com/questions/19669786/check-if-element-is-visible-in-dom
if (elem.offsetParent === null) { return elem.offsetParent !== null;
return false;
}
return true;
} }
// Determines if a focusable element can be focused at a given point in time // 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() { function canPlayNativeHls() {
const media = document.createElement('video'); const media = document.createElement('video');
if (media.canPlayType('application/x-mpegURL').replace(/no/, '') || return !!(media.canPlayType('application/x-mpegURL').replace(/no/, '') ||
media.canPlayType('application/vnd.apple.mpegURL').replace(/no/, '')) { media.canPlayType('application/vnd.apple.mpegURL').replace(/no/, ''));
return true;
}
return false;
} }
export function enableHlsJsPlayer(runTimeTicks, mediaType) { export function enableHlsJsPlayer(runTimeTicks, mediaType) {
@ -123,11 +119,10 @@ import { Events } from 'jellyfin-apiclient';
} }
export function isValidDuration(duration) { export function isValidDuration(duration) {
if (duration && !isNaN(duration) && duration !== Number.POSITIVE_INFINITY && duration !== Number.NEGATIVE_INFINITY) { return duration
return true; && !isNaN(duration)
} && duration !== Number.POSITIVE_INFINITY
&& duration !== Number.NEGATIVE_INFINITY;
return false;
} }
function setCurrentTimeIfNeeded(element, seconds) { function setCurrentTimeIfNeeded(element, seconds) {

View file

@ -5,15 +5,9 @@ import './indicators.scss';
import 'material-design-icons-iconfont'; import 'material-design-icons-iconfont';
export function enableProgressIndicator(item) { export function enableProgressIndicator(item) {
if (item.MediaType === 'Video' && item.Type !== 'TvChannel') { return (item.MediaType === 'Video' && item.Type !== 'TvChannel')
return true; || item.Type === 'AudioBook'
} || item.Type === 'AudioPodcast';
if (item.Type === 'AudioBook' || item.Type === 'AudioPodcast') {
return true;
}
return false;
} }
export function getProgressHtml(pct, options) { export function getProgressHtml(pct, options) {

View file

@ -117,11 +117,7 @@ export function canEdit(user, item) {
} }
export function isLocalItem(item) { export function isLocalItem(item) {
if (item && item.Id && typeof item.Id === 'string' && item.Id.indexOf('local') === 0) { return item && item.Id && typeof item.Id === 'string' && item.Id.indexOf('local') === 0;
return true;
}
return false;
} }
export function canIdentify (user, item) { export function canIdentify (user, item) {
@ -148,11 +144,7 @@ export function canEditImages (user, item) {
} }
if (itemType === 'UserView') { if (itemType === 'UserView') {
if (user.Policy.IsAdministrator) { return !!user.Policy.IsAdministrator;
return true;
}
return false;
} }
if (item.Type === 'Recording' && item.Status !== 'Completed') { if (item.Type === 'Recording' && item.Status !== 'Completed') {
@ -218,29 +210,21 @@ export function canMarkPlayed (item) {
} }
} }
if (item.Type === 'Series' || return item.Type === 'Series'
item.Type === 'Season' || || item.Type === 'Season'
item.Type === 'BoxSet' || || item.Type === 'BoxSet'
item.MediaType === 'Book' || || item.MediaType === 'Book'
item.MediaType === 'Recording') { || item.MediaType === 'Recording';
return true;
}
return false;
} }
export function canRate (item) { export function canRate (item) {
if (item.Type === 'Program' return item.Type !== 'Program'
|| item.Type === 'Timer' && item.Type !== 'Timer'
|| item.Type === 'SeriesTimer' && item.Type !== 'SeriesTimer'
|| item.Type === 'CollectionFolder' && item.Type !== 'CollectionFolder'
|| item.Type === 'UserView' && item.Type !== 'UserView'
|| item.Type === 'Channel' && item.Type !== 'Channel'
|| !item.UserData) { && item.UserData;
return false;
}
return true;
} }
export function canConvert (item, user) { export function canConvert (item, user) {
@ -271,11 +255,7 @@ export function canConvert (item, user) {
return false; return false;
} }
if (item.IsPlaceHolder) { return !item.IsPlaceHolder;
return false;
}
return true;
} }
export function canRefreshMetadata (item, user) { export function canRefreshMetadata (item, user) {
@ -304,14 +284,12 @@ export function supportsMediaSourceSelection (item) {
if (!item.MediaSources || (item.MediaSources.length === 1 && item.MediaSources[0].Type === 'Placeholder')) { if (!item.MediaSources || (item.MediaSources.length === 1 && item.MediaSources[0].Type === 'Placeholder')) {
return false; return false;
} }
if (item.EnableMediaSourceDisplay === false) {
return false; if (item.EnableMediaSourceDisplay != null) {
} return !!item.EnableMediaSourceDisplay;
if (item.EnableMediaSourceDisplay == null && item.SourceType && item.SourceType !== 'Library') {
return false;
} }
return true; return !item.SourceType || item.SourceType === 'Library';
} }
export function sortTracks (trackA, trackB) { export function sortTracks (trackA, trackB) {

View file

@ -19,11 +19,7 @@ function enableLocalPlaylistManagement(player) {
return false; return false;
} }
if (player.isLocalPlayer) { return player.isLocalPlayer;
return true;
}
return false;
} }
function bindToFullscreenChange(player) { function bindToFullscreenChange(player) {
@ -225,11 +221,7 @@ function getParam(name, url) {
} }
function isAutomaticPlayer(player) { function isAutomaticPlayer(player) {
if (player.isLocalPlayer) { return player.isLocalPlayer;
return true;
}
return false;
} }
function getAutomaticPlayers(instance, forceLocalPlayer) { function getAutomaticPlayers(instance, forceLocalPlayer) {
@ -244,10 +236,7 @@ function getAutomaticPlayers(instance, forceLocalPlayer) {
} }
function isServerItem(item) { function isServerItem(item) {
if (!item.Id) { return !!item.Id;
return false;
}
return true;
} }
function enableIntros(item) { function enableIntros(item) {
@ -3007,11 +2996,8 @@ class PlaybackManager {
function enablePlaybackRetryWithTranscoding(streamInfo, errorType, currentlyPreventsVideoStreamCopy, currentlyPreventsAudioStreamCopy) { function enablePlaybackRetryWithTranscoding(streamInfo, errorType, currentlyPreventsVideoStreamCopy, currentlyPreventsAudioStreamCopy) {
// mediadecodeerror, medianotsupported, network, servererror // mediadecodeerror, medianotsupported, network, servererror
if (streamInfo.mediaSource.SupportsTranscoding && (!currentlyPreventsVideoStreamCopy || !currentlyPreventsAudioStreamCopy)) { return streamInfo.mediaSource.SupportsTranscoding
return true; && (!currentlyPreventsVideoStreamCopy || !currentlyPreventsAudioStreamCopy);
}
return false;
} }
function onPlaybackError(e, error) { function onPlaybackError(e, error) {

View file

@ -479,11 +479,7 @@ import layoutManager from './layoutManager';
* Returns true if smooth scroll must be used. * Returns true if smooth scroll must be used.
*/ */
function useSmoothScroll() { function useSmoothScroll() {
if (browser.tizen) { return !!browser.tizen;
return true;
}
return false;
} }
/** /**

View file

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

View file

@ -339,11 +339,7 @@ export class BookPlayer {
} }
canPlayItem(item) { canPlayItem(item) {
if (item.Path && item.Path.endsWith('epub')) { return item.Path && item.Path.endsWith('epub');
return true;
}
return false;
} }
} }

View file

@ -356,11 +356,7 @@ export class ComicsPlayer {
} }
canPlayItem(item) { canPlayItem(item) {
if (item.Path && (item.Path.endsWith('cbz') || item.Path.endsWith('cbr'))) { return item.Path && (item.Path.endsWith('cbz') || item.Path.endsWith('cbr'));
return true;
}
return false;
} }
} }

View file

@ -41,13 +41,9 @@ function cancelFadeTimeout() {
} }
function supportsFade() { function supportsFade() {
if (browser.tv) { // Not working on tizen.
// Not working on tizen. // We could possibly enable on other tv's, but all smart tv browsers tend to be pretty primitive
// We could possibly enable on other tv's, but all smart tv browsers tend to be pretty primitive return !browser.tv;
return false;
}
return true;
} }
function requireHlsPlayer(callback) { function requireHlsPlayer(callback) {

View file

@ -304,11 +304,7 @@ export class PdfPlayer {
} }
canPlayItem(item) { canPlayItem(item) {
if (item.Path && item.Path.endsWith('pdf')) { return item.Path && item.Path.endsWith('pdf');
return true;
}
return false;
} }
} }

View file

@ -19,25 +19,14 @@ function isTv() {
return true; return true;
} }
if (isWeb0s()) { return isWeb0s();
return true;
}
return false;
} }
function isWeb0s() { function isWeb0s() {
const userAgent = navigator.userAgent.toLowerCase(); const userAgent = navigator.userAgent.toLowerCase();
if (userAgent.indexOf('netcast') !== -1) { return userAgent.indexOf('netcast') !== -1
return true; || userAgent.indexOf('web0s') !== -1;
}
if (userAgent.indexOf('web0s') !== -1) {
return true;
}
return false;
} }
function isMobile(userAgent) { function isMobile(userAgent) {
@ -84,11 +73,7 @@ function hasKeyboard(browser) {
return true; return true;
} }
if (browser.tv) { return !!browser.tv;
return true;
}
return false;
} }
function iOSversion() { function iOSversion() {

View file

@ -53,12 +53,8 @@ import browser from './browser';
} }
const media = document.createElement('video'); const media = document.createElement('video');
if (media.canPlayType('application/x-mpegURL').replace(/no/, '') || return !!(media.canPlayType('application/x-mpegURL').replace(/no/, '') ||
media.canPlayType('application/vnd.apple.mpegURL').replace(/no/, '')) { media.canPlayType('application/vnd.apple.mpegURL').replace(/no/, ''));
return true;
}
return false;
} }
function canPlayHlsWithMSE() { function canPlayHlsWithMSE() {
@ -159,11 +155,7 @@ import browser from './browser';
return true; return true;
} }
if (browser.edgeUwp) { return !!browser.edgeUwp;
return true;
}
return false;
} }
function testCanPlayAv1(videoTestElement) { function testCanPlayAv1(videoTestElement) {

View file

@ -168,12 +168,7 @@ function throttle(key) {
const time = times[key] || 0; const time = times[key] || 0;
const now = new Date().getTime(); const now = new Date().getTime();
if ((now - time) >= 200) { return (now - time) >= 200;
//times[key] = now;
return true;
}
return false;
} }
function resetThrottle(key) { function resetThrottle(key) {
@ -187,11 +182,7 @@ function allowInput() {
return false; return false;
} }
if (appHost.getWindowState() === 'Minimized') { return appHost.getWindowState() !== 'Minimized';
return false;
}
return true;
} }
function raiseEvent(name, key, keyCode) { function raiseEvent(name, key, keyCode) {

View file

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