Fix sonarjs no-identical-functions

This commit is contained in:
Bill Thornton 2022-10-05 15:31:15 -04:00
parent 8472112951
commit 4972f50a06
8 changed files with 45 additions and 94 deletions

View file

@ -76,7 +76,6 @@ module.exports = {
'sonarjs/cognitive-complexity': ['warn'],
// TODO: Enable the following rules and fix issues
'sonarjs/no-duplicate-string': ['off'],
'sonarjs/no-identical-functions': ['off'],
'sonarjs/no-redundant-jump': ['off'],
'sonarjs/no-small-switch': ['off'],
'sonarjs/prefer-object-literal': ['off'],

View file

@ -275,6 +275,11 @@ import '../../assets/css/scrollstyles.scss';
}
}
const getAnimationEndHandler = (dlg, callback) => function handler() {
dom.removeEventListener(dlg, dom.whichAnimationEvent(), handler, { once: true });
callback();
};
function animateDialogOpen(dlg) {
const onAnimationFinish = () => {
focusManager.pushScope(dlg);
@ -290,15 +295,11 @@ import '../../assets/css/scrollstyles.scss';
};
if (enableAnimation()) {
const onFinish = () => {
dom.removeEventListener(dlg, dom.whichAnimationEvent(), onFinish, {
once: true
});
onAnimationFinish();
};
dom.addEventListener(dlg, dom.whichAnimationEvent(), onFinish, {
once: true
});
dom.addEventListener(
dlg,
dom.whichAnimationEvent(),
getAnimationEndHandler(dlg, onAnimationFinish),
{ once: true });
return;
}
@ -324,15 +325,12 @@ import '../../assets/css/scrollstyles.scss';
animated = false;
break;
}
const onFinish = () => {
dom.removeEventListener(dlg, dom.whichAnimationEvent(), onFinish, {
once: true
});
onAnimationFinish();
};
dom.addEventListener(dlg, dom.whichAnimationEvent(), onFinish, {
once: true
});
dom.addEventListener(
dlg,
dom.whichAnimationEvent(),
getAnimationEndHandler(dlg, onAnimationFinish),
{ once: true });
if (animated) {
return;

View file

@ -24,37 +24,18 @@ function getEventsToMonitor(instance) {
return [];
}
function onTimerCreated() {
function notifyTimerRefresh() {
const instance = this;
if (getEventsToMonitor(instance).indexOf('timers') !== -1) {
instance.notifyRefreshNeeded();
return;
}
}
function onSeriesTimerCreated() {
function notifySeriesTimerRefresh() {
const instance = this;
if (getEventsToMonitor(instance).indexOf('seriestimers') !== -1) {
instance.notifyRefreshNeeded();
return;
}
}
function onTimerCancelled() {
const instance = this;
if (getEventsToMonitor(instance).indexOf('timers') !== -1) {
instance.notifyRefreshNeeded();
return;
}
}
function onSeriesTimerCancelled() {
const instance = this;
if (getEventsToMonitor(instance).indexOf('seriestimers') !== -1) {
instance.notifyRefreshNeeded();
return;
}
}
@ -125,10 +106,10 @@ class ItemsRefresher {
this.options = options || {};
addNotificationEvent(this, 'UserDataChanged', onUserDataChanged);
addNotificationEvent(this, 'TimerCreated', onTimerCreated);
addNotificationEvent(this, 'SeriesTimerCreated', onSeriesTimerCreated);
addNotificationEvent(this, 'TimerCancelled', onTimerCancelled);
addNotificationEvent(this, 'SeriesTimerCancelled', onSeriesTimerCancelled);
addNotificationEvent(this, 'TimerCreated', notifyTimerRefresh);
addNotificationEvent(this, 'SeriesTimerCreated', notifySeriesTimerRefresh);
addNotificationEvent(this, 'TimerCancelled', notifyTimerRefresh);
addNotificationEvent(this, 'SeriesTimerCancelled', notifySeriesTimerRefresh);
addNotificationEvent(this, 'LibraryChanged', onLibraryChanged);
addNotificationEvent(this, 'playbackstop', onPlaybackStopped, playbackManager);
}

View file

@ -747,14 +747,7 @@ import confirm from '../../components/confirm/confirm';
console.debug('onServerRestarting not implemented', evt, apiClient);
}
function onPackageInstalling(evt, apiClient) {
if (apiClient.serverId() === serverId) {
pollForInfo(view, apiClient);
reloadSystemInfo(view, apiClient);
}
}
function onPackageInstallationCompleted(evt, apiClient) {
function onPackageInstall(_, apiClient) {
if (apiClient.serverId() === serverId) {
pollForInfo(view, apiClient);
reloadSystemInfo(view, apiClient);
@ -786,8 +779,8 @@ import confirm from '../../components/confirm/confirm';
Events.on(serverNotifications, 'RestartRequired', onRestartRequired);
Events.on(serverNotifications, 'ServerShuttingDown', onServerShuttingDown);
Events.on(serverNotifications, 'ServerRestarting', onServerRestarting);
Events.on(serverNotifications, 'PackageInstalling', onPackageInstalling);
Events.on(serverNotifications, 'PackageInstallationCompleted', onPackageInstallationCompleted);
Events.on(serverNotifications, 'PackageInstalling', onPackageInstall);
Events.on(serverNotifications, 'PackageInstallationCompleted', onPackageInstall);
Events.on(serverNotifications, 'Sessions', onSessionsUpdate);
Events.on(serverNotifications, 'ScheduledTasksInfo', onScheduledTasksUpdate);
DashboardPage.lastAppUpdateCheck = null;
@ -824,8 +817,8 @@ import confirm from '../../components/confirm/confirm';
Events.off(serverNotifications, 'RestartRequired', onRestartRequired);
Events.off(serverNotifications, 'ServerShuttingDown', onServerShuttingDown);
Events.off(serverNotifications, 'ServerRestarting', onServerRestarting);
Events.off(serverNotifications, 'PackageInstalling', onPackageInstalling);
Events.off(serverNotifications, 'PackageInstallationCompleted', onPackageInstallationCompleted);
Events.off(serverNotifications, 'PackageInstalling', onPackageInstall);
Events.off(serverNotifications, 'PackageInstallationCompleted', onPackageInstall);
Events.off(serverNotifications, 'Sessions', onSessionsUpdate);
Events.off(serverNotifications, 'ScheduledTasksInfo', onScheduledTasksUpdate);

View file

@ -1204,17 +1204,6 @@ import { setBackdropTransparency, TRANSPARENCY_LEVEL } from '../../../components
resetIdle();
}
function onWindowTouchStart(e) {
clickedElement = e.target;
mouseIsDown = true;
resetIdle();
}
function onWindowTouchEnd() {
mouseIsDown = false;
resetIdle();
}
function onWindowDragEnd() {
// mousedown -> dragstart -> dragend !!! no mouseup :(
mouseIsDown = false;
@ -1370,12 +1359,12 @@ import { setBackdropTransparency, TRANSPARENCY_LEVEL } from '../../../components
capture: true,
passive: true
});
dom.addEventListener(window, 'touchstart', onWindowTouchStart, {
dom.addEventListener(window, 'touchstart', onWindowMouseDown, {
capture: true,
passive: true
});
['touchend', 'touchcancel'].forEach((event) => {
dom.addEventListener(window, event, onWindowTouchEnd, {
dom.addEventListener(window, event, onWindowMouseUp, {
capture: true,
passive: true
});
@ -1411,12 +1400,12 @@ import { setBackdropTransparency, TRANSPARENCY_LEVEL } from '../../../components
capture: true,
passive: true
});
dom.removeEventListener(window, 'touchstart', onWindowTouchStart, {
dom.removeEventListener(window, 'touchstart', onWindowMouseDown, {
capture: true,
passive: true
});
['touchend', 'touchcancel'].forEach((event) => {
dom.removeEventListener(window, event, onWindowTouchEnd, {
dom.removeEventListener(window, event, onWindowMouseUp, {
capture: true,
passive: true
});

View file

@ -417,10 +417,7 @@ class HtmlAudioPlayer {
// This is a retry after error
resume() {
const mediaElement = this._mediaElement;
if (mediaElement) {
mediaElement.play();
}
this.unpause();
}
unpause() {

View file

@ -1690,10 +1690,7 @@ function tryRemoveElement(elem) {
// This is a retry after error
resume() {
const mediaElement = this.#mediaElement;
if (mediaElement) {
mediaElement.play();
}
this.unpause();
}
unpause() {

View file

@ -215,19 +215,7 @@ import { getParameterByName } from '../utils/url.ts';
}
}
function onNodeOpen(event, data) {
const page = $(this).parents('.page')[0];
const node = data.node;
if (node.children) {
loadNodesToLoad(page, node);
}
if (node.li_attr && node.id != '#' && !node.li_attr.loadedFromServer) {
node.li_attr.loadedFromServer = true;
$.jstree.reference('.libraryTree', page).load_node(node.id, loadNodeCallback);
}
}
function onNodeLoad(event, data) {
function onNodeOpen(_, data) {
const page = $(this).parents('.page')[0];
const node = data.node;
if (node.children) {
@ -254,7 +242,13 @@ import { getParameterByName } from '../utils/url.ts';
variant: 'large'
}
}
}).off('select_node.jstree', onNodeSelect).on('select_node.jstree', onNodeSelect).off('open_node.jstree', onNodeOpen).on('open_node.jstree', onNodeOpen).off('load_node.jstree', onNodeLoad).on('load_node.jstree', onNodeLoad);
})
.off('select_node.jstree', onNodeSelect)
.on('select_node.jstree', onNodeSelect)
.off('open_node.jstree', onNodeOpen)
.on('open_node.jstree', onNodeOpen)
.off('load_node.jstree', onNodeOpen)
.on('load_node.jstree', onNodeOpen);
}
function loadNodesToLoad(page, node) {
@ -327,7 +321,10 @@ import { getParameterByName } from '../utils/url.ts';
});
}).on('pagebeforehide', '.metadataEditorPage', function () {
const page = this;
$('.libraryTree', page).off('select_node.jstree', onNodeSelect).off('open_node.jstree', onNodeOpen).off('load_node.jstree', onNodeLoad);
$('.libraryTree', page)
.off('select_node.jstree', onNodeSelect)
.off('open_node.jstree', onNodeOpen)
.off('load_node.jstree', onNodeOpen);
});
let itemId;
window.MetadataEditor = {