Avoid strings concatenation
authorJérôme Benoit <jerome.benoit@sap.com>
Mon, 23 Jan 2023 21:43:03 +0000 (22:43 +0100)
committerJérôme Benoit <jerome.benoit@sap.com>
Mon, 23 Jan 2023 21:43:03 +0000 (22:43 +0100)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/charging-station/ChargingStation.ts
src/charging-station/ChargingStationUtils.ts
src/charging-station/SharedLRUCache.ts
src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts
src/performance/PerformanceStatistics.ts
src/scripts/deleteChargingStations.js
src/scripts/setCSPublicFlag.js
src/utils/Configuration.ts
src/utils/FileUtils.ts
src/utils/Utils.ts
test/robohydra/plugins/wsServer/index.js

index 7fdc9a952e140372c44836e7b5f12107441e2805..7d66d720f1dcb6d1d7d9e862381a2ba0f4172b49 100644 (file)
@@ -1228,7 +1228,7 @@ export default class ChargingStation {
     if (stationInfo?.Connectors) {
       const connectorsConfigHash = crypto
         .createHash(Constants.DEFAULT_HASH_ALGORITHM)
-        .update(JSON.stringify(stationInfo?.Connectors) + configuredMaxConnectors.toString())
+        .update(`${JSON.stringify(stationInfo?.Connectors)}${configuredMaxConnectors.toString()}`)
         .digest('hex');
       const connectorsConfigChanged =
         this.connectors?.size !== 0 && this.connectorsConfigurationHash !== connectorsConfigHash;
index c10a3a15b229579523ad92fbf5efb679a8cf5961..426ff5c0801e4201bfd8fce0377de05bf527b3f0 100644 (file)
@@ -78,8 +78,10 @@ export class ChargingStationUtils {
     return crypto
       .createHash(Constants.DEFAULT_HASH_ALGORITHM)
       .update(
-        JSON.stringify(chargingStationInfo) +
-          ChargingStationUtils.getChargingStationId(index, stationTemplate)
+        `${JSON.stringify(chargingStationInfo)}${ChargingStationUtils.getChargingStationId(
+          index,
+          stationTemplate
+        )}`
       )
       .digest('hex');
   }
@@ -268,13 +270,13 @@ export class ChargingStationUtils {
       : '';
     stationInfo.chargePointSerialNumber =
       stationTemplate?.chargePointSerialNumberPrefix &&
-      stationTemplate.chargePointSerialNumberPrefix + serialNumberSuffix;
+      `${stationTemplate.chargePointSerialNumberPrefix}${serialNumberSuffix}`;
     stationInfo.chargeBoxSerialNumber =
       stationTemplate?.chargeBoxSerialNumberPrefix &&
-      stationTemplate.chargeBoxSerialNumberPrefix + serialNumberSuffix;
+      `${stationTemplate.chargeBoxSerialNumberPrefix}${serialNumberSuffix}`;
     stationInfo.meterSerialNumber =
       stationTemplate?.meterSerialNumberPrefix &&
-      stationTemplate.meterSerialNumberPrefix + serialNumberSuffix;
+      `${stationTemplate.meterSerialNumberPrefix}${serialNumberSuffix}`;
   }
 
   public static propagateSerialNumber(
index 048068534103ea6f5bdd5afec5940dd2753fc1dd..148175111bea63c784fa468ed7d4831f728b34ae 100644 (file)
@@ -79,11 +79,11 @@ export default class SharedLRUCache {
   }
 
   private getChargingStationConfigurationKey(hash: string): string {
-    return CacheType.CHARGING_STATION_CONFIGURATION + hash;
+    return `${CacheType.CHARGING_STATION_CONFIGURATION}${hash}`;
   }
 
   private getChargingStationTemplateKey(hash: string): string {
-    return CacheType.CHARGING_STATION_TEMPLATE + hash;
+    return `${CacheType.CHARGING_STATION_TEMPLATE}${hash}`;
   }
 
   private has(key: string): boolean {
index 6f77cde0f5afaf920cfbff7c9f72d75e878fb697..af378a47a1c6c1371642239ef7c0587ed0e85498 100644 (file)
@@ -1091,7 +1091,7 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer
               path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../../../../'),
               diagnosticsArchive
             ),
-            uri.pathname + diagnosticsArchive
+            `${uri.pathname}${diagnosticsArchive}`
           );
           if (uploadResponse.code === 226) {
             await chargingStation.ocppRequestService.requestHandler<
index ef9d393ab41b051d18266bc16f5ddefe090e7a60..49ebc79b30df23e6bea0c06818d3ad1481c0e6f7 100644 (file)
@@ -50,7 +50,7 @@ export default class PerformanceStatistics {
   }
 
   public static beginMeasure(id: string): string {
-    const markId = `${id.charAt(0).toUpperCase() + id.slice(1)}~${Utils.generateUUID()}`;
+    const markId = `${id.charAt(0).toUpperCase()}${id.slice(1)}~${Utils.generateUUID()}`;
     performance.mark(markId);
     return markId;
   }
index f92cdcf1a7ea0d9573185af3a174a7f161d7108d..4f65bdd3aef1073ecdc9f852a8b86ad5842940bb 100755 (executable)
@@ -20,7 +20,7 @@ if (config && config.mongoConnectionString) {
 
     for await (const tenantID of config.tenantIDs) {
       const response = await db
-        .collection(tenantID + '.chargingstations')
+        .collection(`${tenantID}.chargingstations`)
         .deleteMany({ _id: { $regex: config.idPattern } });
       console.info(
         response.deletedCount,
index c33647321109a51cf991c303bafd82594479922a..e591d3ba5051e8940345ccc0bc47f6cede38090a 100755 (executable)
@@ -21,7 +21,7 @@ if (config && config.mongoConnectionString) {
 
     for await (const tenantID of config.tenantIDs) {
       const response = await db
-        .collection(tenantID + '.chargingstations')
+        .collection(`${tenantID}.chargingstations`)
         .updateMany({ _id: { $regex: config.idPattern } }, { $set: { public: config.publicFlag } });
       console.info(
         response.modifiedCount,
index 9586a86879b06ea62c264932a6aa771de5f89d68..b51e8ada35fac0d2cc1c72c71ce9b4f3c1b709d5 100644 (file)
@@ -311,7 +311,7 @@ export default class Configuration {
   }
 
   private static logPrefix(): string {
-    return new Date().toLocaleString() + ' Simulator configuration |';
+    return `${new Date().toLocaleString()} Simulator configuration |`;
   }
 
   private static warnDeprecatedConfigurationKey(
@@ -421,7 +421,7 @@ export default class Configuration {
     error: NodeJS.ErrnoException,
     params: HandleErrorParams<EmptyObject> = { throwError: true }
   ): void {
-    const prefix = logPrefix.length !== 0 ? logPrefix + ' ' : '';
+    const prefix = logPrefix.trim().length !== 0 ? `${logPrefix} ` : '';
     let logMsg: string;
     switch (error.code) {
       case 'ENOENT':
index 69b5240d2ab3694fb2f7c6218c9fadf4ea9b48e9..ccee788bb99c5ac5d46623bceca00b53bb651fd2 100644 (file)
@@ -52,7 +52,7 @@ export default class FileUtils {
     error: NodeJS.ErrnoException,
     params: HandleErrorParams<EmptyObject> = { throwError: true, consoleOut: false }
   ): void {
-    const prefix = !Utils.isEmptyString(logPrefix) ? logPrefix + ' ' : '';
+    const prefix = !Utils.isEmptyString(logPrefix) ? `${logPrefix} ` : '';
     let logMsg: string;
     switch (error.code) {
       case 'ENOENT':
index 89119bc2df77181529b4de1371fbcc908c58e251..f6fe0670e0397baf6a0ec785812d9d11c79dc68f 100644 (file)
@@ -12,7 +12,7 @@ export default class Utils {
   }
 
   public static logPrefix(prefixString = ''): string {
-    return new Date().toLocaleString() + prefixString;
+    return `${new Date().toLocaleString()} ${prefixString}`;
   }
 
   public static generateUUID(): string {
index fb5e4969ed8e960f7d18da3e8440a6169647055b..dfb4268989fe05d617a9b16297d709a757ba42e4 100644 (file)
@@ -43,10 +43,10 @@ exports.getBodyParts = function (conf) {
         mountPath: '/proxy',
         proxyTo: 'ws://server.example.com',
         preProcessor: function (data) {
-          console.info('From the client: ' + data);
+          console.info(`From the client: ${data}`);
         },
         postProcessor: function (data) {
-          console.info('From the server: ' + data);
+          console.info(`From the server: ${data}`);
         },
       }),