Add no-param-reassign from eslint (#3089)

While waiting for the easterbunny I cleaned up some bad coding practice
:-)

Very open for comments especially regarding the places I commented
myself...

---------

Co-authored-by: veeck <michael@veeck.de>
This commit is contained in:
Veeck
2023-04-16 17:38:39 +02:00
committed by GitHub
parent 979f4ec664
commit 7e58b38ddf
18 changed files with 245 additions and 237 deletions

View File

@@ -205,30 +205,17 @@ function App() {
/**
* Loads all modules.
*
* @param {string[]} modules All modules to be loaded
* @param {Module[]} modules All modules to be loaded
* @returns {Promise} A promise that is resolved when all modules been loaded
*/
async function loadModules(modules) {
return new Promise((resolve) => {
Log.log("Loading module helpers ...");
Log.log("Loading module helpers ...");
/**
*
*/
function loadNextModule() {
if (modules.length > 0) {
const nextModule = modules[0];
loadModule(nextModule);
modules = modules.slice(1);
loadNextModule();
} else {
// All modules are loaded
Log.log("All module helpers loaded.");
resolve();
}
}
for (let module of modules) {
await loadModule(module);
}
loadNextModule();
});
Log.log("All module helpers loaded.");
}
/**
@@ -269,11 +256,13 @@ function App() {
Log.setLogLevel(config.logLevel);
let modules = [];
for (const module of config.modules) {
if (!modules.includes(module.module) && !module.disabled) {
modules.push(module.module);
}
}
await loadModules(modules);
httpServer = new Server(config);

View File

@@ -230,9 +230,7 @@ const MM = (function () {
* @param {Function} callback Called when the animation is done.
* @param {object} [options] Optional settings for the hide method.
*/
const hideModule = function (module, speed, callback, options) {
options = options || {};
const hideModule = function (module, speed, callback, options = {}) {
// set lockString if set in options.
if (options.lockString) {
// Log.log("Has lockstring: " + options.lockString);
@@ -277,9 +275,7 @@ const MM = (function () {
* @param {Function} callback Called when the animation is done.
* @param {object} [options] Optional settings for the show method.
*/
const showModule = function (module, speed, callback, options) {
options = options || {};
const showModule = function (module, speed, callback, options = {}) {
// remove lockString if set in options.
if (options.lockString) {
const index = module.lockStrings.indexOf(options.lockString);

View File

@@ -378,23 +378,24 @@ const Module = Class.extend({
* @param {Function} callback Called when the animation is done.
* @param {object} [options] Optional settings for the hide method.
*/
hide: function (speed, callback, options) {
if (typeof callback === "object") {
options = callback;
callback = function () {};
}
hide: function (speed, callback, options = {}) {
let usedCallback = callback || function () {};
let usedOptions = options;
callback = callback || function () {};
options = options || {};
if (typeof callback === "object") {
Log.error("Parameter mismatch in module.hide: callback is not an optional parameter!");
usedOptions = callback;
usedCallback = function () {};
}
MM.hideModule(
this,
speed,
() => {
this.suspend();
callback();
usedCallback();
},
options
usedOptions
);
},
@@ -406,22 +407,23 @@ const Module = Class.extend({
* @param {object} [options] Optional settings for the show method.
*/
show: function (speed, callback, options) {
if (typeof callback === "object") {
options = callback;
callback = function () {};
}
let usedCallback = callback || function () {};
let usedOptions = options;
callback = callback || function () {};
options = options || {};
if (typeof callback === "object") {
Log.error("Parameter mismatch in module.show: callback is not an optional parameter!");
usedOptions = callback;
usedCallback = function () {};
}
MM.showModule(
this,
speed,
() => {
this.resume();
callback();
usedCallback();
},
options
usedOptions
);
}
});

View File

@@ -44,10 +44,7 @@ const MMSocket = function (moduleName) {
notificationCallback = callback;
};
this.sendNotification = (notification, payload) => {
if (typeof payload === "undefined") {
payload = {};
}
this.sendNotification = (notification, payload = {}) => {
this.socket.emit(notification, payload);
};
};

View File

@@ -15,7 +15,7 @@ const Translator = (function () {
*/
async function loadJSON(file) {
const xhr = new XMLHttpRequest();
return new Promise(function (resolve, reject) {
return new Promise(function (resolve) {
xhr.overrideMimeType("application/json");
xhr.open("GET", file, true);
xhr.onreadystatechange = function () {
@@ -49,9 +49,7 @@ const Translator = (function () {
* @param {object} variables The variables to use within the translation template (optional)
* @returns {string} the translated key
*/
translate: function (module, key, variables) {
variables = variables || {}; // Empty object by default
translate: function (module, key, variables = {}) {
/**
* Combines template and variables like:
* template: "Please wait for {timeToWait} before continuing with {work}."
@@ -66,10 +64,11 @@ const Translator = (function () {
if (Object.prototype.toString.call(template) !== "[object String]") {
return template;
}
let templateToUse = template;
if (variables.fallback && !template.match(new RegExp("{.+}"))) {
template = variables.fallback;
templateToUse = variables.fallback;
}
return template.replace(new RegExp("{([^}]+)}", "g"), function (_unused, varName) {
return templateToUse.replace(new RegExp("{([^}]+)}", "g"), function (_unused, varName) {
return varName in variables ? variables[varName] : `{${varName}}`;
});
}