From 063dffc29d722ccc7775e5e6c3e287f148e3b647 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ari=20Perkki=C3=B6?= Date: Thu, 13 Jun 2024 12:31:56 +0300 Subject: [PATCH] chore: enable `@typescript-eslint/consistent-type-imports` rule --- benchmark/isolate-benchmark.bench.ts | 2 +- eslint.config.js | 8 ++++++++ src/entry/process.ts | 10 +++++----- src/entry/worker.ts | 12 ++++++------ src/index.ts | 22 +++++++++++----------- src/runtime/process-worker.ts | 10 +++++----- src/runtime/thread-worker.ts | 4 ++-- test/task-queue.test.ts | 2 +- 8 files changed, 39 insertions(+), 31 deletions(-) diff --git a/benchmark/isolate-benchmark.bench.ts b/benchmark/isolate-benchmark.bench.ts index 80a0adf..ec18576 100644 --- a/benchmark/isolate-benchmark.bench.ts +++ b/benchmark/isolate-benchmark.bench.ts @@ -2,7 +2,7 @@ import { bench } from 'vitest' import { cpus } from 'node:os' import { Worker } from 'node:worker_threads' import { fork } from 'node:child_process' -import Tinypool, { Options } from '../dist/index' +import Tinypool, { type Options } from '../dist/index' const THREADS = cpus().length - 1 const ROUNDS = THREADS * 10 diff --git a/eslint.config.js b/eslint.config.js index 6162649..91bf336 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -33,6 +33,14 @@ export default defineConfig([ 'error', { varsIgnorePattern: '^_' }, ], + '@typescript-eslint/consistent-type-imports': [ + 'error', + { + prefer: 'type-imports', + fixStyle: 'inline-type-imports', + disallowTypeAnnotations: false, + }, + ], }, }, { diff --git a/src/entry/process.ts b/src/entry/process.ts index 8acf4ad..77a1a66 100644 --- a/src/entry/process.ts +++ b/src/entry/process.ts @@ -1,10 +1,10 @@ import { stderr, stdout } from '../utils' import { - ReadyMessage, - RequestMessage, - ResponseMessage, - StartupMessage, - TinypoolWorkerMessage, + type ReadyMessage, + type RequestMessage, + type ResponseMessage, + type StartupMessage, + type TinypoolWorkerMessage, } from '../common' import { getHandler, throwInNextTick } from './utils' diff --git a/src/entry/worker.ts b/src/entry/worker.ts index d8d85be..6e41f8e 100644 --- a/src/entry/worker.ts +++ b/src/entry/worker.ts @@ -1,15 +1,15 @@ import { parentPort, - MessagePort, + type MessagePort, receiveMessageOnPort, workerData as tinypoolData, } from 'node:worker_threads' import { - ReadyMessage, - RequestMessage, - ResponseMessage, - StartupMessage, - TinypoolData, + type ReadyMessage, + type RequestMessage, + type ResponseMessage, + type StartupMessage, + type TinypoolData, kResponseCountField, kRequestCountField, isMovable, diff --git a/src/index.ts b/src/index.ts index 6202a47..e4dd4af 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,6 +1,6 @@ import { MessageChannel, - MessagePort, + type MessagePort, receiveMessageOnPort, } from 'node:worker_threads' import { once, EventEmitterAsyncResource } from 'node:events' @@ -13,25 +13,25 @@ import { performance } from 'node:perf_hooks' import { readFileSync } from 'node:fs' import { amount as physicalCpuCount } from './physicalCpuCount' import { - ReadyMessage, - RequestMessage, - ResponseMessage, - StartupMessage, + type ReadyMessage, + type RequestMessage, + type ResponseMessage, + type StartupMessage, kResponseCountField, kRequestCountField, kFieldCount, - Transferable, - Task, - TaskQueue, + type Transferable, + type Task, + type TaskQueue, kQueueOptions, isTransferable, markMovable, isMovable, kTransferable, kValue, - TinypoolData, - TinypoolWorker, - TinypoolChannel, + type TinypoolData, + type TinypoolWorker, + type TinypoolChannel, } from './common' import ThreadWorker from './runtime/thread-worker' import ProcessWorker from './runtime/process-worker' diff --git a/src/runtime/process-worker.ts b/src/runtime/process-worker.ts index 316ff72..eadc2cb 100644 --- a/src/runtime/process-worker.ts +++ b/src/runtime/process-worker.ts @@ -1,10 +1,10 @@ -import { ChildProcess, fork } from 'node:child_process' -import { MessagePort, TransferListItem } from 'node:worker_threads' +import { type ChildProcess, fork } from 'node:child_process' +import { MessagePort, type TransferListItem } from 'node:worker_threads' import { fileURLToPath } from 'node:url' import { - TinypoolChannel, - TinypoolWorker, - TinypoolWorkerMessage, + type TinypoolChannel, + type TinypoolWorker, + type TinypoolWorkerMessage, } from '../common' const __tinypool_worker_message__ = true diff --git a/src/runtime/thread-worker.ts b/src/runtime/thread-worker.ts index 71303e4..cd7f9a2 100644 --- a/src/runtime/thread-worker.ts +++ b/src/runtime/thread-worker.ts @@ -1,6 +1,6 @@ import { fileURLToPath } from 'node:url' -import { TransferListItem, Worker } from 'node:worker_threads' -import { TinypoolWorker } from '../common' +import { type TransferListItem, Worker } from 'node:worker_threads' +import { type TinypoolWorker } from '../common' export default class ThreadWorker implements TinypoolWorker { name = 'ThreadWorker' diff --git a/test/task-queue.test.ts b/test/task-queue.test.ts index 716d9be..1c2e8f1 100644 --- a/test/task-queue.test.ts +++ b/test/task-queue.test.ts @@ -1,5 +1,5 @@ import { dirname, resolve } from 'node:path' -import { Tinypool, Task, TaskQueue } from 'tinypool' +import { Tinypool, type Task, type TaskQueue } from 'tinypool' import { fileURLToPath } from 'node:url' const __dirname = dirname(fileURLToPath(import.meta.url))