mirror of
https://github.com/MichMich/MagicMirror.git
synced 2026-07-22 14:23:51 -07:00
refactor: use const instead of let for variable declarations (#4196)
This replaces `let` with `const` for variable declarations where it was possible. Using `const` [is considered best practice](https://www.xjavascript.com/blog/in-javascript-why-should-i-usually-prefer-const-to-let/#5-best-practices-const-first-let-second). I have enabled the corresponding ESLint rule and let the ESLint auto-fix the "wrong" usages of `let`.
This commit is contained in:
committed by
GitHub
parent
3e223b7fad
commit
cdab7a7ea3
@@ -65,7 +65,7 @@ process.on("uncaughtException", function (err) {
|
||||
* @class
|
||||
*/
|
||||
function App () {
|
||||
let nodeHelpers = [];
|
||||
const nodeHelpers = [];
|
||||
let httpServer;
|
||||
let defaultModules;
|
||||
let env;
|
||||
@@ -118,7 +118,7 @@ function App () {
|
||||
Log.error(`Error when loading ${moduleName}:`, e.message);
|
||||
return;
|
||||
}
|
||||
let m = new Module();
|
||||
const m = new Module();
|
||||
|
||||
if (m.requiresVersion) {
|
||||
Log.log(`Check MagicMirror² version for node helper '${moduleName}' - Minimum version: ${m.requiresVersion} - Current version: ${global.version}`);
|
||||
@@ -146,7 +146,7 @@ function App () {
|
||||
async function loadModules (modules) {
|
||||
Log.log("Loading module helpers ...");
|
||||
|
||||
for (let module of modules) {
|
||||
for (const module of modules) {
|
||||
await loadModule(module);
|
||||
}
|
||||
|
||||
@@ -211,7 +211,7 @@ function App () {
|
||||
// get the used module positions
|
||||
Utils.getModulePositions();
|
||||
|
||||
let modules = [];
|
||||
const modules = [];
|
||||
for (const module of config.modules) {
|
||||
if (module.disabled) continue;
|
||||
if (module.module) {
|
||||
@@ -237,7 +237,7 @@ function App () {
|
||||
Log.log("Server started ...");
|
||||
|
||||
const nodePromises = [];
|
||||
for (let nodeHelper of nodeHelpers) {
|
||||
for (const nodeHelper of nodeHelpers) {
|
||||
nodeHelper.setExpressApp(app);
|
||||
nodeHelper.setSocketIO(io);
|
||||
|
||||
@@ -284,7 +284,7 @@ function App () {
|
||||
*/
|
||||
this.stop = async function () {
|
||||
const nodePromises = [];
|
||||
for (let nodeHelper of nodeHelpers) {
|
||||
for (const nodeHelper of nodeHelpers) {
|
||||
try {
|
||||
if (typeof nodeHelper.stop === "function") {
|
||||
nodePromises.push(nodeHelper.stop());
|
||||
|
||||
+2
-2
@@ -45,7 +45,7 @@ function createWindow () {
|
||||
}
|
||||
|
||||
applyElectronSwitches(app.commandLine, config.electronSwitches);
|
||||
let electronOptionsDefaults = {
|
||||
const electronOptionsDefaults = {
|
||||
width: electronSize.width,
|
||||
height: electronSize.height,
|
||||
icon: "favicon.svg",
|
||||
@@ -100,7 +100,7 @@ function createWindow () {
|
||||
prefix = "http://";
|
||||
}
|
||||
|
||||
let address = (config.address === void 0) | (config.address === "") | (config.address === "0.0.0.0") | (config.address === "::") ? (config.address = "localhost") : config.address;
|
||||
const address = (config.address === void 0) | (config.address === "") | (config.address === "0.0.0.0") | (config.address === "::") ? (config.address = "localhost") : config.address;
|
||||
const port = process.env.MM_PORT || config.port;
|
||||
mainWindow.loadURL(`${prefix}${address}:${port}`);
|
||||
|
||||
|
||||
+1
-2
@@ -196,7 +196,6 @@ function moduleNeedsUpdate (module, newHeader, newContent) {
|
||||
const headerWrapper = moduleWrapper.getElementsByClassName("module-header");
|
||||
|
||||
let headerNeedsUpdate = false;
|
||||
let contentNeedsUpdate;
|
||||
|
||||
if (headerWrapper.length > 0) {
|
||||
headerNeedsUpdate = newHeader !== headerWrapper[0].innerHTML;
|
||||
@@ -204,7 +203,7 @@ function moduleNeedsUpdate (module, newHeader, newContent) {
|
||||
|
||||
const tempContentWrapper = document.createElement("div");
|
||||
tempContentWrapper.appendChild(newContent);
|
||||
contentNeedsUpdate = tempContentWrapper.innerHTML !== contentWrapper[0].innerHTML;
|
||||
const contentNeedsUpdate = tempContentWrapper.innerHTML !== contentWrapper[0].innerHTML;
|
||||
|
||||
return headerNeedsUpdate || contentNeedsUpdate;
|
||||
}
|
||||
|
||||
+1
-1
@@ -520,7 +520,7 @@ export function cmpVersions (a, b) {
|
||||
const l = Math.min(segmentsA.length, segmentsB.length);
|
||||
|
||||
for (let i = 0; i < l; i++) {
|
||||
let diff = parseInt(segmentsA[i], 10) - parseInt(segmentsB[i], 10);
|
||||
const diff = parseInt(segmentsA[i], 10) - parseInt(segmentsB[i], 10);
|
||||
if (diff) {
|
||||
return diff;
|
||||
}
|
||||
|
||||
+1
-1
@@ -98,7 +98,7 @@ function Server (configObj) {
|
||||
});
|
||||
}
|
||||
|
||||
let directories = ["/config", "/css", "/favicon.svg", "/defaultmodules", "/modules", "/node_modules/animate.css", "/node_modules/@fontsource", "/node_modules/@fortawesome", "/node_modules/suncalc", "/translations", "/tests/configs", "/tests/mocks"];
|
||||
const directories = ["/config", "/css", "/favicon.svg", "/defaultmodules", "/modules", "/node_modules/animate.css", "/node_modules/@fontsource", "/node_modules/@fortawesome", "/node_modules/suncalc", "/translations", "/tests/configs", "/tests/mocks"];
|
||||
for (const value of Object.values(vendor)) {
|
||||
const dirArr = value.split("/");
|
||||
if (dirArr[0] === "node_modules") directories.push(`/${dirArr[0]}/${dirArr[1]}`);
|
||||
|
||||
@@ -25,7 +25,7 @@ const logSystemInformation = async () => {
|
||||
const freeRam = (os.freemem() / 1024 / 1024).toFixed(2);
|
||||
const usedRam = ((os.totalmem() - os.freemem()) / 1024 / 1024).toFixed(2);
|
||||
|
||||
let systemDataString = [
|
||||
const systemDataString = [
|
||||
"\n#### System Information ####",
|
||||
`- MM: version: v${mmVersion}${mmGitHash ? `; git: ${mmGitHash}` : ""}${mmGitBranch ? `; branch: ${mmGitBranch}` : ""}`,
|
||||
`- SYSTEM: manufacturer: ${system.manufacturer}; model: ${system.model}; virtual: ${system.virtual}`,
|
||||
|
||||
+1
-1
@@ -117,7 +117,7 @@ const Translator = (function () {
|
||||
* The first language defined in translations.js will be used.
|
||||
*/
|
||||
async loadCoreTranslationsFallback () {
|
||||
let first = Object.keys(translations)[0];
|
||||
const first = Object.keys(translations)[0];
|
||||
if (first) {
|
||||
Log.log(`[translator] Loading core translation fallback file: ${translations[first]}`);
|
||||
this.coreTranslationsFallback = await loadJSON(translations[first]);
|
||||
|
||||
+2
-2
@@ -110,7 +110,7 @@ const loadConfig = () => {
|
||||
// For this check proposed to TestSuite
|
||||
// https://forum.magicmirror.builders/topic/1456/test-suite-for-magicmirror/8
|
||||
const configFilename = getConfigFilePath();
|
||||
let templateFile = `${configFilename}.template`;
|
||||
const templateFile = `${configFilename}.template`;
|
||||
|
||||
// check if templateFile exists
|
||||
try {
|
||||
@@ -133,7 +133,7 @@ const loadConfig = () => {
|
||||
|
||||
// Load config.js and catch errors if not accessible
|
||||
try {
|
||||
let configContent = fs.readFileSync(configFilename, "utf-8");
|
||||
const configContent = fs.readFileSync(configFilename, "utf-8");
|
||||
const hideConfigSecrets = configContent.match(/^\s*hideConfigSecrets: true.*$/m);
|
||||
let configContentFull = configContent;
|
||||
let configContentRedacted = hideConfigSecrets ? configContent : undefined;
|
||||
|
||||
Reference in New Issue
Block a user