Refine code formatting rules
authorJérôme Benoit <jerome.benoit@sap.com>
Wed, 25 Jan 2023 11:40:12 +0000 (12:40 +0100)
committerJérôme Benoit <jerome.benoit@sap.com>
Wed, 25 Jan 2023 11:40:12 +0000 (12:40 +0100)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
17 files changed:
.eslintrc.json
.prettierrc.json
src/charging-station/ChargingStation.ts
src/charging-station/ChargingStationConfigurationUtils.ts
src/charging-station/UIServiceWorkerBroadcastChannel.ts
src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts
src/charging-station/ocpp/OCPPRequestService.ts
src/charging-station/ui-server/UIHttpServer.ts
src/charging-station/ui-server/UIWebSocketServer.ts
src/charging-station/ui-server/ui-services/AbstractUIService.ts
src/performance/PerformanceStatistics.ts
src/performance/storage/JsonFileStorage.ts
src/start.ts
src/utils/Configuration.ts
src/utils/Utils.ts
src/worker/WorkerSet.ts
ui/web/src/composables/UIClient.ts

index 27d9f65b987d51ed54c8de4c94c58c633655ffdd..8b10dc67bc7b4f510e918775b1fe6fdbbc3c23e2 100644 (file)
@@ -85,7 +85,7 @@
     "spaced-comment": ["error", "always"],
     "switch-colon-spacing": "error",
     "arrow-body-style": ["error", "as-needed"],
-    "arrow-parens": ["error", "always"],
+    "arrow-parens": ["error", "as-needed"],
     "arrow-spacing": "error",
     "no-duplicate-imports": "error",
     "no-var": "error",
index 5ac85e271d543cf99a88eddb0cd368c1002ca629..ef4fe83fdb37f2f48f424215683b4d32898832bc 100644 (file)
@@ -1,4 +1,5 @@
 {
   "printWidth": 100,
+  "arrowParens": "avoid",
   "singleQuote": true
 }
