From 76ed503c8120362df6810c5554cbe5ab54122433 Mon Sep 17 00:00:00 2001 From: Bill Thornton Date: Sat, 8 Oct 2022 03:18:30 -0400 Subject: [PATCH] Fix sonarjs no-small-switch --- .eslintrc.js | 1 - src/components/htmlMediaHelper.js | 33 ++++++++----------- .../subtitleeditor/subtitleeditor.js | 8 ++--- src/controllers/livetv/livetvrecordings.js | 6 ++-- src/controllers/movies/moviesrecommended.js | 7 ++-- src/controllers/music/musicrecommended.js | 7 ++-- src/controllers/shows/tvrecommended.js | 7 ++-- src/plugins/comicsPlayer/plugin.js | 6 ++-- 8 files changed, 29 insertions(+), 46 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 0f94de8ed9..99321b951e 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -77,7 +77,6 @@ module.exports = { // TODO: Enable the following rules and fix issues 'sonarjs/no-duplicate-string': ['off'], 'sonarjs/no-redundant-jump': ['off'], - 'sonarjs/no-small-switch': ['off'], 'sonarjs/prefer-object-literal': ['off'], 'sonarjs/prefer-single-boolean-return': ['off'] }, diff --git a/src/components/htmlMediaHelper.js b/src/components/htmlMediaHelper.js index 3bb29ca912..4078cbddc0 100644 --- a/src/components/htmlMediaHelper.js +++ b/src/components/htmlMediaHelper.js @@ -273,28 +273,23 @@ import { Events } from 'jellyfin-apiclient'; hls.on(Hls.Events.ERROR, function (event, data) { console.error('HLS Error: Type: ' + data.type + ' Details: ' + (data.details || '') + ' Fatal: ' + (data.fatal || false)); - switch (data.type) { - case Hls.ErrorTypes.NETWORK_ERROR: - // try to recover network error - if (data.response && data.response.code && data.response.code >= 400) { - console.debug('hls.js response error code: ' + data.response.code); + // try to recover network error + if (data.type === Hls.ErrorTypes.NETWORK_ERROR + && data.response?.code && data.response.code >= 400 + ) { + console.debug('hls.js response error code: ' + data.response.code); - // Trigger failure differently depending on whether this is prior to start of playback, or after - hls.destroy(); + // Trigger failure differently depending on whether this is prior to start of playback, or after + hls.destroy(); - if (reject) { - reject('servererror'); - reject = null; - } else { - onErrorInternal(instance, 'servererror'); - } + if (reject) { + reject('servererror'); + reject = null; + } else { + onErrorInternal(instance, 'servererror'); + } - return; - } - - break; - default: - break; + return; } if (data.fatal) { diff --git a/src/components/subtitleeditor/subtitleeditor.js b/src/components/subtitleeditor/subtitleeditor.js index 35d4943c58..1aa6d57fc6 100644 --- a/src/components/subtitleeditor/subtitleeditor.js +++ b/src/components/subtitleeditor/subtitleeditor.js @@ -334,12 +334,8 @@ function showDownloadOptions(button, context, subtitleId) { positionTo: button }).then(function (id) { - switch (id) { - case 'download': - downloadRemoteSubtitles(context, subtitleId); - break; - default: - break; + if (id === 'download') { + downloadRemoteSubtitles(context, subtitleId); } }); }); diff --git a/src/controllers/livetv/livetvrecordings.js b/src/controllers/livetv/livetvrecordings.js index 2ce939907d..73afca81d7 100644 --- a/src/controllers/livetv/livetvrecordings.js +++ b/src/controllers/livetv/livetvrecordings.js @@ -66,11 +66,9 @@ function renderRecordingFolders(context, promise) { function onMoreClick() { const type = this.getAttribute('data-type'); - const serverId = ApiClient.serverId(); - switch (type) { - case 'latest': - Dashboard.navigate('list.html?type=Recordings&serverId=' + serverId); + if (type === 'latest') { + Dashboard.navigate('list.html?type=Recordings&serverId=' + ApiClient.serverId()); } } diff --git a/src/controllers/movies/moviesrecommended.js b/src/controllers/movies/moviesrecommended.js index a4c090bdbe..dc605ca45a 100644 --- a/src/controllers/movies/moviesrecommended.js +++ b/src/controllers/movies/moviesrecommended.js @@ -374,10 +374,9 @@ import Dashboard from '../../utils/dashboard'; } function onInputCommand(e) { - switch (e.detail.command) { - case 'search': - e.preventDefault(); - Dashboard.navigate('search.html?collectionType=movies&parentId=' + params.topParentId); + if (e.detail.command === 'search') { + e.preventDefault(); + Dashboard.navigate('search.html?collectionType=movies&parentId=' + params.topParentId); } } diff --git a/src/controllers/music/musicrecommended.js b/src/controllers/music/musicrecommended.js index d04d4bde52..7682a1241c 100644 --- a/src/controllers/music/musicrecommended.js +++ b/src/controllers/music/musicrecommended.js @@ -348,10 +348,9 @@ import Dashboard from '../../utils/dashboard'; } function onInputCommand(e) { - switch (e.detail.command) { - case 'search': - e.preventDefault(); - Dashboard.navigate('search.html?collectionType=music&parentId=' + params.topParentId); + if (e.detail.command === 'search') { + e.preventDefault(); + Dashboard.navigate('search.html?collectionType=music&parentId=' + params.topParentId); } } diff --git a/src/controllers/shows/tvrecommended.js b/src/controllers/shows/tvrecommended.js index 7dd916f6d8..671ddd12bc 100644 --- a/src/controllers/shows/tvrecommended.js +++ b/src/controllers/shows/tvrecommended.js @@ -333,10 +333,9 @@ import autoFocuser from '../../components/autoFocuser'; } function onInputCommand(e) { - switch (e.detail.command) { - case 'search': - e.preventDefault(); - Dashboard.navigate('search.html?collectionType=tv&parentId=' + params.topParentId); + if (e.detail.command === 'search') { + e.preventDefault(); + Dashboard.navigate('search.html?collectionType=tv&parentId=' + params.topParentId); } } diff --git a/src/plugins/comicsPlayer/plugin.js b/src/plugins/comicsPlayer/plugin.js index 57772d8de5..2d72abaa0b 100644 --- a/src/plugins/comicsPlayer/plugin.js +++ b/src/plugins/comicsPlayer/plugin.js @@ -172,10 +172,8 @@ export class ComicsPlayer { onWindowKeyUp(e) { const key = keyboardnavigation.getKeyName(e); - switch (key) { - case 'Escape': - this.stop(); - break; + if (key === 'Escape') { + this.stop(); } }