Use template literals instead of string concatenation (#3066)

We have used it inconsistently till now. Template literals are more
modern and easier to maintain in my opinion.

Because that's a large amount of changes, here's a way to reproduce it:
I added the rule `"prefer-template": "error"` to the `.eslintrc.json`
and did an autofix. Since this caused a new problem in line 409 of
`newsfeed.js`, I reversed it in that line and also removed the rule from
the eslint config file.

The rule is described here:
https://eslint.org/docs/latest/rules/prefer-template

Note: I've played around with some other linter rules as well, and some
seem to point to some specific, non-cosmetic, issues. But before I dive
even deeper and then introduce even bigger and hardly understandable
changes at once, I thought I'd start with this simple cosmetic rule.
This commit is contained in:
Kristjan ESPERANTO
2023-03-19 14:32:23 +01:00
committed by GitHub
parent 8f8945d418
commit d276a7ddb9
45 changed files with 222 additions and 237 deletions

View File

@@ -18,7 +18,7 @@ const envsub = require("envsub");
// Get version number.
global.version = require(`${__dirname}/../package.json`).version;
Log.log("Starting MagicMirror: v" + global.version);
Log.log(`Starting MagicMirror: v${global.version}`);
// global absolute root path
global.root_path = path.resolve(`${__dirname}/../`);
@@ -64,7 +64,7 @@ function App() {
// For this check proposed to TestSuite
// https://forum.magicmirror.builders/topic/1456/test-suite-for-magicmirror/8
const configFilename = path.resolve(global.configuration_file || `${global.root_path}/config/config.js`);
let templateFile = configFilename + ".template";
let templateFile = `${configFilename}.template`;
// check if templateFile exists
try {
@@ -78,21 +78,21 @@ function App() {
// save current config.js
try {
if (fs.existsSync(configFilename)) {
fs.copyFileSync(configFilename, configFilename + "_" + Date.now());
fs.copyFileSync(configFilename, `${configFilename}_${Date.now()}`);
}
} catch (err) {
Log.warn("Could not copy " + configFilename + ": " + err.message);
Log.warn(`Could not copy ${configFilename}: ${err.message}`);
}
// check if config.env exists
const envFiles = [];
const configEnvFile = configFilename.substr(0, configFilename.lastIndexOf(".")) + ".env";
const configEnvFile = `${configFilename.substr(0, configFilename.lastIndexOf("."))}.env`;
try {
if (fs.existsSync(configEnvFile)) {
envFiles.push(configEnvFile);
}
} catch (err) {
Log.debug(configEnvFile + " does not exist. " + err.message);
Log.debug(`${configEnvFile} does not exist. ${err.message}`);
}
let options = {
@@ -110,7 +110,7 @@ function App() {
try {
await envsub({ templateFile, outputFile, options });
} catch (err) {
Log.error("Could not envsubst variables: " + err.message);
Log.error(`Could not envsubst variables: ${err.message}`);
}
}