From 9534e74eac653e8cdf02b17a33b273d421251a1c Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Sat, 5 Mar 2022 22:14:22 +0100 Subject: [PATCH] Fix eslint configuration for mixed source with .js and .ts MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- .eslintrc | 65 +++++++++++------------- src/charging-station/ChargingStation.ts | 32 +++++++----- src/performance/PerformanceStatistics.ts | 1 + 3 files changed, 49 insertions(+), 49 deletions(-) diff --git a/.eslintrc b/.eslintrc index 255533c3..409a11b2 100644 --- a/.eslintrc +++ b/.eslintrc @@ -1,41 +1,20 @@ { "root": true, - "parser": "@typescript-eslint/parser", - "parserOptions": { - "project": "./tsconfig.json" - }, "extends": [ "eslint:recommended", - "plugin:@typescript-eslint/recommended", - "plugin:@typescript-eslint/recommended-requiring-type-checking", "plugin:import/errors", "plugin:import/warnings", - "plugin:import/typescript", "plugin:jsdoc/recommended", "plugin:prettier/recommended" ], - "plugins": ["import", "jsdoc", "@typescript-eslint"], + "plugins": ["import", "jsdoc"], "settings": { "jsdoc": { "mode": "typescript" } }, "rules": { - "@typescript-eslint/array-type": "off", - "semi": "off", - "@typescript-eslint/semi": ["error", "always"], "space-before-blocks": ["error", "always"], - "@typescript-eslint/no-empty-function": [ - "warn", - { - "allow": ["arrowFunctions", "methods"] - } - ], - "@typescript-eslint/member-ordering": "error", - "@typescript-eslint/await-thenable": "error", - "@typescript-eslint/no-floating-promises": "error", - "@typescript-eslint/promise-function-async": "error", - "@typescript-eslint/no-misused-promises": "error", "curly": ["error", "all"], "brace-style": "error", "eqeqeq": ["error", "always"], @@ -49,8 +28,6 @@ "no-return-assign": ["error", "always"], "no-useless-catch": "error", "no-useless-return": "error", - "no-shadow": "off", // This one is generating false positive no-shadow errors on exported/const enums - "@typescript-eslint/no-shadow": "error", "no-multiple-empty-lines": [ "error", { @@ -96,14 +73,6 @@ "no-lonely-if": "error", "no-trailing-spaces": "error", "no-whitespace-before-property": "error", - "space-before-function-paren": [ - "error", - { - "anonymous": "never", - "named": "never", - "asyncArrow": "always" - } - ], "space-in-parens": ["error", "never"], "space-infix-ops": "error", "space-unary-ops": "error", @@ -143,12 +112,36 @@ }, "overrides": [ { - "files": ["*.js"], + "files": ["**/*.ts"], + "parser": "@typescript-eslint/parser", + "parserOptions": { + "project": "./tsconfig.json" + }, + "extends": [ + "plugin:@typescript-eslint/recommended", + "plugin:@typescript-eslint/recommended-requiring-type-checking", + "plugin:import/typescript" + ], + "plugins": ["@typescript-eslint"], + "rules": { + "@typescript-eslint/array-type": "off", + "semi": "off", + "@typescript-eslint/semi": ["error", "always"], + "@typescript-eslint/no-empty-function": "warn", + "@typescript-eslint/member-ordering": "error", + "@typescript-eslint/await-thenable": "error", + "@typescript-eslint/no-floating-promises": "error", + "@typescript-eslint/promise-function-async": "error", + "@typescript-eslint/no-misused-promises": "error", + "no-shadow": "off", // This one is generating false positive no-shadow errors on exported/const enums + "@typescript-eslint/no-shadow": "error" + } + }, + { + "files": ["**/*.js"], "extends": "plugin:node/recommended", "rules": { - "node/shebang": "off", - "@typescript-eslint/no-unused-vars": "off", - "@typescript-eslint/no-var-requires": "off" + "node/shebang": "off" } } ] diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index 8d5cac1d..d136a150 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -25,7 +25,7 @@ import { } from '../types/ocpp/Configuration'; import { MeterValueMeasurand, MeterValuePhase } from '../types/ocpp/MeterValues'; import { WSError, WebSocketCloseEventStatusCode } from '../types/WebSocket'; -import WebSocket, { ClientOptions, Data, OPEN } from 'ws'; +import WebSocket, { ClientOptions, Data, OPEN, RawData } from 'ws'; import AutomaticTransactionGenerator from './AutomaticTransactionGenerator'; import { ChargePointStatus } from '../types/ocpp/ChargePointStatus'; @@ -451,6 +451,7 @@ export default class ChargingStation { if (interval > 0) { // eslint-disable-next-line @typescript-eslint/no-misused-promises this.getConnectorStatus(connectorId).transactionSetInterval = setInterval( + // eslint-disable-next-line @typescript-eslint/no-misused-promises async (): Promise => { await this.ocppRequestService.sendMeterValues( connectorId, @@ -481,17 +482,26 @@ export default class ChargingStation { // Monitor station template file this.startStationTemplateFileMonitoring(); // Handle WebSocket message - this.wsConnection.on('message', this.onMessage.bind(this)); + this.wsConnection.on( + 'message', + this.onMessage.bind(this) as (this: WebSocket, data: RawData, isBinary: boolean) => void + ); // Handle WebSocket error - this.wsConnection.on('error', this.onError.bind(this)); + this.wsConnection.on( + 'error', + this.onError.bind(this) as (this: WebSocket, error: Error) => void + ); // Handle WebSocket close - this.wsConnection.on('close', this.onClose.bind(this)); + this.wsConnection.on( + 'close', + this.onClose.bind(this) as (this: WebSocket, code: number, reason: Buffer) => void + ); // Handle WebSocket open - this.wsConnection.on('open', this.onOpen.bind(this)); + this.wsConnection.on('open', this.onOpen.bind(this) as (this: WebSocket) => void); // Handle WebSocket ping - this.wsConnection.on('ping', this.onPing.bind(this)); + this.wsConnection.on('ping', this.onPing.bind(this) as (this: WebSocket, data: Buffer) => void); // Handle WebSocket pong - this.wsConnection.on('pong', this.onPong.bind(this)); + this.wsConnection.on('pong', this.onPong.bind(this) as (this: WebSocket, data: Buffer) => void); parentPort.postMessage({ id: ChargingStationWorkerMessageEvents.STARTED, data: { id: this.stationInfo.chargingStationId }, @@ -1077,6 +1087,7 @@ export default class ChargingStation { break; // Error default: + // eslint-disable-next-line @typescript-eslint/restrict-template-expressions errMsg = `${this.logPrefix()} Wrong message type ${messageType}`; logger.error(errMsg); throw new OCPPError(ErrorType.PROTOCOL_ERROR, errMsg); @@ -1104,13 +1115,8 @@ export default class ChargingStation { logger.debug(this.logPrefix() + ' Received a WS pong (rfc6455) from the server'); } - private async onError(error: WSError): Promise { + private onError(error: WSError): void { logger.error(this.logPrefix() + ' WebSocket error: %j', error); - // switch (error.code) { - // case 'ECONNREFUSED': - // await this.reconnect(error); - // break; - // } } private getTemplateChargingStationConfiguration(): ChargingStationConfiguration { diff --git a/src/performance/PerformanceStatistics.ts b/src/performance/PerformanceStatistics.ts index 7338fa24..fdcabb33 100644 --- a/src/performance/PerformanceStatistics.ts +++ b/src/performance/PerformanceStatistics.ts @@ -101,6 +101,7 @@ export default class PerformanceStatistics { } break; default: + // eslint-disable-next-line @typescript-eslint/restrict-template-expressions logger.error(`${this.logPrefix()} wrong message type ${messageType}`); break; } -- 2.34.1