From 386f51c5f3cfddeed55475815ee1b201bc1df65f Mon Sep 17 00:00:00 2001 From: Johan Nyman Date: Tue, 27 Aug 2024 14:52:16 +0200 Subject: [PATCH] chore: lint --- packages/connector/src/connection/mosMessageParser.ts | 4 ++-- packages/connector/src/connection/mosSocketClient.ts | 10 +++++----- packages/helper/src/mosModel/MosMessage.ts | 2 +- packages/helper/src/mosModel/parseMosTypes.ts | 6 +++--- packages/helper/src/mosModel/profile1/xmlConversion.ts | 2 +- packages/model/src/mosTypes/mosDuration.ts | 2 +- 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/packages/connector/src/connection/mosMessageParser.ts b/packages/connector/src/connection/mosMessageParser.ts index 47fb8f28..50e233a1 100644 --- a/packages/connector/src/connection/mosMessageParser.ts +++ b/packages/connector/src/connection/mosMessageParser.ts @@ -138,8 +138,8 @@ export class MosMessageParser extends EventEmitter { } private debugTrace(str: string) { if (this.debug) { - // Supress console spam: - if (!`${str}`.match(//)) { + // Suppress console spam: + if (!//.exec(`${str}`)) { // eslint-disable-next-line no-console console.log(str) } diff --git a/packages/connector/src/connection/mosSocketClient.ts b/packages/connector/src/connection/mosSocketClient.ts index 1af1b076..b4e174ce 100644 --- a/packages/connector/src/connection/mosSocketClient.ts +++ b/packages/connector/src/connection/mosSocketClient.ts @@ -101,7 +101,7 @@ export class MosSocketClient extends EventEmitter { if (!this._lastConnectionAttempt || Date.now() - this._lastConnectionAttempt >= this._reconnectDelay) { // !_lastReconnectionAttempt (means first attempt) OR time > _reconnectionDelay since last attempt // recreate client if new attempt: - if (this._client && this._client.connecting) { + if (this._client?.connecting) { this._client.destroy() this._client.removeAllListeners() delete this._client @@ -274,8 +274,8 @@ export class MosSocketClient extends EventEmitter { /** * convenience wrapper to expose all logging calls to parent object */ - log(args: string | number | any): void { - this.debugTrace(args) + log(...args: any[]): void { + this.debugTrace(...args) } public setDebug(debug: boolean): void { this._debug = debug @@ -544,8 +544,8 @@ export class MosSocketClient extends EventEmitter { } }, this._commandTimeout) } - private debugTrace(...strs: any[]) { + private debugTrace(...args: any[]) { // eslint-disable-next-line no-console - if (this._debug) console.log(...strs) + if (this._debug) console.log(...args) } } diff --git a/packages/helper/src/mosModel/MosMessage.ts b/packages/helper/src/mosModel/MosMessage.ts index b39b2b4e..51914e35 100644 --- a/packages/helper/src/mosModel/MosMessage.ts +++ b/packages/helper/src/mosModel/MosMessage.ts @@ -29,7 +29,7 @@ export abstract class MosMessage { prepare(messageID?: number): void { if (!this.mosID) throw new Error(`Can't prepare message: mosID missing`) if (!this.ncsID) throw new Error(`Can't prepare message: ncsID missing`) - this._messageID = messageID ? messageID : MosMessage.getNewMessageID() + this._messageID = messageID ?? MosMessage.getNewMessageID() } /** */ diff --git a/packages/helper/src/mosModel/parseMosTypes.ts b/packages/helper/src/mosModel/parseMosTypes.ts index 512c7835..54534970 100644 --- a/packages/helper/src/mosModel/parseMosTypes.ts +++ b/packages/helper/src/mosModel/parseMosTypes.ts @@ -215,7 +215,7 @@ function getSpecialMosTypes(strict: boolean) { validate: (_value: string) => true, valueOf: (value: string) => value, stringify: (value: string) => value, - is: (value: string | any): value is string => typeof value !== 'string', + is: (value: any): value is string => typeof value !== 'string', fallback: () => '', } const stringEnum: MosType = { @@ -237,7 +237,7 @@ function getSpecialMosTypes(strict: boolean) { validate: (_value: string) => true, valueOf: (value: string) => value, stringify: (value: string) => value, - is: (value: string | any): value is string => typeof value !== 'string', + is: (value: any): value is string => typeof value !== 'string', fallback: () => '', } const number: MosType = { @@ -248,7 +248,7 @@ function getSpecialMosTypes(strict: boolean) { validate: (_value: number) => true, valueOf: (value: number) => value, stringify: (value: number) => `${value}`, - is: (value: number | any): value is number => typeof value !== 'number', + is: (value: any): value is number => typeof value !== 'number', fallback: () => 0, } diff --git a/packages/helper/src/mosModel/profile1/xmlConversion.ts b/packages/helper/src/mosModel/profile1/xmlConversion.ts index f1bf6b66..dfb75353 100644 --- a/packages/helper/src/mosModel/profile1/xmlConversion.ts +++ b/packages/helper/src/mosModel/profile1/xmlConversion.ts @@ -27,7 +27,7 @@ export namespace XMLMosAck { const ack: IMOSAck = { ID: mosTypes.mosString128.createRequired(xml.objID, 'objID'), - Revision: mosTypes.number.createOptional(xml.objRev, 'objRev') || 0, + Revision: mosTypes.number.createOptional(xml.objRev, 'objRev') ?? 0, Status: mosTypes.stringEnum.createOptional({ value: xml.status, enum: IMOSAckStatus }, 'status') || IMOSAckStatus.ACK, diff --git a/packages/model/src/mosTypes/mosDuration.ts b/packages/model/src/mosTypes/mosDuration.ts index dd47b320..22441842 100644 --- a/packages/model/src/mosTypes/mosDuration.ts +++ b/packages/model/src/mosTypes/mosDuration.ts @@ -11,7 +11,7 @@ export function create(anyValue: AnyValue, strict: boolean): IMOSDuration { if (typeof anyValue === 'number') { value = anyValue } else if (typeof anyValue === 'string') { - const m = anyValue.match(/(\d+):(\d+):(\d+)/) + const m = /(\d+):(\d+):(\d+)/.exec(anyValue) if (!m) throw new Error(`MosDuration: Invalid input format: "${anyValue}"!`) const hh: number = parseInt(m[1], 10)