index 7d66d720f1dcb6d1d7d9e862381a2ba0f4172b49..acee101d61af0b8e2e6bfa636cc0037de0080bea 100644 (file)
@@ -386,7 +386,7 @@ export default class ChargingStation {
       this.heartbeatSetInterval = setInterval(() => {
         this.ocppRequestService
           .requestHandler<HeartbeatRequest, HeartbeatResponse>(this, RequestCommand.HEARTBEAT)
-          .catch((error) => {
+          .catch(error => {
             logger.error(
               `${this.logPrefix()} Error while sending '${RequestCommand.HEARTBEAT}':`,
               error
@@ -475,7 +475,7 @@ export default class ChargingStation {
               meterValue: [meterValue],
             }
           )
-          .catch((error) => {
+          .catch(error => {
             logger.error(
               `${this.logPrefix()} Error while sending '${RequestCommand.METER_VALUES}':`,
               error
@@ -767,7 +767,7 @@ export default class ChargingStation {
 
   private flushMessageBuffer(): void {
     if (this.messageBuffer.size > 0) {
-      this.messageBuffer.forEach((message) => {
+      this.messageBuffer.forEach(message => {
         let beginId: string;
         let commandName: RequestCommand;
         const [messageType] = JSON.parse(message) as OutgoingRequest | Response | ErrorResponse;
index bfd9838bad3045bc66f1999279aa1fd376580dcc..4e0d55cc07015914dab423f4b4768e75cde8994e 100644 (file)
@@ -17,7 +17,7 @@ export class ChargingStationConfigurationUtils {
     key: string | StandardParametersKey,
     caseInsensitive = false
   ): ConfigurationKey | undefined {
-    return chargingStation.ocppConfiguration.configurationKey.find((configElement) => {
+    return chargingStation.ocppConfiguration.configurationKey.find(configElement => {
       if (caseInsensitive) {
         return configElement.key.toLowerCase() === key.toLowerCase();
       }
index cdbe108df333e9f6b6388f91e5327be60a8a3821..fa9236abad6f478c6fa043c3bf611248b2c27820 100644 (file)
@@ -74,7 +74,7 @@ export default class UIServiceWorkerBroadcastChannel extends WorkerBroadcastChan
             return hashId;
           }
         })
-        .filter((hashId) => hashId !== undefined),
+        .filter(hashId => hashId !== undefined),
       ...(responsesStatus === ResponseStatus.FAILURE && {
         hashIdsFailed: this.responses
           .get(uuid)
@@ -83,17 +83,17 @@ export default class UIServiceWorkerBroadcastChannel extends WorkerBroadcastChan
               return hashId;
             }
           })
-          .filter((hashId) => hashId !== undefined),
+          .filter(hashId => hashId !== undefined),
       }),
       ...(responsesStatus === ResponseStatus.FAILURE && {
         responsesFailed: this.responses
           .get(uuid)
-          ?.responses.map((response) => {
+          ?.responses.map(response => {
             if (response.status === ResponseStatus.FAILURE) {
               return response;
             }
           })
-          .filter((response) => response !== undefined),
+          .filter(response => response !== undefined),
       }),
     };
   }
index af378a47a1c6c1371642239ef7c0587ed0e85498..4deabe4f0a099157b1ea7b77020547b8f350a007 100644 (file)
@@ -718,7 +718,7 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer
               .getAuthorizedTags(
                 ChargingStationUtils.getAuthorizationFile(chargingStation.stationInfo)
               )
-              .find((idTag) => idTag === commandPayload.idTag)
+              .find(idTag => idTag === commandPayload.idTag)
           ) {
             connectorStatus.localAuthorizeIdTag = commandPayload.idTag;
             connectorStatus.idTagLocalAuthorized = true;
@@ -1051,8 +1051,8 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer
       try {
         const logFiles = fs
           .readdirSync(path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../../../../'))
-          .filter((file) => file.endsWith('.log'))
-          .map((file) => path.join('./', file));
+          .filter(file => file.endsWith('.log'))
+          .map(file => path.join('./', file));
         const diagnosticsArchive = `${chargingStation.stationInfo.chargingStationId}_logs.tar.gz`;
         tar.create({ gzip: true }, logFiles).pipe(fs.createWriteStream(diagnosticsArchive));
         ftpClient = new Client();
@@ -1064,7 +1064,7 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer
         });
         let uploadResponse: FTPResponse;
         if (accessResponse.code === 220) {
-          ftpClient.trackProgress((info) => {
+          ftpClient.trackProgress(info => {
             logger.info(
               `${chargingStation.logPrefix()} ${
                 info.bytes / 1024
@@ -1077,7 +1077,7 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer
               >(chargingStation, OCPP16RequestCommand.DIAGNOSTICS_STATUS_NOTIFICATION, {
                 status: OCPP16DiagnosticsStatus.Uploading,
               })
-              .catch((error) => {
+              .catch(error => {
                 logger.error(
                   `${chargingStation.logPrefix()} ${moduleName}.handleRequestGetDiagnostics: Error while sending '${
                     OCPP16RequestCommand.DIAGNOSTICS_STATUS_NOTIFICATION
@@ -1190,7 +1190,7 @@ export default class OCPP16IncomingRequestService extends OCPPIncomingRequestSer
                 chargingStation.bootNotificationRequest,
                 { skipBufferingOnError: true, triggerMessage: true }
               )
-              .then((response) => {
+              .then(response => {
                 chargingStation.bootNotificationResponse = response;
               })
               .catch(() => {
index 13cb170789f502fce73c4e6847b9e45f12fad6da..dbf478ece1252a803c618929d05460f87313129d 100644 (file)
@@ -322,7 +322,7 @@ export default abstract class OCPPRequestService {
               .then(() => {
                 resolve(payload);
               })
-              .catch((error) => {
+              .catch(error => {
                 reject(error);
               })
               .finally(() => {
index 87f10a5eab41ef30ce19d0dd5211320900d9697e..da347672df86af76f8c1ce314410161b33e01b89 100644 (file)
@@ -68,7 +68,7 @@ export default class UIHttpServer extends AbstractUIServer {
   }
 
   private requestListener(req: IncomingMessage, res: ServerResponse): void {
-    this.authenticate(req, (err) => {
+    this.authenticate(req, err => {
       if (err) {
         res
           .writeHead(StatusCodes.UNAUTHORIZED, {
@@ -94,7 +94,7 @@ export default class UIHttpServer extends AbstractUIServer {
         throw new BaseError(`Unsupported UI protocol version: '${fullProtocol}'`);
       }
       this.registerProtocolVersionUIService(version);
-      req.on('error', (error) => {
+      req.on('error', error => {
         logger.error(
           `${this.logPrefix(moduleName, 'requestListener.req.onerror')} Error on HTTP request:`,
           error
@@ -103,7 +103,7 @@ export default class UIHttpServer extends AbstractUIServer {
       if (req.method === 'POST') {
         const bodyBuffer = [];
         req
-          .on('data', (chunk) => {
+          .on('data', chunk => {
             bodyBuffer.push(chunk);
           })
           .on('end', () => {
index e217305f2e1e42f9644ad25f1467aceab57fa12b..006c3914b8a67f6c7368345c8b747631698cdcbe 100644 (file)
@@ -39,7 +39,7 @@ export default class UIWebSocketServer extends AbstractUIServer {
       }
       const [, version] = UIServerUtils.getProtocolAndVersion(ws.protocol);
       this.registerProtocolVersionUIService(version);
-      ws.on('message', (rawData) => {
+      ws.on('message', rawData => {
         const request = this.validateRawDataRequest(rawData);
         if (request === false) {
           ws.close(WebSocketCloseEventStatusCode.CLOSE_INVALID_PAYLOAD);
@@ -54,7 +54,7 @@ export default class UIWebSocketServer extends AbstractUIServer {
             /* Error caught by AbstractUIService */
           });
       });
-      ws.on('error', (error) => {
+      ws.on('error', error => {
         logger.error(`${this.logPrefix(moduleName, 'start.ws.onerror')} WebSocket error:`, error);
       });
       ws.on('close', (code, reason) => {
@@ -78,7 +78,7 @@ export default class UIWebSocketServer extends AbstractUIServer {
     this.httpServer.on(
       'upgrade',
       (req: IncomingMessage, socket: internal.Duplex, head: Buffer): void => {
-        this.authenticate(req, (err) => {
+        this.authenticate(req, err => {
           if (err) {
             socket.write(`HTTP/1.1 ${StatusCodes.UNAUTHORIZED} Unauthorized\r\n\r\n`);
             socket.destroy();
index 5a418b9d4baf53cc3032efee92e808971da58626..2b1267f35fd40b4584f29d87379782ebe3d419b7 100644 (file)
@@ -156,7 +156,7 @@ export default abstract class AbstractUIService {
   ): void {
     if (!Utils.isEmptyArray(payload.hashIds)) {
       payload.hashIds = payload.hashIds
-        .map((hashId) => {
+        .map(hashId => {
           if (this.uiServer.chargingStations.has(hashId) === true) {
             return hashId;
           }
@@ -167,7 +167,7 @@ export default abstract class AbstractUIService {
             )} Charging station with hashId '${hashId}' not found`
           );
         })
-        .filter((hashId) => hashId !== undefined);
+        .filter(hashId => hashId !== undefined);
     }
     const expectedNumberOfResponses = !Utils.isEmptyArray(payload.hashIds)
       ? payload.hashIds.length
index 49ebc79b30df23e6bea0c06818d3ad1481c0e6f7..6c0ff042264d12196ebb6cd1ca8d2f8544030b64 100644 (file)
@@ -138,7 +138,7 @@ export default class PerformanceStatistics {
   }
 
   private initializePerformanceObserver(): void {
-    this.performanceObserver = new PerformanceObserver((performanceObserverList) => {
+    this.performanceObserver = new PerformanceObserver(performanceObserverList => {
       const lastPerformanceEntry = performanceObserverList.getEntries()[0];
       // logger.debug(
       //   `${this.logPrefix()} '${lastPerformanceEntry.name}' performance entry: %j`,
@@ -287,7 +287,7 @@ export default class PerformanceStatistics {
   }
 
   private extractTimeSeriesValues(timeSeries: CircularArray<TimeSeries>): number[] {
-    return timeSeries.map((timeSeriesItem) => timeSeriesItem.value);
+    return timeSeries.map(timeSeriesItem => timeSeriesItem.value);
   }
 
   private logPrefix(): string {
index 63d12a439a0aa6a54283b4717ce93ce0e1ba596a..94c36eddac1ea5012d81d22d314f52dfa8edc12f 100644 (file)
@@ -22,7 +22,7 @@ export class JsonFileStorage extends Storage {
     this.checkPerformanceRecordsFile();
     lockfile
       .lock(this.dbName, { stale: 5000, retries: 3 })
-      .then(async (release) => {
+      .then(async release => {
         try {
           const fileData = fs.readFileSync(this.dbName, 'utf8');
           const performanceRecords: Statistics[] = fileData
index 8eca3a4a11e093983b7ab8f499b2c6406175a2fa..a21f7fcf07b59c80e341c1f864b3124d74d4ce31 100644 (file)
@@ -6,6 +6,6 @@ import { Bootstrap } from './internal';
 
 Bootstrap.getInstance()
   .start()
-  .catch((error) => {
+  .catch(error => {
     console.error(chalk.red(error));
   });
index b51e8ada35fac0d2cc1c72c71ce9b4f3c1b709d5..03789f154c01371d9d668237ef7128d48a282fe6 100644 (file)
@@ -369,7 +369,7 @@ export default class Configuration {
           // Nullify to force configuration file reading
           Configuration.configuration = null;
           if (!Configuration.isUndefined(Configuration.configurationChangeCallback)) {
-            Configuration.configurationChangeCallback().catch((error) => {
+            Configuration.configurationChangeCallback().catch(error => {
               throw typeof error === 'string' ? new Error(error) : error;
             });
           }
index ca8f44af23d44ed91b15047428787edccdb0a9db..4a9bdb709a2ab8c530a18e2aaa4b41a2d452342c 100644 (file)
@@ -26,7 +26,7 @@ export default class Utils {
   }
 
   public static async sleep(milliSeconds: number): Promise<NodeJS.Timeout> {
-    return new Promise((resolve) => setTimeout(resolve as () => void, milliSeconds));
+    return new Promise(resolve => setTimeout(resolve as () => void, milliSeconds));
   }
 
   public static formatDurationMilliSeconds(duration: number): string {
index c82e79fcfb81a41f795b34617f7b0cb5658072b4..76d759a2c33ee7d21b553179ab479e6ffecb38cd 100644 (file)
@@ -98,7 +98,7 @@ export default class WorkerSet extends WorkerAbstract<WorkerData> {
       ).bind(this) as MessageHandler<Worker>
     );
     worker.on('error', WorkerUtils.defaultErrorHandler.bind(this) as (err: Error) => void);
-    worker.on('exit', (code) => {
+    worker.on('exit', code => {
       WorkerUtils.defaultExitHandler(code);
       this.workerSet.delete(this.getWorkerSetElementByWorker(worker));
     });
index e78836fd51b7b18cdefa36b3f73c5a94e76ca191..056e2ce27cef9ddfb051ece83ee2266acc66339d 100644 (file)
@@ -112,10 +112,10 @@ export default class UIClient {
       config.uiServer.protocol
     );
     this._ws.onmessage = this.responseHandler.bind(this);
-    this._ws.onerror = (errorEvent) => {
+    this._ws.onerror = errorEvent => {
       console.error('WebSocket error: ', errorEvent);
     };
-    this._ws.onclose = (closeEvent) => {
+    this._ws.onclose = closeEvent => {
       console.info('WebSocket closed: ', closeEvent);
     };
   }