Skip to content

Commit 1d07768

Browse files
committed
chore(eslint): fix lint errors
1 parent 6345407 commit 1d07768

File tree

10 files changed

+82
-107
lines changed

10 files changed

+82
-107
lines changed

eslint.config.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ const config: ReturnType<typeof defineConfig> = defineConfig(
3030
kazupon: {
3131
ignores: [
3232
'./**/playground/**',
33+
'./packages/shared/**',
3334
'./scripts/**',
3435
'./**/test/**',
3536
'./**/src/**/*.test.ts',
@@ -42,7 +43,7 @@ const config: ReturnType<typeof defineConfig> = defineConfig(
4243
}),
4344
jsdoc({
4445
typescript: 'syntax',
45-
ignores: ['./**/playground/**', './**/spec/**']
46+
ignores: ['./**/playground/**', './**/spec/**', './packages/shared/**']
4647
}),
4748
imports({
4849
typescript: true,
@@ -65,7 +66,8 @@ const config: ReturnType<typeof defineConfig> = defineConfig(
6566
}),
6667
typescript({
6768
parserOptions: {
68-
tsconfigRootDir: import.meta.dirname
69+
tsconfigRootDir: import.meta.dirname,
70+
project: true
6971
},
7072
rules: {
7173
'@typescript-eslint/no-empty-object-type': 'off',

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
"devDependencies": {
4848
"@eslint/compat": "^1.4.1",
4949
"@eslint/markdown": "^7.5.1",
50-
"@kazupon/eslint-config": "^0.37.2",
50+
"@kazupon/eslint-config": "^0.38.0",
5151
"@kazupon/prettier-config": "^0.1.1",
5252
"@types/node": "^24.10.1",
5353
"@typescript/native-preview": "7.0.0-dev.20251108.1",

packages/h3/spec/e2e.spec.ts

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,11 @@
1-
import { exec, spawn } from 'node:child_process'
1+
import { spawn } from 'node:child_process'
22
import path from 'node:path'
33
import { afterEach, describe, expect, test } from 'vitest'
4-
5-
import type { ExecOptions } from 'node:child_process'
6-
7-
export function runCommand(command: string, options?: ExecOptions): Promise<string> {
8-
return new Promise((resolve, reject) => {
9-
exec(
10-
command,
11-
{ timeout: 30_000, ...options, env: { ...process.env, ...options?.env } },
12-
(error, stdout, stderr) => {
13-
if (error) {
14-
reject(new Error(`Command failed: ${command}\n${stderr}\n${error.message}`))
15-
} else {
16-
resolve(stdout.toString())
17-
}
18-
}
19-
)
20-
})
21-
}
22-
23-
const delay = (ms: number) => new Promise(resolve => setTimeout(resolve, ms))
4+
import { delay, runCommand } from '../../shared/helper.ts'
245

256
let serve: ReturnType<typeof spawn> | null = null
267

27-
afterEach(async () => {
8+
afterEach(() => {
289
serve?.kill()
2910
})
3011

packages/h3/spec/integration.spec.ts

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { eventHandler, H3 } from 'h3'
22
import { afterEach, describe, expect, test, vi } from 'vitest'
3+
import { delay as sleep } from '../../shared/helper.ts'
34

45
import {
56
detectLocaleFromAcceptLanguageHeader,
@@ -88,15 +89,15 @@ describe('custom locale detection', () => {
8889
expect(body).toEqual({ message: 'こんにちは, h3' })
8990
})
9091

91-
test('detect with async loading', async () => {
92-
const sleep = (ms: number) => new Promise(resolve => setTimeout(resolve, ms))
93-
94-
const loader = (path: string) => import(path).then(m => m.default || m)
95-
const messages: Record<string, () => ReturnType<typeof loader>> = {
96-
en: () => loader('./fixtures/en.json'),
97-
ja: () => loader('./fixtures/ja.json')
98-
}
92+
const messages: Record<
93+
string,
94+
() => Promise<typeof import('./fixtures/en.json') | typeof import('./fixtures/ja.json')>
95+
> = {
96+
en: () => import('./fixtures/en.json', { with: { type: 'json' } }).then(m => m.default),
97+
ja: () => import('./fixtures/ja.json', { with: { type: 'json' } }).then(m => m.default)
98+
}
9999

100+
test('detect with async loading', async () => {
100101
// async locale detector
101102
const localeDetector = async (
102103
event: H3Event,
@@ -152,14 +153,6 @@ describe('custom locale detection', () => {
152153
})
153154

154155
test('detect with async parallel loading', async () => {
155-
const sleep = (ms: number) => new Promise(resolve => setTimeout(resolve, ms))
156-
157-
const loader = (path: string) => import(path).then(m => m.default || m)
158-
const messages: Record<string, () => ReturnType<typeof loader>> = {
159-
en: () => loader('./fixtures/en.json'),
160-
ja: () => loader('./fixtures/ja.json')
161-
}
162-
163156
// async locale detector
164157
const localeDetector = async (
165158
event: H3Event,
@@ -206,14 +199,13 @@ describe('custom locale detection', () => {
206199
message: 'こんにちは, h3'
207200
}
208201
}
202+
209203
// request in parallel
210-
const resList = await Promise.all(
211-
['en', 'ja'].map(locale =>
212-
app
213-
.fetch(new Request(`http://localhost/?locale=${locale}`))
214-
// @ts-ignore
215-
.then(res => res.json())
216-
)
204+
const resList: { message: string }[] = await Promise.all(
205+
['en', 'ja'].map(async (locale): Promise<{ message: string }> => {
206+
const res: Response = await app.request(`/?locale=${locale}`)
207+
return (await res.json()) as { message: string }
208+
})
217209
)
218210
expect(resList).toEqual([translated['en'], translated['ja']])
219211
})

packages/h3/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,9 +418,11 @@ export async function useTranslation<
418418
context[SYMBOL_I18N].locale = locale
419419

420420
function translate(key: string, ...args: unknown[]): string {
421+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call -- NOTE(kazupon): generic type
421422
const [_, options] = parseTranslateArgs(key, ...args)
422423
const [arg2] = args
423424

425+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment -- NOTE(kazupon): generic type
424426
const result = Reflect.apply(_translate, null, [
425427
context[SYMBOL_I18N]!,
426428
key,

packages/hono/spec/e2e.spec.ts

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,11 @@
1-
import { exec, spawn } from 'node:child_process'
1+
import { spawn } from 'node:child_process'
22
import path from 'node:path'
33
import { afterEach, describe, expect, test } from 'vitest'
4-
5-
import type { ExecOptions } from 'node:child_process'
6-
7-
export function runCommand(command: string, options?: ExecOptions): Promise<string> {
8-
return new Promise((resolve, reject) => {
9-
exec(
10-
command,
11-
{ timeout: 30_000, ...options, env: { ...process.env, ...options?.env } },
12-
(error, stdout, stderr) => {
13-
if (error) {
14-
reject(new Error(`Command failed: ${command}\n${stderr}\n${error.message}`))
15-
} else {
16-
resolve(stdout.toString())
17-
}
18-
}
19-
)
20-
})
21-
}
22-
23-
const delay = (ms: number) => new Promise(resolve => setTimeout(resolve, ms))
4+
import { delay, runCommand } from '../../shared/helper.ts'
245

256
let serve: ReturnType<typeof spawn> | null = null
267

27-
afterEach(async () => {
8+
afterEach(() => {
289
serve?.kill()
2910
})
3011

packages/hono/spec/integration.spec.ts

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Hono } from 'hono'
22
import { afterEach, describe, expect, test, vi } from 'vitest'
3+
import { delay as sleep } from '../../shared/helper.ts'
34
import {
45
defineI18nMiddleware,
56
detectLocaleFromAcceptLanguageHeader,
@@ -79,15 +80,15 @@ describe('custom locale detection', () => {
7980
expect(await res.json()).toEqual({ message: 'こんにちは, hono' })
8081
})
8182

82-
test('detect with async loading', async () => {
83-
const sleep = (ms: number) => new Promise(resolve => setTimeout(resolve, ms))
84-
85-
const loader = (path: string) => import(path).then(m => m.default || m)
86-
const messages: Record<string, () => ReturnType<typeof loader>> = {
87-
en: () => loader('./fixtures/en.json'),
88-
ja: () => loader('./fixtures/ja.json')
89-
}
83+
const messages: Record<
84+
string,
85+
() => Promise<typeof import('./fixtures/en.json') | typeof import('./fixtures/ja.json')>
86+
> = {
87+
en: () => import('./fixtures/en.json', { with: { type: 'json' } }).then(m => m.default),
88+
ja: () => import('./fixtures/ja.json', { with: { type: 'json' } }).then(m => m.default)
89+
}
9090

91+
test('detect with async loading', async () => {
9192
// async locale detector
9293
const localeDetector = async (ctx: Context, i18n: CoreContext<string, DefineLocaleMessage>) => {
9394
const locale = getQueryLocale(ctx.req.raw).toString()
@@ -135,14 +136,6 @@ describe('custom locale detection', () => {
135136
})
136137

137138
test('detect with async parallel loading', async () => {
138-
const sleep = (ms: number) => new Promise(resolve => setTimeout(resolve, ms))
139-
140-
const loader = (path: string) => import(path).then(m => m.default || m)
141-
const messages: Record<string, () => ReturnType<typeof loader>> = {
142-
en: () => loader('./fixtures/en.json'),
143-
ja: () => loader('./fixtures/ja.json')
144-
}
145-
146139
// async locale detector
147140
const localeDetector = async (ctx: Context, i18n: CoreContext<string, DefineLocaleMessage>) => {
148141
const locale = getQueryLocale(ctx.req.raw).toString()
@@ -181,14 +174,13 @@ describe('custom locale detection', () => {
181174
message: 'こんにちは, hono'
182175
}
183176
}
177+
184178
// request in parallel
185-
const resList = await Promise.all(
186-
['en', 'ja'].map(locale =>
187-
app
188-
.request(`/?locale=${locale}`)
189-
// @ts-ignore
190-
.then(res => res.json())
191-
)
179+
const resList: { message: string }[] = await Promise.all(
180+
['en', 'ja'].map(async (locale): Promise<{ message: string }> => {
181+
const res: Response = await app.request(`/?locale=${locale}`)
182+
return (await res.json()) as { message: string }
183+
})
192184
)
193185
expect(resList).toEqual([translated['en'], translated['ja']])
194186
})

packages/hono/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,9 +367,11 @@ export async function useTranslation<
367367
i18n.locale = locale
368368

369369
function translate(key: string, ...args: unknown[]): string {
370+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call -- NOTE(kazupon): generic type
370371
const [_, options] = parseTranslateArgs(key, ...args)
371372
const [arg2] = args
372373

374+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment -- NOTE(kazupon): generic type
373375
const result = Reflect.apply(_translate, null, [
374376
i18n,
375377
key,

packages/shared/helper.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { exec } from 'node:child_process'
2+
3+
import type { ExecOptions } from 'node:child_process'
4+
5+
export function runCommand(command: string, options?: ExecOptions): Promise<string> {
6+
return new Promise((resolve, reject) => {
7+
exec(
8+
command,
9+
{ timeout: 30_000, ...options, env: { ...process.env, ...options?.env } },
10+
(error, stdout, stderr) => {
11+
if (error) {
12+
reject(new Error(`Command failed: ${command}\n${stderr.toString()}\n${error.message}`))
13+
} else {
14+
resolve(stdout.toString())
15+
}
16+
}
17+
)
18+
})
19+
}
20+
21+
export function delay(ms: number) {
22+
return new Promise(resolve => setTimeout(resolve, ms))
23+
}

pnpm-lock.yaml

Lines changed: 14 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)