refactor: cleanup some eslint rules disablement
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Thu, 4 Jan 2024 11:13:07 +0000 (12:13 +0100)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Thu, 4 Jan 2024 11:13:07 +0000 (12:13 +0100)
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
src/pools/abstract-pool.ts
src/pools/selection-strategies/interleaved-weighted-round-robin-worker-choice-strategy.ts
src/pools/thread/fixed.ts
src/pools/worker-node.ts
src/worker/abstract-worker.ts

index 0c366911a1ddb059f3c993f69bfdabfa8404173a..a9f6edd73099454681644b56693b8978cec9f81e 100644 (file)
@@ -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
           })
         }
index e2aa0c6d03ceec1dabd8a012e92c7e72e4ca69ff..2d604e71a97002ad0980da85f2799f232608b6d3 100644 (file)
@@ -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] &&
index 9561cc787a2cddbcb757fa1939cdeea25888a5a0..78ef12f87744729733f7434bdbb21a299f286b63 100644 (file)
@@ -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,
index 9fa4ea3201e3ca0db3d3aa9f79153adc3f1625d5..a9f9ca5f71fac8adf9655a105d55307e78884d5a 100644 (file)
@@ -78,8 +78,7 @@ export class WorkerNode<Worker extends IWorker, Data = unknown>
     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<Worker extends IWorker, Data = unknown>
     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
index 890f340e69a63ac1bce217ecafa0ae5191febae1..238f749e12325a9b18d47a1ec0e3871d0fc95cbe 100644 (file)
@@ -325,26 +325,28 @@ export abstract class AbstractWorker<
     message: MessageValue<Data>
   ): 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)
         }
       })