From: Jérôme Benoit Date: Fri, 1 Nov 2024 16:02:03 +0000 (+0100) Subject: refactor: cleanup linter warnings X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=1ea7f1dfaa14dfb2be0855e73e3b541da86af536;p=e-mobility-charging-stations-simulator.git refactor: cleanup linter warnings Signed-off-by: Jérôme Benoit --- diff --git a/src/charging-station/Bootstrap.ts b/src/charging-station/Bootstrap.ts index 82c2cea9..e791ed01 100644 --- a/src/charging-station/Bootstrap.ts +++ b/src/charging-station/Bootstrap.ts @@ -1,6 +1,6 @@ // Partial Copyright Jerome Benoit. 2021-2024. All Rights Reserved. -import type { Worker } from 'worker_threads' +import type { Worker } from 'node:worker_threads' import chalk from 'chalk' import { EventEmitter } from 'node:events' diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index 5c54018c..5e0640b6 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -1827,17 +1827,17 @@ export class ChargingStation extends EventEmitter { getChargingStationChargingProfilesLimit(this)! / this.powerDivider! const connectorChargingProfilesLimit = getConnectorChargingProfilesLimit(this, connectorId) return min( - isNaN(connectorMaximumPower) ? Number.POSITIVE_INFINITY : connectorMaximumPower, + Number.isNaN(connectorMaximumPower) ? Number.POSITIVE_INFINITY : connectorMaximumPower, // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - isNaN(connectorAmperageLimitationLimit!) + Number.isNaN(connectorAmperageLimitationLimit!) ? Number.POSITIVE_INFINITY : // eslint-disable-next-line @typescript-eslint/no-non-null-assertion connectorAmperageLimitationLimit!, - isNaN(chargingStationChargingProfilesLimit) + Number.isNaN(chargingStationChargingProfilesLimit) ? Number.POSITIVE_INFINITY : chargingStationChargingProfilesLimit, // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - isNaN(connectorChargingProfilesLimit!) + Number.isNaN(connectorChargingProfilesLimit!) ? Number.POSITIVE_INFINITY : // eslint-disable-next-line @typescript-eslint/no-non-null-assertion connectorChargingProfilesLimit! diff --git a/src/charging-station/ocpp/OCPPServiceUtils.ts b/src/charging-station/ocpp/OCPPServiceUtils.ts index 14d5120b..6f54853f 100644 --- a/src/charging-station/ocpp/OCPPServiceUtils.ts +++ b/src/charging-station/ocpp/OCPPServiceUtils.ts @@ -1146,8 +1146,9 @@ const getLimitFromSampledValueTemplateCustomValue = ( if (options.limitationEnabled) { return max( min( - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - (!isNaN(parsedValue) ? parsedValue : Number.POSITIVE_INFINITY) * options.unitMultiplier!, + (!Number.isNaN(parsedValue) ? parsedValue : Number.POSITIVE_INFINITY) * + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + options.unitMultiplier!, maxLimit ), minLimit diff --git a/src/utils/Utils.ts b/src/utils/Utils.ts index cc26fcc4..6f0e6b9f 100644 --- a/src/utils/Utils.ts +++ b/src/utils/Utils.ts @@ -76,9 +76,9 @@ export const formatDurationSeconds = (duration: number): string => { // More efficient time validation function than the one provided by date-fns export const isValidDate = (date: Date | number | undefined): date is Date | number => { if (typeof date === 'number') { - return !isNaN(date) + return !Number.isNaN(date) } else if (isDate(date)) { - return !isNaN(date.getTime()) + return !Number.isNaN(date.getTime()) } return false } @@ -94,7 +94,7 @@ export const convertToDate = ( } if (typeof value === 'string' || typeof value === 'number') { const valueToDate = new Date(value) - if (isNaN(valueToDate.getTime())) { + if (Number.isNaN(valueToDate.getTime())) { throw new Error(`Cannot convert to date: '${value.toString()}'`) } return valueToDate @@ -115,7 +115,7 @@ export const convertToInt = (value: unknown): number => { if (typeof value === 'string') { changedValue = Number.parseInt(value) } - if (isNaN(changedValue)) { + if (Number.isNaN(changedValue)) { // eslint-disable-next-line @typescript-eslint/no-base-to-string throw new Error(`Cannot convert to integer: '${value.toString()}'`) } @@ -130,7 +130,7 @@ export const convertToFloat = (value: unknown): number => { if (typeof value === 'string') { changedValue = Number.parseFloat(value) } - if (isNaN(changedValue)) { + if (Number.isNaN(changedValue)) { // eslint-disable-next-line @typescript-eslint/no-base-to-string throw new Error(`Cannot convert to float: '${value.toString()}'`) }