refactor: cleanup some eslint rules disablement
[poolifier.git] / src / worker / abstract-worker.ts
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)
         }
       })