From: Jérôme Benoit Date: Thu, 4 Jan 2024 11:13:07 +0000 (+0100) Subject: refactor: cleanup some eslint rules disablement X-Git-Tag: v3.1.17~7 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=7f0e133432b540753bcdd06160d1363e9fe65437;p=poolifier.git refactor: cleanup some eslint rules disablement Signed-off-by: Jérôme Benoit --- diff --git a/src/pools/abstract-pool.ts b/src/pools/abstract-pool.ts index 0c366911..a9f6edd7 100644 --- a/src/pools/abstract-pool.ts +++ b/src/pools/abstract-pool.ts @@ -1768,8 +1768,7 @@ export abstract class AbstractPool< workerNodeTasksUsage.sequentiallyStolen === 0 ) { workerNode.emit('idle', { - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - workerId: workerId!, + workerId, workerNodeKey }) } diff --git a/src/pools/selection-strategies/interleaved-weighted-round-robin-worker-choice-strategy.ts b/src/pools/selection-strategies/interleaved-weighted-round-robin-worker-choice-strategy.ts index e2aa0c6d..2d604e71 100644 --- a/src/pools/selection-strategies/interleaved-weighted-round-robin-worker-choice-strategy.ts +++ b/src/pools/selection-strategies/interleaved-weighted-round-robin-worker-choice-strategy.ts @@ -95,7 +95,7 @@ export class InterleavedWeightedRoundRobinWorkerChoiceStrategy< this.workerNodeVirtualTaskRunTime = 0 } // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - const workerWeight = this.opts!.weights![workerNodeKey]! + const workerWeight = this.opts!.weights![workerNodeKey] if ( this.isWorkerNodeReady(workerNodeKey) && workerWeight >= this.roundWeights[roundIndex] && diff --git a/src/pools/thread/fixed.ts b/src/pools/thread/fixed.ts index 9561cc78..78ef12f8 100644 --- a/src/pools/thread/fixed.ts +++ b/src/pools/thread/fixed.ts @@ -1,5 +1,4 @@ import { - type MessagePort, type TransferListItem, type Worker, isMainThread @@ -63,7 +62,7 @@ export class FixedThreadPool< protected sendStartupMessageToWorker (workerNodeKey: number): void { const workerNode = this.workerNodes[workerNodeKey] // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - const port2: MessagePort = workerNode.messageChannel!.port2 + const port2 = workerNode.messageChannel!.port2 workerNode.worker.postMessage( { ready: false, diff --git a/src/pools/worker-node.ts b/src/pools/worker-node.ts index 9fa4ea32..a9f9ca5f 100644 --- a/src/pools/worker-node.ts +++ b/src/pools/worker-node.ts @@ -78,8 +78,7 @@ export class WorkerNode const tasksQueueSize = this.tasksQueue.push(task) if (this.hasBackPressure() && !this.onBackPressureStarted) { this.onBackPressureStarted = true - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - this.emit('backPressure', { workerId: this.info.id! }) + this.emit('backPressure', { workerId: this.info.id }) this.onBackPressureStarted = false } return tasksQueueSize @@ -90,8 +89,7 @@ export class WorkerNode const tasksQueueSize = this.tasksQueue.unshift(task) if (this.hasBackPressure() && !this.onBackPressureStarted) { this.onBackPressureStarted = true - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - this.emit('backPressure', { workerId: this.info.id! }) + this.emit('backPressure', { workerId: this.info.id }) this.onBackPressureStarted = false } return tasksQueueSize diff --git a/src/worker/abstract-worker.ts b/src/worker/abstract-worker.ts index 890f340e..238f749e 100644 --- a/src/worker/abstract-worker.ts +++ b/src/worker/abstract-worker.ts @@ -325,26 +325,28 @@ export abstract class AbstractWorker< message: MessageValue ): void { const { taskFunctionOperation, taskFunctionName, taskFunction } = message - let response!: TaskFunctionOperationResult + if (taskFunctionName == null) { + throw new Error( + 'Cannot handle task function operation message without a task function name' + ) + } + let response: TaskFunctionOperationResult switch (taskFunctionOperation) { case 'add': response = this.addTaskFunction( - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - taskFunctionName!, - // eslint-disable-next-line @typescript-eslint/no-implied-eval, no-new-func, @typescript-eslint/no-non-null-assertion - new Function(`return ${taskFunction!}`)() as TaskFunction< + taskFunctionName, + // eslint-disable-next-line @typescript-eslint/no-implied-eval, no-new-func + new Function(`return ${taskFunction}`)() as TaskFunction< Data, Response > ) break case 'remove': - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - response = this.removeTaskFunction(taskFunctionName!) + response = this.removeTaskFunction(taskFunctionName) break case 'default': - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - response = this.setDefaultTaskFunction(taskFunctionName!) + response = this.setDefaultTaskFunction(taskFunctionName) break default: response = { status: false, error: new Error('Unknown task operation') } @@ -357,8 +359,7 @@ export abstract class AbstractWorker< ...(!response.status && response.error != null && { workerError: { - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - name: taskFunctionName!, + name: taskFunctionName, message: this.handleError(response.error as Error | string) } })