From 8ebe6c308dc1fc3202980126da043b2855d24780 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Mon, 14 Aug 2023 00:13:25 +0200 Subject: [PATCH] build: switch from prettier to rome as code formatter MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- .lintstagedrc.js | 4 +- .prettierignore | 10 --- .prettierrc.json | 7 -- benchmarks/benchmarks-utils.mjs | 10 +-- benchmarks/internal/bench.mjs | 4 +- benchmarks/internal/cluster-worker.mjs | 2 +- benchmarks/internal/thread-worker.mjs | 2 +- .../functions/function-to-bench.js | 2 +- examples/javascript/dynamicExample.js | 4 +- examples/javascript/fixedExample.js | 4 +- examples/javascript/multiFunctionExample.js | 10 +-- .../typescript/http-client-pool/httpd-echo.js | 2 +- .../express-worker_threads/src/main.ts | 4 +- .../express-worker_threads/src/worker.ts | 2 +- .../fastify-cluster/src/main.ts | 4 +- .../fastify-cluster/src/worker.ts | 6 +- .../fastify-hybrid/src/fastify-worker.ts | 4 +- .../fastify-hybrid/src/main.ts | 4 +- .../src/request-handler-worker.ts | 2 +- .../fastify-worker_threads/src/main.ts | 4 +- .../fastify-worker_threads/src/worker.ts | 2 +- .../ws-cluster/requests.js | 2 +- .../ws-cluster/src/main.ts | 4 +- .../ws-cluster/src/worker.ts | 4 +- .../ws-hybrid/requests.js | 2 +- .../ws-hybrid/src/main.ts | 4 +- .../ws-hybrid/src/request-handler-worker.ts | 2 +- .../ws-hybrid/src/websocket-server-worker.ts | 6 +- .../ws-worker_threads/requests.js | 2 +- .../ws-worker_threads/src/main.ts | 6 +- .../ws-worker_threads/src/worker.ts | 2 +- examples/typescript/worker.ts | 2 +- package.json | 17 +---- pnpm-lock.yaml | 74 ++++++++++++++++--- rome.json | 39 ++++++++++ src/pools/abstract-pool.ts | 26 +++---- src/pools/cluster/fixed.ts | 2 +- src/pools/thread/fixed.ts | 2 +- src/worker/abstract-worker.ts | 6 +- tests/pools/abstract/abstract-pool.test.js | 8 +- tests/pools/cluster/dynamic.test.js | 6 +- tests/pools/cluster/fixed.test.js | 18 ++--- tests/pools/thread/dynamic.test.js | 6 +- tests/pools/thread/fixed.test.js | 18 ++--- tests/test-utils.js | 16 ++-- .../cluster/testMultiTasksWorker.js | 6 +- .../thread/testMultiTasksWorker.js | 6 +- typedoc.mjs | 2 +- 48 files changed, 225 insertions(+), 156 deletions(-) delete mode 100644 .prettierignore delete mode 100644 .prettierrc.json create mode 100644 rome.json diff --git a/.lintstagedrc.js b/.lintstagedrc.js index 5455fcaa..a247d74d 100644 --- a/.lintstagedrc.js +++ b/.lintstagedrc.js @@ -1,8 +1,8 @@ module.exports = { '**/*.{ts,tsx,js,jsx,cjs,mjs}': [ - 'prettier --cache --write', + 'rome format --write', 'ts-standard --fix', 'eslint --cache --fix' ], - '**/*.{json,md,yml,yaml}': ['prettier --cache --write'] + '**/*.{json,md,yml,yaml}': ['rome format --write'] } diff --git a/.prettierignore b/.prettierignore deleted file mode 100644 index 400bb753..00000000 --- a/.prettierignore +++ /dev/null @@ -1,10 +0,0 @@ -pnpm-lock.yaml -.nyc_output/ -coverage/ -reports/ -benchmarks/internal/results/ -docs/**/*.html -docs/**/*.css -docs/**/*.js -outputs/ -lib/ diff --git a/.prettierrc.json b/.prettierrc.json deleted file mode 100644 index 82fe1c17..00000000 --- a/.prettierrc.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "$schema": "https://json.schemastore.org/prettierrc", - "arrowParens": "avoid", - "semi": false, - "singleQuote": true, - "trailingComma": "none" -} diff --git a/benchmarks/benchmarks-utils.mjs b/benchmarks/benchmarks-utils.mjs index 259fca56..e8c67583 100644 --- a/benchmarks/benchmarks-utils.mjs +++ b/benchmarks/benchmarks-utils.mjs @@ -23,7 +23,7 @@ export const runTest = async (pool, { taskExecutions, workerData }) => { } return null }) - .catch(err => { + .catch((err) => { console.error(err) return reject(err) }) @@ -46,7 +46,7 @@ export const generateRandomInteger = ( return Math.floor(Math.random() * (max + 1)) } -const jsonIntegerSerialization = n => { +const jsonIntegerSerialization = (n) => { for (let i = 0; i < n; i++) { const o = { a: i @@ -61,7 +61,7 @@ const jsonIntegerSerialization = n => { * @param {number} n - The number of fibonacci numbers to generate. * @returns {number} - The nth fibonacci number. */ -const fibonacci = n => { +const fibonacci = (n) => { if (n <= 1) return n return fibonacci(n - 1) + fibonacci(n - 2) } @@ -71,7 +71,7 @@ const fibonacci = n => { * @param {number} n - The number to calculate the factorial of. * @returns {number} - The factorial of n. */ -const factorial = n => { +const factorial = (n) => { if (n === 0) { return 1 } @@ -100,7 +100,7 @@ const readWriteFiles = ( return { ok: 1 } } -export const executeTaskFunction = data => { +export const executeTaskFunction = (data) => { switch (data.function) { case TaskFunctions.jsonIntegerSerialization: return jsonIntegerSerialization(data.taskSize || 1000) diff --git a/benchmarks/internal/bench.mjs b/benchmarks/internal/bench.mjs index 2749da42..193827f3 100644 --- a/benchmarks/internal/bench.mjs +++ b/benchmarks/internal/bench.mjs @@ -50,7 +50,7 @@ const workerData = { function: TaskFunctions.jsonIntegerSerialization, taskSize: 1000 } -const addPools = pools => +const addPools = (pools) => pools.map(([name, pool]) => { return add(name, async () => { await runTest(pool, { @@ -90,4 +90,4 @@ suite( // eslint-disable-next-line n/no-process-exit return process.exit() }) - .catch(err => console.error(err)) + .catch((err) => console.error(err)) diff --git a/benchmarks/internal/cluster-worker.mjs b/benchmarks/internal/cluster-worker.mjs index 60876beb..bc354839 100644 --- a/benchmarks/internal/cluster-worker.mjs +++ b/benchmarks/internal/cluster-worker.mjs @@ -5,7 +5,7 @@ import { TaskFunctions } from '../benchmarks-types.mjs' const debug = false -const taskFunction = data => { +const taskFunction = (data) => { data = data || {} data.function = data.function || TaskFunctions.jsonIntegerSerialization const res = executeTaskFunction(data) diff --git a/benchmarks/internal/thread-worker.mjs b/benchmarks/internal/thread-worker.mjs index 869e95f4..855ba622 100644 --- a/benchmarks/internal/thread-worker.mjs +++ b/benchmarks/internal/thread-worker.mjs @@ -5,7 +5,7 @@ import { TaskFunctions } from '../benchmarks-types.mjs' const debug = false -const taskFunction = data => { +const taskFunction = (data) => { data = data || {} data.function = data.function || TaskFunctions.jsonIntegerSerialization const res = executeTaskFunction(data) diff --git a/benchmarks/versus-external-pools/functions/function-to-bench.js b/benchmarks/versus-external-pools/functions/function-to-bench.js index ecc39a1c..eca756b7 100644 --- a/benchmarks/versus-external-pools/functions/function-to-bench.js +++ b/benchmarks/versus-external-pools/functions/function-to-bench.js @@ -5,7 +5,7 @@ * @param {*} data The worker data. * @returns {*} The result. */ -const functionToBench = data => { +const functionToBench = (data) => { const crypto = require('crypto') const fs = require('fs') const TaskTypes = { diff --git a/examples/javascript/dynamicExample.js b/examples/javascript/dynamicExample.js index ad79ba20..21fe9050 100644 --- a/examples/javascript/dynamicExample.js +++ b/examples/javascript/dynamicExample.js @@ -10,7 +10,7 @@ const pool = new DynamicThreadPool( availableParallelism(), './yourWorker.js', { - errorHandler: e => console.error(e), + errorHandler: (e) => console.error(e), onlineHandler: () => console.info('worker is online') } ) @@ -37,5 +37,5 @@ for (let i = 1; i <= iterations; i++) { } return null }) - .catch(err => console.error(err)) + .catch((err) => console.error(err)) } diff --git a/examples/javascript/fixedExample.js b/examples/javascript/fixedExample.js index 1f5ac4ea..85f159d3 100644 --- a/examples/javascript/fixedExample.js +++ b/examples/javascript/fixedExample.js @@ -6,7 +6,7 @@ const { } = require('poolifier') const pool = new FixedThreadPool(availableParallelism(), './yourWorker.js', { - errorHandler: e => console.error(e), + errorHandler: (e) => console.error(e), onlineHandler: () => console.info('worker is online') }) let poolReady = 0 @@ -29,5 +29,5 @@ for (let i = 1; i <= iterations; i++) { } return null }) - .catch(err => console.error(err)) + .catch((err) => console.error(err)) } diff --git a/examples/javascript/multiFunctionExample.js b/examples/javascript/multiFunctionExample.js index 27a50325..addbf46c 100644 --- a/examples/javascript/multiFunctionExample.js +++ b/examples/javascript/multiFunctionExample.js @@ -5,18 +5,18 @@ const pool = new FixedThreadPool( availableParallelism(), './multiFunctionWorker.js', { - errorHandler: e => console.error(e), + errorHandler: (e) => console.error(e), onlineHandler: () => console.info('worker is online') } ) pool .execute({ text: 'hello' }, 'fn0') - .then(res => console.info(res)) - .catch(err => console.error(err)) + .then((res) => console.info(res)) + .catch((err) => console.error(err)) pool .execute({ text: 'multiple functions' }, 'fn1') - .then(res => console.info(res)) - .catch(err => console.error(err)) + .then((res) => console.info(res)) + .catch((err) => console.error(err)) setTimeout(pool.destroy(), 3000) diff --git a/examples/typescript/http-client-pool/httpd-echo.js b/examples/typescript/http-client-pool/httpd-echo.js index 53b8ad11..cbfb8da7 100644 --- a/examples/typescript/http-client-pool/httpd-echo.js +++ b/examples/typescript/http-client-pool/httpd-echo.js @@ -7,7 +7,7 @@ server .on('request', (request, response) => { let body = [] request - .on('data', chunk => { + .on('data', (chunk) => { body.push(chunk) }) .on('end', () => { diff --git a/examples/typescript/http-server-pool/express-worker_threads/src/main.ts b/examples/typescript/http-server-pool/express-worker_threads/src/main.ts index 4f1a4d95..970cf4d0 100644 --- a/examples/typescript/http-server-pool/express-worker_threads/src/main.ts +++ b/examples/typescript/http-server-pool/express-worker_threads/src/main.ts @@ -21,7 +21,7 @@ expressApp.use(express.json()) expressApp.all('/api/echo', (req: Request, res: Response) => { requestHandlerPool .execute({ body: req.body }, 'echo') - .then(response => { + .then((response) => { return res.send(response.body).end() }) .catch(emptyFunction) @@ -31,7 +31,7 @@ expressApp.get('/api/factorial/:number', (req: Request, res: Response) => { const { number } = req.params requestHandlerPool .execute({ body: { number: parseInt(number) } }, 'factorial') - .then(response => { + .then((response) => { return res.send(response.body).end() }) .catch(emptyFunction) diff --git a/examples/typescript/http-server-pool/express-worker_threads/src/worker.ts b/examples/typescript/http-server-pool/express-worker_threads/src/worker.ts index 7589aa6b..cc46cba4 100644 --- a/examples/typescript/http-server-pool/express-worker_threads/src/worker.ts +++ b/examples/typescript/http-server-pool/express-worker_threads/src/worker.ts @@ -5,7 +5,7 @@ import { type WorkerResponse } from './types.js' -const factorial: (n: number) => number = n => { +const factorial: (n: number) => number = (n) => { if (n === 0) { return 1 } diff --git a/examples/typescript/http-server-pool/fastify-cluster/src/main.ts b/examples/typescript/http-server-pool/fastify-cluster/src/main.ts index 88167a3c..1dc88be2 100644 --- a/examples/typescript/http-server-pool/fastify-cluster/src/main.ts +++ b/examples/typescript/http-server-pool/fastify-cluster/src/main.ts @@ -15,7 +15,7 @@ const pool = new FixedClusterPool( onlineHandler: () => { pool .execute({ port: 8080 }) - .then(response => { + .then((response) => { if (response.status) { console.info( // eslint-disable-next-line @typescript-eslint/restrict-template-expressions @@ -24,7 +24,7 @@ const pool = new FixedClusterPool( } return null }) - .catch(error => { + .catch((error) => { console.error('Fastify failed to start in cluster worker:', error) }) }, diff --git a/examples/typescript/http-server-pool/fastify-cluster/src/worker.ts b/examples/typescript/http-server-pool/fastify-cluster/src/worker.ts index 4084bf71..3f7b3661 100644 --- a/examples/typescript/http-server-pool/fastify-cluster/src/worker.ts +++ b/examples/typescript/http-server-pool/fastify-cluster/src/worker.ts @@ -3,7 +3,7 @@ import { ClusterWorker } from 'poolifier' import Fastify, { type FastifyInstance } from 'fastify' import type { WorkerData, WorkerResponse } from './types.js' -const factorial: (n: number) => number = n => { +const factorial: (n: number) => number = (n) => { if (n === 0) { return 1 } @@ -21,13 +21,13 @@ class FastifyWorker extends ClusterWorker { logger: true }) - FastifyWorker.fastify.all('/api/echo', request => { + FastifyWorker.fastify.all('/api/echo', (request) => { return request.body }) FastifyWorker.fastify.get<{ Params: { number: number } - }>('/api/factorial/:number', request => { + }>('/api/factorial/:number', (request) => { const { number } = request.params return { number: factorial(number) } }) diff --git a/examples/typescript/http-server-pool/fastify-hybrid/src/fastify-worker.ts b/examples/typescript/http-server-pool/fastify-hybrid/src/fastify-worker.ts index dd77f123..89fc3338 100644 --- a/examples/typescript/http-server-pool/fastify-hybrid/src/fastify-worker.ts +++ b/examples/typescript/http-server-pool/fastify-hybrid/src/fastify-worker.ts @@ -20,7 +20,7 @@ ClusterWorkerResponse await FastifyWorker.fastify.register(fastifyPoolifier, workerData) - FastifyWorker.fastify.all('/api/echo', async request => { + FastifyWorker.fastify.all('/api/echo', async (request) => { return ( await FastifyWorker.fastify.execute({ body: request.body }, 'echo') ).body @@ -28,7 +28,7 @@ ClusterWorkerResponse FastifyWorker.fastify.get<{ Params: { number: number } - }>('/api/factorial/:number', async request => { + }>('/api/factorial/:number', async (request) => { const { number } = request.params return ( await FastifyWorker.fastify.execute({ body: { number } }, 'factorial') diff --git a/examples/typescript/http-server-pool/fastify-hybrid/src/main.ts b/examples/typescript/http-server-pool/fastify-hybrid/src/main.ts index 9b269760..ca7c42d4 100644 --- a/examples/typescript/http-server-pool/fastify-hybrid/src/main.ts +++ b/examples/typescript/http-server-pool/fastify-hybrid/src/main.ts @@ -31,7 +31,7 @@ const pool = new FixedClusterPool( console.error('Thread worker error', e) } }) - .then(response => { + .then((response) => { if (response.status) { console.info( // eslint-disable-next-line @typescript-eslint/restrict-template-expressions @@ -40,7 +40,7 @@ const pool = new FixedClusterPool( } return null }) - .catch(error => { + .catch((error) => { console.error('Fastify failed to start in cluster worker:', error) }) }, diff --git a/examples/typescript/http-server-pool/fastify-hybrid/src/request-handler-worker.ts b/examples/typescript/http-server-pool/fastify-hybrid/src/request-handler-worker.ts index 1b35b44b..d3b6c876 100644 --- a/examples/typescript/http-server-pool/fastify-hybrid/src/request-handler-worker.ts +++ b/examples/typescript/http-server-pool/fastify-hybrid/src/request-handler-worker.ts @@ -5,7 +5,7 @@ import { type ThreadWorkerResponse } from './types.js' -const factorial: (n: number) => number = n => { +const factorial: (n: number) => number = (n) => { if (n === 0) { return 1 } diff --git a/examples/typescript/http-server-pool/fastify-worker_threads/src/main.ts b/examples/typescript/http-server-pool/fastify-worker_threads/src/main.ts index cc647a0f..f1271c6e 100644 --- a/examples/typescript/http-server-pool/fastify-worker_threads/src/main.ts +++ b/examples/typescript/http-server-pool/fastify-worker_threads/src/main.ts @@ -28,13 +28,13 @@ await fastify.register(fastifyPoolifier, { } }) -fastify.all('/api/echo', async request => { +fastify.all('/api/echo', async (request) => { return (await fastify.execute({ body: request.body }, 'echo')).body }) fastify.get<{ Params: { number: number } -}>('/api/factorial/:number', async request => { +}>('/api/factorial/:number', async (request) => { const { number } = request.params return (await fastify.execute({ body: { number } }, 'factorial')).body }) diff --git a/examples/typescript/http-server-pool/fastify-worker_threads/src/worker.ts b/examples/typescript/http-server-pool/fastify-worker_threads/src/worker.ts index 7589aa6b..cc46cba4 100644 --- a/examples/typescript/http-server-pool/fastify-worker_threads/src/worker.ts +++ b/examples/typescript/http-server-pool/fastify-worker_threads/src/worker.ts @@ -5,7 +5,7 @@ import { type WorkerResponse } from './types.js' -const factorial: (n: number) => number = n => { +const factorial: (n: number) => number = (n) => { if (n === 0) { return 1 } diff --git a/examples/typescript/websocket-server-pool/ws-cluster/requests.js b/examples/typescript/websocket-server-pool/ws-cluster/requests.js index 1f302a6c..3f796e36 100644 --- a/examples/typescript/websocket-server-pool/ws-cluster/requests.js +++ b/examples/typescript/websocket-server-pool/ws-cluster/requests.js @@ -16,6 +16,6 @@ ws.on('open', () => { } }) -ws.on('message', message => { +ws.on('message', (message) => { console.info('message received: %s', message) }) diff --git a/examples/typescript/websocket-server-pool/ws-cluster/src/main.ts b/examples/typescript/websocket-server-pool/ws-cluster/src/main.ts index ad58bd20..ebf35134 100644 --- a/examples/typescript/websocket-server-pool/ws-cluster/src/main.ts +++ b/examples/typescript/websocket-server-pool/ws-cluster/src/main.ts @@ -15,7 +15,7 @@ const pool = new FixedClusterPool( onlineHandler: () => { pool .execute({ port: 8080 }) - .then(response => { + .then((response) => { if (response.status) { console.info( // eslint-disable-next-line @typescript-eslint/restrict-template-expressions @@ -24,7 +24,7 @@ const pool = new FixedClusterPool( } return null }) - .catch(error => { + .catch((error) => { console.error( 'WebSocket server failed to start in cluster worker:', error diff --git a/examples/typescript/websocket-server-pool/ws-cluster/src/worker.ts b/examples/typescript/websocket-server-pool/ws-cluster/src/worker.ts index c82c7e63..efe0facd 100644 --- a/examples/typescript/websocket-server-pool/ws-cluster/src/worker.ts +++ b/examples/typescript/websocket-server-pool/ws-cluster/src/worker.ts @@ -8,7 +8,7 @@ import { type WorkerResponse } from './types.js' -const factorial: (n: number) => number = n => { +const factorial: (n: number) => number = (n) => { if (n === 0) { return 1 } @@ -28,7 +28,7 @@ class WebSocketServerWorker extends ClusterWorker { ) }) - WebSocketServerWorker.wss.on('connection', ws => { + WebSocketServerWorker.wss.on('connection', (ws) => { ws.on('error', console.error) ws.on('message', (message: RawData) => { const { type, data } = JSON.parse( diff --git a/examples/typescript/websocket-server-pool/ws-hybrid/requests.js b/examples/typescript/websocket-server-pool/ws-hybrid/requests.js index 1f302a6c..3f796e36 100644 --- a/examples/typescript/websocket-server-pool/ws-hybrid/requests.js +++ b/examples/typescript/websocket-server-pool/ws-hybrid/requests.js @@ -16,6 +16,6 @@ ws.on('open', () => { } }) -ws.on('message', message => { +ws.on('message', (message) => { console.info('message received: %s', message) }) diff --git a/examples/typescript/websocket-server-pool/ws-hybrid/src/main.ts b/examples/typescript/websocket-server-pool/ws-hybrid/src/main.ts index d9e827cb..62e772da 100644 --- a/examples/typescript/websocket-server-pool/ws-hybrid/src/main.ts +++ b/examples/typescript/websocket-server-pool/ws-hybrid/src/main.ts @@ -31,7 +31,7 @@ const pool = new FixedClusterPool( console.error('Thread worker error:', e) } }) - .then(response => { + .then((response) => { if (response.status) { console.info( // eslint-disable-next-line @typescript-eslint/restrict-template-expressions @@ -40,7 +40,7 @@ const pool = new FixedClusterPool( } return null }) - .catch(error => { + .catch((error) => { console.error( 'WebSocket server failed to start in cluster worker:', error diff --git a/examples/typescript/websocket-server-pool/ws-hybrid/src/request-handler-worker.ts b/examples/typescript/websocket-server-pool/ws-hybrid/src/request-handler-worker.ts index 40cde50d..6a88d20a 100644 --- a/examples/typescript/websocket-server-pool/ws-hybrid/src/request-handler-worker.ts +++ b/examples/typescript/websocket-server-pool/ws-hybrid/src/request-handler-worker.ts @@ -5,7 +5,7 @@ import { type ThreadWorkerResponse } from './types.js' -const factorial: (n: number) => number = n => { +const factorial: (n: number) => number = (n) => { if (n === 0) { return 1 } diff --git a/examples/typescript/websocket-server-pool/ws-hybrid/src/websocket-server-worker.ts b/examples/typescript/websocket-server-pool/ws-hybrid/src/websocket-server-worker.ts index bd7b8fbb..f495a721 100644 --- a/examples/typescript/websocket-server-pool/ws-hybrid/src/websocket-server-worker.ts +++ b/examples/typescript/websocket-server-pool/ws-hybrid/src/websocket-server-worker.ts @@ -47,7 +47,7 @@ ClusterWorkerResponse workerData?.workerFile as string ) - WebSocketServerWorker.wss.on('connection', ws => { + WebSocketServerWorker.wss.on('connection', (ws) => { ws.on('error', console.error) ws.on('message', (message: RawData) => { const { type, data } = JSON.parse( @@ -58,7 +58,7 @@ ClusterWorkerResponse case MessageType.echo: WebSocketServerWorker.requestHandlerPool .execute({ data }, 'echo') - .then(response => { + .then((response) => { ws.send( JSON.stringify({ type: MessageType.echo, @@ -72,7 +72,7 @@ ClusterWorkerResponse case MessageType.factorial: WebSocketServerWorker.requestHandlerPool .execute({ data }, 'factorial') - .then(response => { + .then((response) => { ws.send( JSON.stringify({ type: MessageType.factorial, diff --git a/examples/typescript/websocket-server-pool/ws-worker_threads/requests.js b/examples/typescript/websocket-server-pool/ws-worker_threads/requests.js index 1f302a6c..3f796e36 100644 --- a/examples/typescript/websocket-server-pool/ws-worker_threads/requests.js +++ b/examples/typescript/websocket-server-pool/ws-worker_threads/requests.js @@ -16,6 +16,6 @@ ws.on('open', () => { } }) -ws.on('message', message => { +ws.on('message', (message) => { console.info('message received: %s', message) }) diff --git a/examples/typescript/websocket-server-pool/ws-worker_threads/src/main.ts b/examples/typescript/websocket-server-pool/ws-worker_threads/src/main.ts index 6283759d..9edb16b0 100644 --- a/examples/typescript/websocket-server-pool/ws-worker_threads/src/main.ts +++ b/examples/typescript/websocket-server-pool/ws-worker_threads/src/main.ts @@ -13,7 +13,7 @@ const emptyFunction = (): void => { /** Intentional */ } -wss.on('connection', ws => { +wss.on('connection', (ws) => { ws.on('error', console.error) ws.on('message', (message: RawData) => { const { type, data } = JSON.parse( @@ -24,7 +24,7 @@ wss.on('connection', ws => { case MessageType.echo: requestHandlerPool .execute({ data }, 'echo') - .then(response => { + .then((response) => { ws.send( JSON.stringify({ type: MessageType.echo, @@ -38,7 +38,7 @@ wss.on('connection', ws => { case MessageType.factorial: requestHandlerPool .execute({ data }, 'factorial') - .then(response => { + .then((response) => { ws.send( JSON.stringify({ type: MessageType.factorial, diff --git a/examples/typescript/websocket-server-pool/ws-worker_threads/src/worker.ts b/examples/typescript/websocket-server-pool/ws-worker_threads/src/worker.ts index 92b9d64a..e31cc4fe 100644 --- a/examples/typescript/websocket-server-pool/ws-worker_threads/src/worker.ts +++ b/examples/typescript/websocket-server-pool/ws-worker_threads/src/worker.ts @@ -5,7 +5,7 @@ import { type WorkerResponse } from './types.js' -const factorial: (n: number) => number = n => { +const factorial: (n: number) => number = (n) => { if (n === 0) { return 1 } diff --git a/examples/typescript/worker.ts b/examples/typescript/worker.ts index 81d39df3..caf6e3ac 100644 --- a/examples/typescript/worker.ts +++ b/examples/typescript/worker.ts @@ -18,7 +18,7 @@ class MyThreadWorker extends ThreadWorker> { } private async process (data: MyData): Promise { - return await new Promise(resolve => { + return await new Promise((resolve) => { setTimeout(() => { resolve({ message: 'Hello from Worker :)', data }) }, 10000) diff --git a/package.json b/package.json index dba4df87..f5e72d4b 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,7 @@ "test:debug": "pnpm build && mocha --no-parallel --inspect 'tests/**/*.test.js'", "coverage": "c8 report --reporter=lcov", "coverage:html": "c8 report --reporter=html", - "format": "prettier . --cache --write; ts-standard . --fix", + "format": "rome format . --write; ts-standard . --fix", "lint": "eslint . --cache", "lint:fix": "eslint . --cache --fix", "lint:report": "eslint . --cache --format json --output-file reports/eslint.json", @@ -35,14 +35,7 @@ "prepublishOnly": "pnpm build:prod" }, "ts-standard": { - "globals": [ - "describe", - "it", - "before", - "after", - "beforeEach", - "afterEach" - ] + "globals": ["describe", "it", "before", "after", "beforeEach", "afterEach"] }, "engines": { "node": ">=16.14.0", @@ -97,9 +90,7 @@ "url": "https://github.com/poolifier/poolifier/issues" }, "homepage": "https://github.com/poolifier/poolifier#readme", - "files": [ - "lib" - ], + "files": ["lib"], "pnpm": { "overrides": { "semver": "^7.5.3" @@ -134,12 +125,12 @@ "microtime": "^3.1.1", "mocha": "^10.2.0", "mochawesome": "^7.1.3", - "prettier": "^3.0.1", "release-it": "^16.1.5", "rollup": "^3.28.0", "rollup-plugin-analyzer": "^4.0.0", "rollup-plugin-command": "^1.1.3", "rollup-plugin-delete": "^2.0.0", + "rome": "^12.1.3", "sinon": "^15.2.0", "source-map-support": "^0.5.21", "ts-standard": "^12.0.2", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 55286c30..e08287ad 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -92,9 +92,6 @@ devDependencies: mochawesome: specifier: ^7.1.3 version: 7.1.3(mocha@10.2.0) - prettier: - specifier: ^3.0.1 - version: 3.0.1 release-it: specifier: ^16.1.5 version: 16.1.5 @@ -110,6 +107,9 @@ devDependencies: rollup-plugin-delete: specifier: ^2.0.0 version: 2.0.0 + rome: + specifier: ^12.1.3 + version: 12.1.3 sinon: specifier: ^15.2.0 version: 15.2.0 @@ -768,6 +768,54 @@ packages: rollup: 3.28.0 dev: true + /@rometools/cli-darwin-arm64@12.1.3: + resolution: {integrity: sha512-AmFTUDYjBuEGQp/Wwps+2cqUr+qhR7gyXAUnkL5psCuNCz3807TrUq/ecOoct5MIavGJTH6R4aaSL6+f+VlBEg==} + cpu: [arm64] + os: [darwin] + requiresBuild: true + dev: true + optional: true + + /@rometools/cli-darwin-x64@12.1.3: + resolution: {integrity: sha512-k8MbWna8q4LRlb005N2X+JS1UQ+s3ZLBBvwk4fP8TBxlAJXUz17jLLu/Fi+7DTTEmMhM84TWj4FDKW+rNar28g==} + cpu: [x64] + os: [darwin] + requiresBuild: true + dev: true + optional: true + + /@rometools/cli-linux-arm64@12.1.3: + resolution: {integrity: sha512-X/uLhJ2/FNA3nu5TiyeNPqiD3OZoFfNfRvw6a3ut0jEREPvEn72NI7WPijH/gxSz55znfQ7UQ6iM4DZumUknJg==} + cpu: [arm64] + os: [linux] + requiresBuild: true + dev: true + optional: true + + /@rometools/cli-linux-x64@12.1.3: + resolution: {integrity: sha512-csP17q1eWiUXx9z6Jr/JJPibkplyKIwiWPYNzvPCGE8pHlKhwZj3YHRuu7Dm/4EOqx0XFIuqqWZUYm9bkIC8xg==} + cpu: [x64] + os: [linux] + requiresBuild: true + dev: true + optional: true + + /@rometools/cli-win32-arm64@12.1.3: + resolution: {integrity: sha512-RymHWeod57EBOJY4P636CgUwYA6BQdkQjh56XKk4pLEHO6X1bFyMet2XL7KlHw5qOTalzuzf5jJqUs+vf3jdXQ==} + cpu: [arm64] + os: [win32] + requiresBuild: true + dev: true + optional: true + + /@rometools/cli-win32-x64@12.1.3: + resolution: {integrity: sha512-yHSKYidqJMV9nADqg78GYA+cZ0hS1twANAjiFibQdXj9aGzD+s/IzIFEIi/U/OBLvWYg/SCw0QVozi2vTlKFDQ==} + cpu: [x64] + os: [win32] + requiresBuild: true + dev: true + optional: true + /@sinclair/typebox@0.27.8: resolution: {integrity: sha512-+Fj43pSMwJs4KRrH/938Uf+uAELIgVBmQzg/q1YG10djyfA3TnrU8N8XzqCh/okZdszqBQTZf96idMfE5lnwTA==} dev: true @@ -4802,12 +4850,6 @@ packages: engines: {node: '>= 0.8.0'} dev: true - /prettier@3.0.1: - resolution: {integrity: sha512-fcOWSnnpCrovBsmFZIGIy9UqK2FaI7Hqax+DIO0A9UxeVoY4iweyaFjS5TavZN97Hfehph0nhsZnjlVKzEQSrQ==} - engines: {node: '>=14'} - hasBin: true - dev: true - /pretty-format@29.6.2: resolution: {integrity: sha512-1q0oC8eRveTg5nnBEWMXAU2qpv65Gnuf2eCQzSjxpWFkPaPARwqZZDGuNE0zPAZfTCHzIk3A8dIjwlQKKLphyg==} engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0} @@ -5158,6 +5200,20 @@ packages: fsevents: 2.3.2 dev: true + /rome@12.1.3: + resolution: {integrity: sha512-e+ff72hxDpe/t5/Us7YRBVw3PBET7SeczTQNn6tvrWdrCaAw3qOukQQ+tDCkyFtS4yGsnhjrJbm43ctNbz27Yg==} + engines: {node: '>=14.*'} + hasBin: true + requiresBuild: true + optionalDependencies: + '@rometools/cli-darwin-arm64': 12.1.3 + '@rometools/cli-darwin-x64': 12.1.3 + '@rometools/cli-linux-arm64': 12.1.3 + '@rometools/cli-linux-x64': 12.1.3 + '@rometools/cli-win32-arm64': 12.1.3 + '@rometools/cli-win32-x64': 12.1.3 + dev: true + /run-applescript@5.0.0: resolution: {integrity: sha512-XcT5rBksx1QdIhlFOCtgZkB99ZEouFZ1E2Kc2LHqNW13U3/74YGdkQRmThTwxy4QIyookibDKYZOPqX//6BlAg==} engines: {node: '>=12'} diff --git a/rome.json b/rome.json new file mode 100644 index 00000000..9e65641a --- /dev/null +++ b/rome.json @@ -0,0 +1,39 @@ +{ + "$schema": "https://docs.rome.tools/schemas/12.1.3/schema.json", + "organizeImports": { + "enabled": false + }, + "linter": { + "enabled": true, + "rules": { + "recommended": true + } + }, + "formatter": { + "enabled": true, + "indentStyle": "space", + "indentSize": 2 + }, + "javascript": { + "formatter": { + "quoteStyle": "single", + "trailingComma": "none", + "semicolons": "asNeeded" + } + }, + "files": { + "ignore": [ + ".vscode/", + ".nyc_output/", + "benchmarks/internal/results/", + "coverage/", + "docs/**/*.css", + "docs/**/*.html", + "docs/**/*.js", + "lib/", + "outputs/", + "pnpm-lock.yaml", + "reports/" + ] + } +} diff --git a/src/pools/abstract-pool.ts b/src/pools/abstract-pool.ts index b4860837..8332d31a 100644 --- a/src/pools/abstract-pool.ts +++ b/src/pools/abstract-pool.ts @@ -360,14 +360,14 @@ export abstract class AbstractPool< minimum: round( Math.min( ...this.workerNodes.map( - workerNode => workerNode.usage.runTime?.minimum ?? Infinity + (workerNode) => workerNode.usage.runTime?.minimum ?? Infinity ) ) ), maximum: round( Math.max( ...this.workerNodes.map( - workerNode => workerNode.usage.runTime?.maximum ?? -Infinity + (workerNode) => workerNode.usage.runTime?.maximum ?? -Infinity ) ) ), @@ -388,7 +388,7 @@ export abstract class AbstractPool< median: round( median( this.workerNodes.map( - workerNode => workerNode.usage.runTime?.median ?? 0 + (workerNode) => workerNode.usage.runTime?.median ?? 0 ) ) ) @@ -401,14 +401,14 @@ export abstract class AbstractPool< minimum: round( Math.min( ...this.workerNodes.map( - workerNode => workerNode.usage.waitTime?.minimum ?? Infinity + (workerNode) => workerNode.usage.waitTime?.minimum ?? Infinity ) ) ), maximum: round( Math.max( ...this.workerNodes.map( - workerNode => workerNode.usage.waitTime?.maximum ?? -Infinity + (workerNode) => workerNode.usage.waitTime?.maximum ?? -Infinity ) ) ), @@ -429,7 +429,7 @@ export abstract class AbstractPool< median: round( median( this.workerNodes.map( - workerNode => workerNode.usage.waitTime?.median ?? 0 + (workerNode) => workerNode.usage.waitTime?.median ?? 0 ) ) ) @@ -522,7 +522,7 @@ export abstract class AbstractPool< */ private getWorkerNodeKeyByWorker (worker: Worker): number { return this.workerNodes.findIndex( - workerNode => workerNode.worker === worker + (workerNode) => workerNode.worker === worker ) } @@ -534,7 +534,7 @@ export abstract class AbstractPool< */ private getWorkerNodeKeyByWorkerId (workerId: number): number { return this.workerNodes.findIndex( - workerNode => workerNode.info.id === workerId + (workerNode) => workerNode.info.id === workerId ) } @@ -624,7 +624,7 @@ export abstract class AbstractPool< if (this.opts.enableTasksQueue === true) { return ( this.workerNodes.findIndex( - workerNode => + (workerNode) => workerNode.info.ready && workerNode.usage.tasks.executing < (this.opts.tasksQueueOptions?.concurrency as number) @@ -633,7 +633,7 @@ export abstract class AbstractPool< } else { return ( this.workerNodes.findIndex( - workerNode => + (workerNode) => workerNode.info.ready && workerNode.usage.tasks.executing === 0 ) === -1 ) @@ -887,7 +887,7 @@ export abstract class AbstractPool< worker.on('message', this.opts.messageHandler ?? EMPTY_FUNCTION) worker.on('error', this.opts.errorHandler ?? EMPTY_FUNCTION) - worker.on('error', error => { + worker.on('error', (error) => { const workerNodeKey = this.getWorkerNodeKeyByWorker(worker) const workerInfo = this.getWorkerInfo(workerNodeKey) workerInfo.ready = false @@ -924,7 +924,7 @@ export abstract class AbstractPool< */ protected createAndSetupDynamicWorkerNode (): number { const workerNodeKey = this.createAndSetupWorkerNode() - this.registerWorkerMessageListener(workerNodeKey, message => { + this.registerWorkerMessageListener(workerNodeKey, (message) => { const localWorkerNodeKey = this.getWorkerNodeKeyByWorkerId( message.workerId ) @@ -1057,7 +1057,7 @@ export abstract class AbstractPool< * @returns The listener function to execute when a message is received from a worker. */ protected workerListener (): (message: MessageValue) => void { - return message => { + return (message) => { this.checkMessageWorkerId(message) if (message.ready != null) { // Worker ready response received from worker diff --git a/src/pools/cluster/fixed.ts b/src/pools/cluster/fixed.ts index 522e7b67..b5b32527 100644 --- a/src/pools/cluster/fixed.ts +++ b/src/pools/cluster/fixed.ts @@ -64,7 +64,7 @@ export class FixedClusterPool< this.flushTasksQueue(workerNodeKey) // FIXME: wait for tasks to be finished const worker = this.workerNodes[workerNodeKey].worker - const waitWorkerExit = new Promise(resolve => { + const waitWorkerExit = new Promise((resolve) => { worker.on('exit', () => { resolve() }) diff --git a/src/pools/thread/fixed.ts b/src/pools/thread/fixed.ts index 2e708d97..a193091f 100644 --- a/src/pools/thread/fixed.ts +++ b/src/pools/thread/fixed.ts @@ -62,7 +62,7 @@ export class FixedThreadPool< // FIXME: wait for tasks to be finished const workerNode = this.workerNodes[workerNodeKey] const worker = workerNode.worker - const waitWorkerExit = new Promise(resolve => { + const waitWorkerExit = new Promise((resolve) => { worker.on('exit', () => { resolve() }) diff --git a/src/worker/abstract-worker.ts b/src/worker/abstract-worker.ts index 64627efb..ae7778c4 100644 --- a/src/worker/abstract-worker.ts +++ b/src/worker/abstract-worker.ts @@ -119,7 +119,7 @@ export abstract class AbstractWorker< this.taskFunctions.set(DEFAULT_TASK_NAME, boundFn) this.taskFunctions.set( typeof taskFunctions.name === 'string' && - taskFunctions.name.trim().length > 0 + taskFunctions.name.trim().length > 0 ? taskFunctions.name : 'fn1', boundFn @@ -454,7 +454,7 @@ export abstract class AbstractWorker< ): void { let taskPerformance = this.beginTaskPerformance(task.name) fn(task.data) - .then(res => { + .then((res) => { taskPerformance = this.endTaskPerformance(taskPerformance) this.sendToMainWorker({ data: res, @@ -464,7 +464,7 @@ export abstract class AbstractWorker< }) return null }) - .catch(e => { + .catch((e) => { const errorMessage = this.handleError(e as Error | string) this.sendToMainWorker({ taskError: { diff --git a/tests/pools/abstract/abstract-pool.test.js b/tests/pools/abstract/abstract-pool.test.js index af167214..953e50d0 100644 --- a/tests/pools/abstract/abstract-pool.test.js +++ b/tests/pools/abstract/abstract-pool.test.js @@ -30,7 +30,7 @@ describe('Abstract pool test suite', () => { numberOfWorkers, './tests/worker-files/thread/testWorker.js', { - errorHandler: e => console.error(e) + errorHandler: (e) => console.error(e) } ) ).toThrowError('Cannot start a pool from a worker!') @@ -741,7 +741,7 @@ describe('Abstract pool test suite', () => { const promises = new Set() let poolFull = 0 let poolInfo - pool.emitter.on(PoolEvents.full, info => { + pool.emitter.on(PoolEvents.full, (info) => { ++poolFull poolInfo = info }) @@ -778,7 +778,7 @@ describe('Abstract pool test suite', () => { ) let poolInfo let poolReady = 0 - pool.emitter.on(PoolEvents.ready, info => { + pool.emitter.on(PoolEvents.ready, (info) => { ++poolReady poolInfo = info }) @@ -810,7 +810,7 @@ describe('Abstract pool test suite', () => { const promises = new Set() let poolBusy = 0 let poolInfo - pool.emitter.on(PoolEvents.busy, info => { + pool.emitter.on(PoolEvents.busy, (info) => { ++poolBusy poolInfo = info }) diff --git a/tests/pools/cluster/dynamic.test.js b/tests/pools/cluster/dynamic.test.js index 65dff559..724c0c91 100644 --- a/tests/pools/cluster/dynamic.test.js +++ b/tests/pools/cluster/dynamic.test.js @@ -11,7 +11,7 @@ describe('Dynamic cluster pool test suite', () => { max, './tests/worker-files/cluster/testWorker.js', { - errorHandler: e => console.error(e) + errorHandler: (e) => console.error(e) } ) @@ -88,7 +88,7 @@ describe('Dynamic cluster pool test suite', () => { max, './tests/worker-files/cluster/longRunningWorkerHardBehavior.js', { - errorHandler: e => console.error(e), + errorHandler: (e) => console.error(e), onlineHandler: () => console.info('long executing worker is online'), exitHandler: () => console.info('long executing worker exited') } @@ -115,7 +115,7 @@ describe('Dynamic cluster pool test suite', () => { max, './tests/worker-files/cluster/longRunningWorkerSoftBehavior.js', { - errorHandler: e => console.error(e), + errorHandler: (e) => console.error(e), onlineHandler: () => console.info('long executing worker is online'), exitHandler: () => console.info('long executing worker exited') } diff --git a/tests/pools/cluster/fixed.test.js b/tests/pools/cluster/fixed.test.js index 335e6d13..30dbc363 100644 --- a/tests/pools/cluster/fixed.test.js +++ b/tests/pools/cluster/fixed.test.js @@ -10,7 +10,7 @@ describe('Fixed cluster pool test suite', () => { numberOfWorkers, './tests/worker-files/cluster/testWorker.js', { - errorHandler: e => console.error(e) + errorHandler: (e) => console.error(e) } ) const queuePool = new FixedClusterPool( @@ -21,7 +21,7 @@ describe('Fixed cluster pool test suite', () => { tasksQueueOptions: { concurrency: tasksConcurrency }, - errorHandler: e => console.error(e) + errorHandler: (e) => console.error(e) } ) const emptyPool = new FixedClusterPool( @@ -37,14 +37,14 @@ describe('Fixed cluster pool test suite', () => { numberOfWorkers, './tests/worker-files/cluster/errorWorker.js', { - errorHandler: e => console.error(e) + errorHandler: (e) => console.error(e) } ) const asyncErrorPool = new FixedClusterPool( numberOfWorkers, './tests/worker-files/cluster/asyncErrorWorker.js', { - errorHandler: e => console.error(e) + errorHandler: (e) => console.error(e) } ) const asyncPool = new FixedClusterPool( @@ -83,7 +83,7 @@ describe('Fixed cluster pool test suite', () => { numberOfWorkers, './tests/worker-files/cluster/testWorker.js', { - errorHandler: e => console.error(e) + errorHandler: (e) => console.error(e) } ) let poolReady = 0 @@ -158,7 +158,7 @@ describe('Fixed cluster pool test suite', () => { it('Verify that error handling is working properly:sync', async () => { const data = { f: 10 } let taskError - errorPool.emitter.on(PoolEvents.taskError, e => { + errorPool.emitter.on(PoolEvents.taskError, (e) => { taskError = e }) let inError @@ -177,7 +177,7 @@ describe('Fixed cluster pool test suite', () => { }) expect( errorPool.workerNodes.some( - workerNode => workerNode.usage.tasks.failed === 1 + (workerNode) => workerNode.usage.tasks.failed === 1 ) ).toBe(true) }) @@ -185,7 +185,7 @@ describe('Fixed cluster pool test suite', () => { it('Verify that error handling is working properly:async', async () => { const data = { f: 10 } let taskError - asyncErrorPool.emitter.on(PoolEvents.taskError, e => { + asyncErrorPool.emitter.on(PoolEvents.taskError, (e) => { taskError = e }) let inError @@ -204,7 +204,7 @@ describe('Fixed cluster pool test suite', () => { }) expect( asyncErrorPool.workerNodes.some( - workerNode => workerNode.usage.tasks.failed === 1 + (workerNode) => workerNode.usage.tasks.failed === 1 ) ).toBe(true) }) diff --git a/tests/pools/thread/dynamic.test.js b/tests/pools/thread/dynamic.test.js index ac926a92..6e6142b7 100644 --- a/tests/pools/thread/dynamic.test.js +++ b/tests/pools/thread/dynamic.test.js @@ -11,7 +11,7 @@ describe('Dynamic thread pool test suite', () => { max, './tests/worker-files/thread/testWorker.js', { - errorHandler: e => console.error(e) + errorHandler: (e) => console.error(e) } ) @@ -88,7 +88,7 @@ describe('Dynamic thread pool test suite', () => { max, './tests/worker-files/thread/longRunningWorkerHardBehavior.js', { - errorHandler: e => console.error(e), + errorHandler: (e) => console.error(e), onlineHandler: () => console.info('long executing worker is online'), exitHandler: () => console.info('long executing worker exited') } @@ -115,7 +115,7 @@ describe('Dynamic thread pool test suite', () => { max, './tests/worker-files/thread/longRunningWorkerSoftBehavior.js', { - errorHandler: e => console.error(e), + errorHandler: (e) => console.error(e), onlineHandler: () => console.info('long executing worker is online'), exitHandler: () => console.info('long executing worker exited') } diff --git a/tests/pools/thread/fixed.test.js b/tests/pools/thread/fixed.test.js index 4fce0b9e..26546d5e 100644 --- a/tests/pools/thread/fixed.test.js +++ b/tests/pools/thread/fixed.test.js @@ -10,7 +10,7 @@ describe('Fixed thread pool test suite', () => { numberOfThreads, './tests/worker-files/thread/testWorker.js', { - errorHandler: e => console.error(e) + errorHandler: (e) => console.error(e) } ) const queuePool = new FixedThreadPool( @@ -21,7 +21,7 @@ describe('Fixed thread pool test suite', () => { tasksQueueOptions: { concurrency: tasksConcurrency }, - errorHandler: e => console.error(e) + errorHandler: (e) => console.error(e) } ) const emptyPool = new FixedThreadPool( @@ -37,14 +37,14 @@ describe('Fixed thread pool test suite', () => { numberOfThreads, './tests/worker-files/thread/errorWorker.js', { - errorHandler: e => console.error(e) + errorHandler: (e) => console.error(e) } ) const asyncErrorPool = new FixedThreadPool( numberOfThreads, './tests/worker-files/thread/asyncErrorWorker.js', { - errorHandler: e => console.error(e) + errorHandler: (e) => console.error(e) } ) const asyncPool = new FixedThreadPool( @@ -83,7 +83,7 @@ describe('Fixed thread pool test suite', () => { numberOfThreads, './tests/worker-files/thread/testWorker.js', { - errorHandler: e => console.error(e) + errorHandler: (e) => console.error(e) } ) let poolReady = 0 @@ -184,7 +184,7 @@ describe('Fixed thread pool test suite', () => { it('Verify that error handling is working properly:sync', async () => { const data = { f: 10 } let taskError - errorPool.emitter.on(PoolEvents.taskError, e => { + errorPool.emitter.on(PoolEvents.taskError, (e) => { taskError = e }) let inError @@ -205,7 +205,7 @@ describe('Fixed thread pool test suite', () => { }) expect( errorPool.workerNodes.some( - workerNode => workerNode.usage.tasks.failed === 1 + (workerNode) => workerNode.usage.tasks.failed === 1 ) ).toBe(true) }) @@ -213,7 +213,7 @@ describe('Fixed thread pool test suite', () => { it('Verify that error handling is working properly:async', async () => { const data = { f: 10 } let taskError - asyncErrorPool.emitter.on(PoolEvents.taskError, e => { + asyncErrorPool.emitter.on(PoolEvents.taskError, (e) => { taskError = e }) let inError @@ -234,7 +234,7 @@ describe('Fixed thread pool test suite', () => { }) expect( asyncErrorPool.workerNodes.some( - workerNode => workerNode.usage.tasks.failed === 1 + (workerNode) => workerNode.usage.tasks.failed === 1 ) ).toBe(true) }) diff --git a/tests/test-utils.js b/tests/test-utils.js index b55f7621..3234a6a2 100644 --- a/tests/test-utils.js +++ b/tests/test-utils.js @@ -1,7 +1,7 @@ const { TaskFunctions } = require('./test-types') const waitWorkerEvents = async (pool, workerEvent, numberOfEventsToWait) => { - return new Promise(resolve => { + return new Promise((resolve) => { let events = 0 if (numberOfEventsToWait === 0) { resolve(events) @@ -18,7 +18,7 @@ const waitWorkerEvents = async (pool, workerEvent, numberOfEventsToWait) => { } const waitPoolEvents = async (pool, poolEvent, numberOfEventsToWait) => { - return new Promise(resolve => { + return new Promise((resolve) => { let events = 0 if (numberOfEventsToWait === 0) { resolve(events) @@ -32,8 +32,8 @@ const waitPoolEvents = async (pool, poolEvent, numberOfEventsToWait) => { }) } -const sleep = async ms => { - return new Promise(resolve => setTimeout(resolve, ms)) +const sleep = async (ms) => { + return new Promise((resolve) => setTimeout(resolve, ms)) } const sleepTaskFunction = async ( @@ -65,7 +65,7 @@ const generateRandomInteger = (max = Number.MAX_SAFE_INTEGER, min = 0) => { return Math.floor(Math.random() * (max + 1)) } -const jsonIntegerSerialization = n => { +const jsonIntegerSerialization = (n) => { for (let i = 0; i < n; i++) { const o = { a: i @@ -80,7 +80,7 @@ const jsonIntegerSerialization = n => { * @param {number} n - The number of fibonacci numbers to generate. * @returns {number} - The nth fibonacci number. */ -const fibonacci = n => { +const fibonacci = (n) => { if (n <= 1) return n return fibonacci(n - 1) + fibonacci(n - 2) } @@ -90,14 +90,14 @@ const fibonacci = n => { * @param {number} n - The number to calculate the factorial of. * @returns {number} - The factorial of n. */ -const factorial = n => { +const factorial = (n) => { if (n === 0) { return 1 } return factorial(n - 1) * n } -const executeTaskFunction = data => { +const executeTaskFunction = (data) => { switch (data.function) { case TaskFunctions.jsonIntegerSerialization: return jsonIntegerSerialization(data.n || 100) diff --git a/tests/worker-files/cluster/testMultiTasksWorker.js b/tests/worker-files/cluster/testMultiTasksWorker.js index 62b640fb..5072691b 100644 --- a/tests/worker-files/cluster/testMultiTasksWorker.js +++ b/tests/worker-files/cluster/testMultiTasksWorker.js @@ -8,9 +8,9 @@ const { module.exports = new ClusterWorker( { - jsonIntegerSerialization: data => jsonIntegerSerialization(data.n), - factorial: data => factorial(data.n), - fibonacci: data => fibonacci(data.n) + jsonIntegerSerialization: (data) => jsonIntegerSerialization(data.n), + factorial: (data) => factorial(data.n), + fibonacci: (data) => fibonacci(data.n) }, { maxInactiveTime: 500, diff --git a/tests/worker-files/thread/testMultiTasksWorker.js b/tests/worker-files/thread/testMultiTasksWorker.js index ace9fea0..f2275269 100644 --- a/tests/worker-files/thread/testMultiTasksWorker.js +++ b/tests/worker-files/thread/testMultiTasksWorker.js @@ -8,9 +8,9 @@ const { module.exports = new ThreadWorker( { - jsonIntegerSerialization: data => jsonIntegerSerialization(data.n), - factorial: data => factorial(data.n), - fibonacci: data => fibonacci(data.n) + jsonIntegerSerialization: (data) => jsonIntegerSerialization(data.n), + factorial: (data) => factorial(data.n), + fibonacci: (data) => fibonacci(data.n) }, { maxInactiveTime: 500, diff --git a/typedoc.mjs b/typedoc.mjs index b9f9cc99..1d74fb4e 100644 --- a/typedoc.mjs +++ b/typedoc.mjs @@ -9,7 +9,7 @@ try { }) const markdownFiles = readdirSync( join(dirname(fileURLToPath(import.meta.url)), 'docs') - ).filter(file => file.endsWith('.md')) + ).filter((file) => file.endsWith('.md')) for (const markdownFile of markdownFiles) { copyFileSync( join(dirname(fileURLToPath(import.meta.url)), 'docs', markdownFile), -- 2.34.1