From 7d80b046ec9ec33ab00a173959aa9b24605ac548 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Tue, 17 Mar 2026 00:48:15 +0100 Subject: [PATCH] refactor: enforce consistent-type-imports eslint rule and fix violations --- eslint.config.js | 6 ++++++ src/charging-station/ocpp/1.6/OCPP16ResponseService.ts | 3 ++- src/charging-station/ocpp/2.0/OCPP20ResponseService.ts | 3 ++- .../ocpp/auth/adapters/OCPP20AuthAdapter.ts | 7 ++----- .../ocpp/auth/services/OCPPAuthServiceImpl.ts | 2 +- .../ocpp/auth/strategies/RemoteAuthStrategy.ts | 2 +- src/charging-station/ocpp/auth/types/AuthTypes.ts | 2 +- src/charging-station/ocpp/auth/utils/AuthHelpers.ts | 4 ++-- ...16IncomingRequestService-RemoteStartTransaction.test.ts | 7 +++++-- ...0IncomingRequestService-RequestStartTransaction.test.ts | 4 +++- ...20IncomingRequestService-RequestStopTransaction.test.ts | 4 +++- tests/charging-station/ui-server/UIServerTestUtils.ts | 7 ++++--- tests/helpers/OCPPAuthIntegrationTest.ts | 2 +- 13 files changed, 33 insertions(+), 20 deletions(-) diff --git a/eslint.config.js b/eslint.config.js index 3ce166cf..203c4b1f 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -138,6 +138,12 @@ export default defineConfig([ tsconfigRootDir: import.meta.dirname, }, }, + rules: { + '@typescript-eslint/consistent-type-imports': [ + 'error', + { fixStyle: 'separate-type-imports', prefer: 'type-imports' }, + ], + }, }, { files: ['**/*.js', '**/*.mjs', '**/*.cjs'], diff --git a/src/charging-station/ocpp/1.6/OCPP16ResponseService.ts b/src/charging-station/ocpp/1.6/OCPP16ResponseService.ts index 64b4c30d..d88a33e0 100644 --- a/src/charging-station/ocpp/1.6/OCPP16ResponseService.ts +++ b/src/charging-station/ocpp/1.6/OCPP16ResponseService.ts @@ -2,6 +2,8 @@ import type { ValidateFunction } from 'ajv' import { secondsToMilliseconds } from 'date-fns' +import type { OCPP16IncomingRequestCommand } from '../../../types/index.js' + import { addConfigurationKey, type ChargingStation, @@ -17,7 +19,6 @@ import { type OCPP16AuthorizeResponse, type OCPP16BootNotificationResponse, OCPP16ChargePointStatus, - OCPP16IncomingRequestCommand, type OCPP16MeterValue, type OCPP16MeterValuesRequest, type OCPP16MeterValuesResponse, diff --git a/src/charging-station/ocpp/2.0/OCPP20ResponseService.ts b/src/charging-station/ocpp/2.0/OCPP20ResponseService.ts index 60611914..3ab8940a 100644 --- a/src/charging-station/ocpp/2.0/OCPP20ResponseService.ts +++ b/src/charging-station/ocpp/2.0/OCPP20ResponseService.ts @@ -1,5 +1,7 @@ import type { ValidateFunction } from 'ajv' +import type { OCPP20IncomingRequestCommand } from '../../../types/index.js' + import { addConfigurationKey, type ChargingStation } from '../../../charging-station/index.js' import { ChargingStationEvents, @@ -7,7 +9,6 @@ import { type OCPP20BootNotificationResponse, type OCPP20FirmwareStatusNotificationResponse, type OCPP20HeartbeatResponse, - OCPP20IncomingRequestCommand, type OCPP20LogStatusNotificationResponse, type OCPP20MeterValuesResponse, type OCPP20NotifyCustomerInformationResponse, diff --git a/src/charging-station/ocpp/auth/adapters/OCPP20AuthAdapter.ts b/src/charging-station/ocpp/auth/adapters/OCPP20AuthAdapter.ts index ce3d3044..75fac487 100644 --- a/src/charging-station/ocpp/auth/adapters/OCPP20AuthAdapter.ts +++ b/src/charging-station/ocpp/auth/adapters/OCPP20AuthAdapter.ts @@ -1,3 +1,4 @@ +import type { RequestStartStopStatusEnumType } from '../../../../types/index.js' import type { ChargingStation } from '../../../index.js' import type { OCPPAuthAdapter } from '../interfaces/OCPPAuthService.js' import type { @@ -9,11 +10,7 @@ import type { import { OCPP20ServiceUtils } from '../../2.0/OCPP20ServiceUtils.js' import { OCPP20VariableManager } from '../../2.0/OCPP20VariableManager.js' -import { - GetVariableStatusEnumType, - type OCPP20IdTokenType, - RequestStartStopStatusEnumType, -} from '../../../../types/index.js' +import { GetVariableStatusEnumType, type OCPP20IdTokenType } from '../../../../types/index.js' import { type AdditionalInfoType, OCPP20AuthorizationStatusEnumType, diff --git a/src/charging-station/ocpp/auth/services/OCPPAuthServiceImpl.ts b/src/charging-station/ocpp/auth/services/OCPPAuthServiceImpl.ts index 03553242..452d8dc2 100644 --- a/src/charging-station/ocpp/auth/services/OCPPAuthServiceImpl.ts +++ b/src/charging-station/ocpp/auth/services/OCPPAuthServiceImpl.ts @@ -1,5 +1,6 @@ import type { OCPP16AuthAdapter } from '../adapters/OCPP16AuthAdapter.js' import type { OCPP20AuthAdapter } from '../adapters/OCPP20AuthAdapter.js' +import type { LocalAuthStrategy } from '../strategies/LocalAuthStrategy.js' import { OCPPError } from '../../../../exception/OCPPError.js' import { ErrorType } from '../../../../types/index.js' @@ -12,7 +13,6 @@ import { type AuthStrategy, type OCPPAuthService, } from '../interfaces/OCPPAuthService.js' -import { LocalAuthStrategy } from '../strategies/LocalAuthStrategy.js' import { type AuthConfiguration, AuthContext, diff --git a/src/charging-station/ocpp/auth/strategies/RemoteAuthStrategy.ts b/src/charging-station/ocpp/auth/strategies/RemoteAuthStrategy.ts index b51c391e..b80b06f9 100644 --- a/src/charging-station/ocpp/auth/strategies/RemoteAuthStrategy.ts +++ b/src/charging-station/ocpp/auth/strategies/RemoteAuthStrategy.ts @@ -1,3 +1,4 @@ +import type { OCPPVersion } from '../../../../types/ocpp/OCPPVersion.js' import type { AuthCache, AuthStrategy, @@ -6,7 +7,6 @@ import type { } from '../interfaces/OCPPAuthService.js' import type { AuthConfiguration, AuthorizationResult, AuthRequest } from '../types/AuthTypes.js' -import { OCPPVersion } from '../../../../types/ocpp/OCPPVersion.js' import { ensureError, getErrorMessage, logger } from '../../../../utils/index.js' import { AuthenticationError, diff --git a/src/charging-station/ocpp/auth/types/AuthTypes.ts b/src/charging-station/ocpp/auth/types/AuthTypes.ts index ed7bc64f..355c4eb2 100644 --- a/src/charging-station/ocpp/auth/types/AuthTypes.ts +++ b/src/charging-station/ocpp/auth/types/AuthTypes.ts @@ -1,11 +1,11 @@ import type { JsonObject } from '../../../../types/JsonType.js' +import type { OCPPVersion } from '../../../../types/ocpp/OCPPVersion.js' import { OCPP16AuthorizationStatus } from '../../../../types/ocpp/1.6/Transaction.js' import { OCPP20IdTokenEnumType, RequestStartStopStatusEnumType, } from '../../../../types/ocpp/2.0/Transaction.js' -import { OCPPVersion } from '../../../../types/ocpp/OCPPVersion.js' /** * Authentication context for strategy selection diff --git a/src/charging-station/ocpp/auth/utils/AuthHelpers.ts b/src/charging-station/ocpp/auth/utils/AuthHelpers.ts index c83d2887..78ef4918 100644 --- a/src/charging-station/ocpp/auth/utils/AuthHelpers.ts +++ b/src/charging-station/ocpp/auth/utils/AuthHelpers.ts @@ -1,6 +1,6 @@ -import type { AuthorizationResult, AuthRequest, UnifiedIdentifier } from '../types/AuthTypes.js' +import type { AuthContext, AuthenticationMethod, AuthorizationResult, AuthRequest, UnifiedIdentifier } from '../types/AuthTypes.js' -import { AuthContext, AuthenticationMethod, AuthorizationStatus } from '../types/AuthTypes.js' +import { AuthorizationStatus } from '../types/AuthTypes.js' /** * Compute remaining TTL in seconds from an expiry date. diff --git a/tests/charging-station/ocpp/1.6/OCPP16IncomingRequestService-RemoteStartTransaction.test.ts b/tests/charging-station/ocpp/1.6/OCPP16IncomingRequestService-RemoteStartTransaction.test.ts index 6abb6702..d3ddeeef 100644 --- a/tests/charging-station/ocpp/1.6/OCPP16IncomingRequestService-RemoteStartTransaction.test.ts +++ b/tests/charging-station/ocpp/1.6/OCPP16IncomingRequestService-RemoteStartTransaction.test.ts @@ -3,9 +3,12 @@ * @description Unit tests for OCPP 1.6 RemoteStartTransaction incoming request handler (§5.11) */ +import type { mock } from 'node:test' + import assert from 'node:assert/strict' -import { afterEach, beforeEach, describe, it, mock } from 'node:test' +import { afterEach, beforeEach, describe, it } from 'node:test' +import type { ChargingStation } from '../../../../src/charging-station/ChargingStation.js' import type { RemoteStartTransactionRequest } from '../../../../src/types/index.js' import { OCPP16IncomingRequestService } from '../../../../src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.js' @@ -170,7 +173,7 @@ await describe('OCPP16IncomingRequestService — RemoteStartTransaction', async await describe('REMOTE_START_TRANSACTION event listener', async () => { let incomingRequestService: OCPP16IncomingRequestService let requestHandlerMock: ReturnType - let listenerStation: import('../../../../src/charging-station/ChargingStation.js').ChargingStation + let listenerStation: ChargingStation beforeEach(() => { ;({ requestHandlerMock, station: listenerStation } = createOCPP16ListenerStation( diff --git a/tests/charging-station/ocpp/2.0/OCPP20IncomingRequestService-RequestStartTransaction.test.ts b/tests/charging-station/ocpp/2.0/OCPP20IncomingRequestService-RequestStartTransaction.test.ts index 338d0e78..30cbd128 100644 --- a/tests/charging-station/ocpp/2.0/OCPP20IncomingRequestService-RequestStartTransaction.test.ts +++ b/tests/charging-station/ocpp/2.0/OCPP20IncomingRequestService-RequestStartTransaction.test.ts @@ -1,9 +1,11 @@ +import type { mock } from 'node:test' + /** * @file Tests for OCPP20IncomingRequestService RequestStartTransaction * @description Unit tests for OCPP 2.0 RequestStartTransaction command handling (F01/F02) */ import assert from 'node:assert/strict' -import { afterEach, beforeEach, describe, it, mock } from 'node:test' +import { afterEach, beforeEach, describe, it } from 'node:test' import type { ChargingStation } from '../../../../src/charging-station/index.js' import type { diff --git a/tests/charging-station/ocpp/2.0/OCPP20IncomingRequestService-RequestStopTransaction.test.ts b/tests/charging-station/ocpp/2.0/OCPP20IncomingRequestService-RequestStopTransaction.test.ts index 51e842e8..70c99756 100644 --- a/tests/charging-station/ocpp/2.0/OCPP20IncomingRequestService-RequestStopTransaction.test.ts +++ b/tests/charging-station/ocpp/2.0/OCPP20IncomingRequestService-RequestStopTransaction.test.ts @@ -3,8 +3,10 @@ * @description Unit tests for OCPP 2.0 RequestStopTransaction command handling (F03) */ +import type { mock } from 'node:test' + import assert from 'node:assert/strict' -import { afterEach, beforeEach, describe, it, mock } from 'node:test' +import { afterEach, beforeEach, describe, it } from 'node:test' import type { ChargingStation } from '../../../../src/charging-station/index.js' import type { diff --git a/tests/charging-station/ui-server/UIServerTestUtils.ts b/tests/charging-station/ui-server/UIServerTestUtils.ts index 3d1acce0..c5aff7be 100644 --- a/tests/charging-station/ui-server/UIServerTestUtils.ts +++ b/tests/charging-station/ui-server/UIServerTestUtils.ts @@ -8,11 +8,14 @@ import { EventEmitter } from 'node:events' import type { ChargingStationData, + ProcedureName, ProtocolRequest, ProtocolResponse, + ProtocolVersion, RequestPayload, + UIServerConfiguration, - UUIDv4, + UUIDv4 } from '../../../src/types/index.js' import { UIWebSocketServer } from '../../../src/charging-station/ui-server/UIWebSocketServer.js' @@ -20,8 +23,6 @@ import { ApplicationProtocol, ApplicationProtocolVersion, AuthenticationType, - ProcedureName, - ProtocolVersion, ResponseStatus, } from '../../../src/types/index.js' import { MockWebSocket } from '../mocks/MockWebSocket.js' diff --git a/tests/helpers/OCPPAuthIntegrationTest.ts b/tests/helpers/OCPPAuthIntegrationTest.ts index f05f97d5..18a5b1e8 100644 --- a/tests/helpers/OCPPAuthIntegrationTest.ts +++ b/tests/helpers/OCPPAuthIntegrationTest.ts @@ -1,3 +1,4 @@ +import type { ChargingStation } from '../../src/charging-station/ChargingStation.js' import type { AuthConfiguration, AuthorizationResult, @@ -5,7 +6,6 @@ import type { UnifiedIdentifier, } from '../../src/charging-station/ocpp/auth/types/AuthTypes.js' -import { ChargingStation } from '../../src/charging-station/ChargingStation.js' import { OCPPAuthServiceImpl } from '../../src/charging-station/ocpp/auth/services/OCPPAuthServiceImpl.js' import { AuthContext, -- 2.43.0