From: Jérôme Benoit Date: Wed, 25 Jan 2023 11:40:12 +0000 (+0100) Subject: Refine code formatting rules X-Git-Tag: v1.1.92~20 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=8475b2228f0b36777e1a9528b2d61348facad82f;p=e-mobility-charging-stations-simulator.git Refine code formatting rules Signed-off-by: Jérôme Benoit --- diff --git a/.eslintrc.json b/.eslintrc.json index 27d9f65b..8b10dc67 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -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", diff --git a/.prettierrc.json b/.prettierrc.json index 5ac85e27..ef4fe83f 100644 --- a/.prettierrc.json +++ b/.prettierrc.json @@ -1,4 +1,5 @@ { "printWidth": 100, + "arrowParens": "avoid", "singleQuote": true } diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index 7d66d720..acee101d 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -386,7 +386,7 @@ export default class ChargingStation { this.heartbeatSetInterval = setInterval(() => { this.ocppRequestService .requestHandler(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; diff --git a/src/charging-station/ChargingStationConfigurationUtils.ts b/src/charging-station/ChargingStationConfigurationUtils.ts index bfd9838b..4e0d55cc 100644 --- a/src/charging-station/ChargingStationConfigurationUtils.ts +++ b/src/charging-station/ChargingStationConfigurationUtils.ts @@ -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(); } diff --git a/src/charging-station/UIServiceWorkerBroadcastChannel.ts b/src/charging-station/UIServiceWorkerBroadcastChannel.ts index cdbe108d..fa9236ab 100644 --- a/src/charging-station/UIServiceWorkerBroadcastChannel.ts +++ b/src/charging-station/UIServiceWorkerBroadcastChannel.ts @@ -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), }), }; } diff --git a/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts b/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts index af378a47..4deabe4f 100644 --- a/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts +++ b/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts @@ -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(() => { diff --git a/src/charging-station/ocpp/OCPPRequestService.ts b/src/charging-station/ocpp/OCPPRequestService.ts index 13cb1707..dbf478ec 100644 --- a/src/charging-station/ocpp/OCPPRequestService.ts +++ b/src/charging-station/ocpp/OCPPRequestService.ts @@ -322,7 +322,7 @@ export default abstract class OCPPRequestService { .then(() => { resolve(payload); }) - .catch((error) => { + .catch(error => { reject(error); }) .finally(() => { diff --git a/src/charging-station/ui-server/UIHttpServer.ts b/src/charging-station/ui-server/UIHttpServer.ts index 87f10a5e..da347672 100644 --- a/src/charging-station/ui-server/UIHttpServer.ts +++ b/src/charging-station/ui-server/UIHttpServer.ts @@ -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', () => { diff --git a/src/charging-station/ui-server/UIWebSocketServer.ts b/src/charging-station/ui-server/UIWebSocketServer.ts index e217305f..006c3914 100644 --- a/src/charging-station/ui-server/UIWebSocketServer.ts +++ b/src/charging-station/ui-server/UIWebSocketServer.ts @@ -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(); diff --git a/src/charging-station/ui-server/ui-services/AbstractUIService.ts b/src/charging-station/ui-server/ui-services/AbstractUIService.ts index 5a418b9d..2b1267f3 100644 --- a/src/charging-station/ui-server/ui-services/AbstractUIService.ts +++ b/src/charging-station/ui-server/ui-services/AbstractUIService.ts @@ -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 diff --git a/src/performance/PerformanceStatistics.ts b/src/performance/PerformanceStatistics.ts index 49ebc79b..6c0ff042 100644 --- a/src/performance/PerformanceStatistics.ts +++ b/src/performance/PerformanceStatistics.ts @@ -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): number[] { - return timeSeries.map((timeSeriesItem) => timeSeriesItem.value); + return timeSeries.map(timeSeriesItem => timeSeriesItem.value); } private logPrefix(): string { diff --git a/src/performance/storage/JsonFileStorage.ts b/src/performance/storage/JsonFileStorage.ts index 63d12a43..94c36edd 100644 --- a/src/performance/storage/JsonFileStorage.ts +++ b/src/performance/storage/JsonFileStorage.ts @@ -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 diff --git a/src/start.ts b/src/start.ts index 8eca3a4a..a21f7fcf 100644 --- a/src/start.ts +++ b/src/start.ts @@ -6,6 +6,6 @@ import { Bootstrap } from './internal'; Bootstrap.getInstance() .start() - .catch((error) => { + .catch(error => { console.error(chalk.red(error)); }); diff --git a/src/utils/Configuration.ts b/src/utils/Configuration.ts index b51e8ada..03789f15 100644 --- a/src/utils/Configuration.ts +++ b/src/utils/Configuration.ts @@ -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; }); } diff --git a/src/utils/Utils.ts b/src/utils/Utils.ts index ca8f44af..4a9bdb70 100644 --- a/src/utils/Utils.ts +++ b/src/utils/Utils.ts @@ -26,7 +26,7 @@ export default class Utils { } public static async sleep(milliSeconds: number): Promise { - return new Promise((resolve) => setTimeout(resolve as () => void, milliSeconds)); + return new Promise(resolve => setTimeout(resolve as () => void, milliSeconds)); } public static formatDurationMilliSeconds(duration: number): string { diff --git a/src/worker/WorkerSet.ts b/src/worker/WorkerSet.ts index c82e79fc..76d759a2 100644 --- a/src/worker/WorkerSet.ts +++ b/src/worker/WorkerSet.ts @@ -98,7 +98,7 @@ export default class WorkerSet extends WorkerAbstract { ).bind(this) as MessageHandler ); 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)); }); diff --git a/ui/web/src/composables/UIClient.ts b/ui/web/src/composables/UIClient.ts index e78836fd..056e2ce2 100644 --- a/ui/web/src/composables/UIClient.ts +++ b/ui/web/src/composables/UIClient.ts @@ -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); }; }