diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 08ec00fdc..baccdd5cf 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -7,3 +7,5 @@ RUN curl -fsSL https://gist.githubusercontent.com/LukeChannings/09d53f5c36439104 # Install Bun ENV BUN_INSTALL=/usr/local RUN curl -fsSL https://bun.sh/install | bash + +WORKDIR /hono diff --git a/.devcontainer/docker-compose.yml b/.devcontainer/docker-compose.yml new file mode 100644 index 000000000..6222a4ead --- /dev/null +++ b/.devcontainer/docker-compose.yml @@ -0,0 +1,18 @@ +version: '3' + +services: + hono: + build: . + container_name: hono + volumes: + - ../:/hono + networks: + - hono + command: bash + stdin_open: true + tty: true + restart: 'no' + +networks: + hono: + driver: bridge diff --git a/bun.lockb b/bun.lockb index 50d8fc4c9..9ff4f09df 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/deno_dist/adapter/deno/serve-static.ts b/deno_dist/adapter/deno/serve-static.ts index 8cecd4fc5..7b572b9ca 100644 --- a/deno_dist/adapter/deno/serve-static.ts +++ b/deno_dist/adapter/deno/serve-static.ts @@ -34,7 +34,9 @@ export const serveStatic = ( defaultDocument: DEFAULT_DOCUMENT, }) - if (!path) return await next() + if (!path) { + return await next() + } path = `./${path}` diff --git a/deno_dist/client/client.ts b/deno_dist/client/client.ts index b12f62c60..4b1e6fd72 100644 --- a/deno_dist/client/client.ts +++ b/deno_dist/client/client.ts @@ -8,7 +8,9 @@ import { deepMerge, mergePath, removeIndexString, replaceUrlParam } from './util const createProxy = (callback: Callback, path: string[]) => { const proxy: unknown = new Proxy(() => {}, { get(_obj, key) { - if (typeof key !== 'string' || key === 'then') return undefined + if (typeof key !== 'string' || key === 'then') { + return undefined + } return createProxy(callback, [...path, key]) }, apply(_1, _2, args) { @@ -91,7 +93,9 @@ class ClientRequestImpl { headerValues['Cookie'] = cookies.join(',') } - if (this.cType) headerValues['Content-Type'] = this.cType + if (this.cType) { + headerValues['Content-Type'] = this.cType + } const headers = new Headers(headerValues ?? undefined) let url = this.url diff --git a/deno_dist/helper/accepts/accepts.ts b/deno_dist/helper/accepts/accepts.ts index e0b1c5f44..9800874c0 100644 --- a/deno_dist/helper/accepts/accepts.ts +++ b/deno_dist/helper/accepts/accepts.ts @@ -63,7 +63,9 @@ export const defaultMatch = (accepts: Accept[], config: acceptsConfig) => { */ export const accepts = (c: Context, options: acceptsOptions) => { const acceptHeader = c.req.header(options.header) - if (!acceptHeader) return options.default + if (!acceptHeader) { + return options.default + } const accepts = parseAccept(acceptHeader) const match = options.match || defaultMatch diff --git a/deno_dist/helper/adapter/index.ts b/deno_dist/helper/adapter/index.ts index 040c07724..abb5ece13 100644 --- a/deno_dist/helper/adapter/index.ts +++ b/deno_dist/helper/adapter/index.ts @@ -34,12 +34,24 @@ export const getRuntimeKey = () => { // eslint-disable-next-line @typescript-eslint/no-explicit-any const global = globalThis as any - if (global?.Deno !== undefined) return 'deno' - if (global?.Bun !== undefined) return 'bun' - if (typeof global?.WebSocketPair === 'function') return 'workerd' - if (typeof global?.EdgeRuntime === 'string') return 'edge-light' - if (global?.fastly !== undefined) return 'fastly' - if (global?.process?.release?.name === 'node') return 'node' + if (global?.Deno !== undefined) { + return 'deno' + } + if (global?.Bun !== undefined) { + return 'bun' + } + if (typeof global?.WebSocketPair === 'function') { + return 'workerd' + } + if (typeof global?.EdgeRuntime === 'string') { + return 'edge-light' + } + if (global?.fastly !== undefined) { + return 'fastly' + } + if (global?.process?.release?.name === 'node') { + return 'node' + } return 'other' } diff --git a/deno_dist/helper/cookie/index.ts b/deno_dist/helper/cookie/index.ts index 2d4ce36e2..b75d7f372 100644 --- a/deno_dist/helper/cookie/index.ts +++ b/deno_dist/helper/cookie/index.ts @@ -15,11 +15,15 @@ interface GetSignedCookie { export const getCookie: GetCookie = (c, key?) => { const cookie = c.req.raw.headers.get('Cookie') if (typeof key === 'string') { - if (!cookie) return undefined + if (!cookie) { + return undefined + } const obj = parse(cookie, key) return obj[key] } - if (!cookie) return {} + if (!cookie) { + return {} + } const obj = parse(cookie) // eslint-disable-next-line @typescript-eslint/no-explicit-any return obj as any @@ -28,11 +32,15 @@ export const getCookie: GetCookie = (c, key?) => { export const getSignedCookie: GetSignedCookie = async (c, secret, key?) => { const cookie = c.req.raw.headers.get('Cookie') if (typeof key === 'string') { - if (!cookie) return undefined + if (!cookie) { + return undefined + } const obj = await parseSigned(cookie, secret, key) return obj[key] } - if (!cookie) return {} + if (!cookie) { + return {} + } const obj = await parseSigned(cookie, secret) // eslint-disable-next-line @typescript-eslint/no-explicit-any return obj as any diff --git a/deno_dist/helper/ssg/index.ts b/deno_dist/helper/ssg/index.ts index 4ee486212..c32e391f2 100644 --- a/deno_dist/helper/ssg/index.ts +++ b/deno_dist/helper/ssg/index.ts @@ -120,7 +120,9 @@ export const fetchRoutesContent = async < const baseURL = 'http://localhost' for (const route of inspectRoutes(app)) { - if (route.isMiddleware) continue + if (route.isMiddleware) { + continue + } // GET Route Info const thisRouteBaseURL = new URL(route.path, baseURL).toString() @@ -128,13 +130,17 @@ export const fetchRoutesContent = async < let forGetInfoURLRequest = new Request(thisRouteBaseURL) as AddedSSGDataRequest if (beforeRequestHook) { const maybeRequest = beforeRequestHook(forGetInfoURLRequest) - if (!maybeRequest) continue + if (!maybeRequest) { + continue + } forGetInfoURLRequest = maybeRequest as unknown as AddedSSGDataRequest } await app.fetch(forGetInfoURLRequest) if (!forGetInfoURLRequest.ssgParams) { - if (isDynamicRoute(route.path)) continue + if (isDynamicRoute(route.path)) { + continue + } forGetInfoURLRequest.ssgParams = [{}] } @@ -143,7 +149,9 @@ export const fetchRoutesContent = async < let response = await app.request(replacedUrlParam, forGetInfoURLRequest) if (afterResponseHook) { const maybeResponse = afterResponseHook(response) - if (!maybeResponse) continue + if (!maybeResponse) { + continue + } response = maybeResponse } const mimeType = response.headers.get('Content-Type')?.split(';')[0] || 'text/plain' diff --git a/deno_dist/hono-base.ts b/deno_dist/hono-base.ts index 292ebf53e..1f13ef19f 100644 --- a/deno_dist/hono-base.ts +++ b/deno_dist/hono-base.ts @@ -130,7 +130,9 @@ class Hono< // Implementation of app.on(method, path, ...handlers[]) this.on = (method: string | string[], path: string | string[], ...handlers: H[]) => { - if (!method) return this + if (!method) { + return this + } for (const p of [path].flat()) { this.#path = p for (const m of [method].flat()) { @@ -188,7 +190,9 @@ class Hono< ): Hono> & S, BasePath> { const subApp = this.basePath(path) - if (!app) return subApp + if (!app) { + return subApp + } app.routes.map((r) => { let handler @@ -274,7 +278,9 @@ class Hono< ...optionsArray ) - if (res) return res + if (res) { + return res + } await next() } @@ -295,7 +301,9 @@ class Hono< } private handleError(err: unknown, c: Context) { - if (err instanceof Error) return this.errorHandler(err, c) + if (err instanceof Error) { + return this.errorHandler(err, c) + } throw err } @@ -325,7 +333,9 @@ class Hono< let res: ReturnType try { res = matchResult[0][0][0][0](c, async () => {}) - if (!res) return this.notFoundHandler(c) + if (!res) { + return this.notFoundHandler(c) + } } catch (err) { return this.handleError(err, c) } diff --git a/deno_dist/middleware/jsx-renderer/index.ts b/deno_dist/middleware/jsx-renderer/index.ts index 2916d0b3c..f43f2e594 100644 --- a/deno_dist/middleware/jsx-renderer/index.ts +++ b/deno_dist/middleware/jsx-renderer/index.ts @@ -67,7 +67,9 @@ export const jsxRenderer = ( ): MiddlewareHandler => function jsxRenderer(c, next) { const parentLayout = c.getLayout() - if (!parentLayout && component) c.setLayout(component) + if (!parentLayout && component) { + c.setLayout(component) + } /* eslint-disable @typescript-eslint/no-explicit-any */ c.setRenderer(createRenderer(c, component, options) as any) diff --git a/deno_dist/request.ts b/deno_dist/request.ts index cdde94c3d..d68206c59 100644 --- a/deno_dist/request.ts +++ b/deno_dist/request.ts @@ -161,7 +161,9 @@ export class HonoRequest

{ header(name: string): string | undefined header(): Record header(name?: string) { - if (name) return this.raw.headers.get(name.toLowerCase()) ?? undefined + if (name) { + return this.raw.headers.get(name.toLowerCase()) ?? undefined + } const headerData: Record = {} this.raw.headers.forEach((value, key) => { @@ -181,7 +183,9 @@ export class HonoRequest

{ * @see https://hono.dev/api/request#parsebody */ async parseBody(options?: ParseBodyOptions): Promise { - if (this.bodyCache.parsedBody) return this.bodyCache.parsedBody as T + if (this.bodyCache.parsedBody) { + return this.bodyCache.parsedBody as T + } const parsedBody = await parseBody(this, options) this.bodyCache.parsedBody = parsedBody return parsedBody @@ -190,7 +194,9 @@ export class HonoRequest

{ private cachedBody = (key: keyof Body) => { const { bodyCache, raw } = this const cachedBody = bodyCache[key] - if (cachedBody) return cachedBody + if (cachedBody) { + return cachedBody + } /** * If an arrayBuffer cache is exist, * use it for creating a text, json, and others. diff --git a/deno_dist/router/reg-exp-router/router.ts b/deno_dist/router/reg-exp-router/router.ts index 4c65a55b2..b43e8280f 100644 --- a/deno_dist/router/reg-exp-router/router.ts +++ b/deno_dist/router/reg-exp-router/router.ts @@ -137,7 +137,9 @@ export class RegExpRouter implements Router { throw new Error(MESSAGE_MATCHER_IS_ALREADY_BUILT) } - if (methodNames.indexOf(method) === -1) methodNames.push(method) + if (methodNames.indexOf(method) === -1) { + methodNames.push(method) + } if (!middleware[method]) { ;[middleware, routes].forEach((handlerMap) => { handlerMap[method] = {} diff --git a/deno_dist/router/trie-router/node.ts b/deno_dist/router/trie-router/node.ts index cb6c46a43..fd5b16bfb 100644 --- a/deno_dist/router/trie-router/node.ts +++ b/deno_dist/router/trie-router/node.ts @@ -53,7 +53,9 @@ export class Node { parentPatterns.push(...curNode.patterns) curNode = curNode.children[p] const pattern = getPattern(p) - if (pattern) possibleKeys.push(pattern[1]) + if (pattern) { + possibleKeys.push(pattern[1]) + } continue } @@ -160,7 +162,9 @@ export class Node { continue } - if (part === '') continue + if (part === '') { + continue + } const [key, name, matcher] = pattern diff --git a/deno_dist/utils/cookie.ts b/deno_dist/utils/cookie.ts index d64641deb..13b688978 100644 --- a/deno_dist/utils/cookie.ts +++ b/deno_dist/utils/cookie.ts @@ -36,8 +36,9 @@ const verifySignature = async ( try { const signatureBinStr = atob(base64Signature) const signature = new Uint8Array(signatureBinStr.length) - for (let i = 0, len = signatureBinStr.length; i < len; i++) + for (let i = 0, len = signatureBinStr.length; i < len; i++) { signature[i] = signatureBinStr.charCodeAt(i) + } return await crypto.subtle.verify(algorithm, secret, signature, new TextEncoder().encode(value)) } catch (e) { return false @@ -60,16 +61,22 @@ export const parse = (cookie: string, name?: string): Cookie => { return pairs.reduce((parsedCookie, pairStr) => { pairStr = pairStr.trim() const valueStartPos = pairStr.indexOf('=') - if (valueStartPos === -1) return parsedCookie + if (valueStartPos === -1) { + return parsedCookie + } const cookieName = pairStr.substring(0, valueStartPos).trim() - if ((name && name !== cookieName) || !validCookieNameRegEx.test(cookieName)) return parsedCookie + if ((name && name !== cookieName) || !validCookieNameRegEx.test(cookieName)) { + return parsedCookie + } let cookieValue = pairStr.substring(valueStartPos + 1).trim() - if (cookieValue.startsWith('"') && cookieValue.endsWith('"')) + if (cookieValue.startsWith('"') && cookieValue.endsWith('"')) { cookieValue = cookieValue.slice(1, -1) - if (validCookieValueRegEx.test(cookieValue)) + } + if (validCookieValueRegEx.test(cookieValue)) { parsedCookie[cookieName] = decodeURIComponent_(cookieValue) + } return parsedCookie }, {} as Cookie) @@ -85,11 +92,15 @@ export const parseSigned = async ( for (const [key, value] of Object.entries(parse(cookie, name))) { const signatureStartPos = value.lastIndexOf('.') - if (signatureStartPos < 1) continue + if (signatureStartPos < 1) { + continue + } const signedValue = value.substring(0, signatureStartPos) const signature = value.substring(signatureStartPos + 1) - if (signature.length !== 44 || !signature.endsWith('=')) continue + if (signature.length !== 44 || !signature.endsWith('=')) { + continue + } const isVerified = await verifySignature(signature, signedValue, secretKey) parsedCookie[key] = isVerified ? signedValue : false diff --git a/deno_dist/utils/filepath.ts b/deno_dist/utils/filepath.ts index 8ac30685a..3a9edefd0 100644 --- a/deno_dist/utils/filepath.ts +++ b/deno_dist/utils/filepath.ts @@ -6,7 +6,9 @@ type FilePathOptions = { export const getFilePath = (options: FilePathOptions): string | undefined => { let filename = options.filename - if (/(?:^|[\/\\])\.\.(?:$|[\/\\])/.test(filename)) return + if (/(?:^|[\/\\])\.\.(?:$|[\/\\])/.test(filename)) { + return + } let root = options.root || '' const defaultDocument = options.defaultDocument || 'index.html' diff --git a/deno_dist/utils/mime.ts b/deno_dist/utils/mime.ts index 07a8d25c9..76374efaf 100644 --- a/deno_dist/utils/mime.ts +++ b/deno_dist/utils/mime.ts @@ -1,7 +1,9 @@ export const getMimeType = (filename: string): string | undefined => { const regexp = /\.([a-zA-Z0-9]+?)$/ const match = filename.match(regexp) - if (!match) return + if (!match) { + return + } let mimeType = mimes[match[1]] if ((mimeType && mimeType.startsWith('text')) || mimeType === 'application/json') { mimeType += '; charset=utf-8' diff --git a/deno_dist/utils/url.ts b/deno_dist/utils/url.ts index 785948ee0..86daf2bf5 100644 --- a/deno_dist/utils/url.ts +++ b/deno_dist/utils/url.ts @@ -126,7 +126,9 @@ export const checkOptionalParameter = (path: string): string[] | null => { in other cases it will return null */ - if (!path.match(/\:.+\?$/)) return null + if (!path.match(/\:.+\?$/)) { + return null + } const segments = path.split('/') const results: string[] = [] diff --git a/docs/CONTRIBUTING.md b/docs/CONTRIBUTING.md index 5be42d90f..f245c6aee 100644 --- a/docs/CONTRIBUTING.md +++ b/docs/CONTRIBUTING.md @@ -52,3 +52,11 @@ It may be under the "honojs organization" and distributed in the `@honojs` names The monorepo "[honojs/middleware](https://github.com/honojs/middleware)" manages these middleware. If you want to do it, create the issue about your middleware. + +## Local Development + +``` +git clone git@github.com:honojs/hono.git && cd hono/.devcontainer && yarn install +docker compose up -d --build +docker compose exec hono bash +``` \ No newline at end of file diff --git a/package.json b/package.json index 6dac0f4ee..c130deea6 100644 --- a/package.json +++ b/package.json @@ -507,7 +507,7 @@ ], "devDependencies": { "@cloudflare/workers-types": "^4.20231121.0", - "@hono/eslint-config": "^0.0.3", + "@hono/eslint-config": "^0.0.4", "@hono/node-server": "^1.3.3", "@types/crypto-js": "^4.1.1", "@types/glob": "^8.0.0", diff --git a/runtime_tests/lambda/index.test.ts b/runtime_tests/lambda/index.test.ts index e674e7706..fdc2c0c1d 100644 --- a/runtime_tests/lambda/index.test.ts +++ b/runtime_tests/lambda/index.test.ts @@ -133,7 +133,9 @@ describe('AWS Lambda Adapter for Hono', () => { const validCookies = getCookie(c, testCookie1.key) === testCookie1.value && getCookie(c, testCookie2.key) === testCookie2.value - if (!validCookies) return c.text('Invalid Cookies') + if (!validCookies) { + return c.text('Invalid Cookies') + } return c.text('Valid Cookies') }) diff --git a/src/adapter/aws-lambda/handler.ts b/src/adapter/aws-lambda/handler.ts index 9dafd4292..e340289be 100644 --- a/src/adapter/aws-lambda/handler.ts +++ b/src/adapter/aws-lambda/handler.ts @@ -204,7 +204,9 @@ const createRequest = (event: LambdaEvent) => { const headers = new Headers() getCookies(event, headers) for (const [k, v] of Object.entries(event.headers)) { - if (v) headers.set(k, v) + if (v) { + headers.set(k, v) + } } const method = isProxyEventV2(event) ? event.requestContext.http.method : event.httpMethod diff --git a/src/adapter/bun/serve-static.ts b/src/adapter/bun/serve-static.ts index 479718f9a..77946c8ae 100644 --- a/src/adapter/bun/serve-static.ts +++ b/src/adapter/bun/serve-static.ts @@ -36,7 +36,9 @@ export const serveStatic = ( defaultDocument: DEFAULT_DOCUMENT, }) - if (!path) return await next() + if (!path) { + return await next() + } path = `./${path}` diff --git a/src/adapter/cloudflare-workers/serve-static.ts b/src/adapter/cloudflare-workers/serve-static.ts index 801b70522..4e5aabca8 100644 --- a/src/adapter/cloudflare-workers/serve-static.ts +++ b/src/adapter/cloudflare-workers/serve-static.ts @@ -36,7 +36,9 @@ export const serveStatic = ( defaultDocument: DEFAULT_DOCUMENT, }) - if (!path) return await next() + if (!path) { + return await next() + } const content = await getContentFromKVAsset(path, { manifest: options.manifest, diff --git a/src/adapter/deno/serve-static.ts b/src/adapter/deno/serve-static.ts index 8add7e715..f0110df60 100644 --- a/src/adapter/deno/serve-static.ts +++ b/src/adapter/deno/serve-static.ts @@ -34,7 +34,9 @@ export const serveStatic = ( defaultDocument: DEFAULT_DOCUMENT, }) - if (!path) return await next() + if (!path) { + return await next() + } path = `./${path}` diff --git a/src/client/client.test.ts b/src/client/client.test.ts index 57b101ca3..de6c9e6d2 100644 --- a/src/client/client.test.ts +++ b/src/client/client.test.ts @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/no-unused-vars */ /* eslint-disable @typescript-eslint/no-explicit-any */ /* eslint-disable @typescript-eslint/ban-ts-comment */ import { rest } from 'msw' diff --git a/src/client/client.ts b/src/client/client.ts index a9b18d33e..ada4f2210 100644 --- a/src/client/client.ts +++ b/src/client/client.ts @@ -8,7 +8,9 @@ import { deepMerge, mergePath, removeIndexString, replaceUrlParam } from './util const createProxy = (callback: Callback, path: string[]) => { const proxy: unknown = new Proxy(() => {}, { get(_obj, key) { - if (typeof key !== 'string' || key === 'then') return undefined + if (typeof key !== 'string' || key === 'then') { + return undefined + } return createProxy(callback, [...path, key]) }, apply(_1, _2, args) { @@ -91,7 +93,9 @@ class ClientRequestImpl { headerValues['Cookie'] = cookies.join(',') } - if (this.cType) headerValues['Content-Type'] = this.cType + if (this.cType) { + headerValues['Content-Type'] = this.cType + } const headers = new Headers(headerValues ?? undefined) let url = this.url diff --git a/src/helper/accepts/accepts.ts b/src/helper/accepts/accepts.ts index 123a690b3..4a8338e66 100644 --- a/src/helper/accepts/accepts.ts +++ b/src/helper/accepts/accepts.ts @@ -63,7 +63,9 @@ export const defaultMatch = (accepts: Accept[], config: acceptsConfig) => { */ export const accepts = (c: Context, options: acceptsOptions) => { const acceptHeader = c.req.header(options.header) - if (!acceptHeader) return options.default + if (!acceptHeader) { + return options.default + } const accepts = parseAccept(acceptHeader) const match = options.match || defaultMatch diff --git a/src/helper/adapter/index.ts b/src/helper/adapter/index.ts index 8f45f0897..0df451fd1 100644 --- a/src/helper/adapter/index.ts +++ b/src/helper/adapter/index.ts @@ -34,12 +34,24 @@ export const getRuntimeKey = () => { // eslint-disable-next-line @typescript-eslint/no-explicit-any const global = globalThis as any - if (global?.Deno !== undefined) return 'deno' - if (global?.Bun !== undefined) return 'bun' - if (typeof global?.WebSocketPair === 'function') return 'workerd' - if (typeof global?.EdgeRuntime === 'string') return 'edge-light' - if (global?.fastly !== undefined) return 'fastly' - if (global?.process?.release?.name === 'node') return 'node' + if (global?.Deno !== undefined) { + return 'deno' + } + if (global?.Bun !== undefined) { + return 'bun' + } + if (typeof global?.WebSocketPair === 'function') { + return 'workerd' + } + if (typeof global?.EdgeRuntime === 'string') { + return 'edge-light' + } + if (global?.fastly !== undefined) { + return 'fastly' + } + if (global?.process?.release?.name === 'node') { + return 'node' + } return 'other' } diff --git a/src/helper/cookie/index.test.ts b/src/helper/cookie/index.test.ts index 8cee5859a..d3a2c4e50 100644 --- a/src/helper/cookie/index.test.ts +++ b/src/helper/cookie/index.test.ts @@ -122,7 +122,9 @@ describe('Cookie Middleware', () => { app.get('/cookie', (c) => { const yummyCookie = getCookie(c, 'yummy_cookie') const res = new Response('Good cookie') - if (yummyCookie) res.headers.set('Yummy-Cookie', yummyCookie) + if (yummyCookie) { + res.headers.set('Yummy-Cookie', yummyCookie) + } return res }) diff --git a/src/helper/cookie/index.ts b/src/helper/cookie/index.ts index cd7f638e9..418092ac7 100644 --- a/src/helper/cookie/index.ts +++ b/src/helper/cookie/index.ts @@ -15,11 +15,15 @@ interface GetSignedCookie { export const getCookie: GetCookie = (c, key?) => { const cookie = c.req.raw.headers.get('Cookie') if (typeof key === 'string') { - if (!cookie) return undefined + if (!cookie) { + return undefined + } const obj = parse(cookie, key) return obj[key] } - if (!cookie) return {} + if (!cookie) { + return {} + } const obj = parse(cookie) // eslint-disable-next-line @typescript-eslint/no-explicit-any return obj as any @@ -28,11 +32,15 @@ export const getCookie: GetCookie = (c, key?) => { export const getSignedCookie: GetSignedCookie = async (c, secret, key?) => { const cookie = c.req.raw.headers.get('Cookie') if (typeof key === 'string') { - if (!cookie) return undefined + if (!cookie) { + return undefined + } const obj = await parseSigned(cookie, secret, key) return obj[key] } - if (!cookie) return {} + if (!cookie) { + return {} + } const obj = await parseSigned(cookie, secret) // eslint-disable-next-line @typescript-eslint/no-explicit-any return obj as any diff --git a/src/helper/css/index.test.tsx b/src/helper/css/index.test.tsx index cbe24816c..df8509491 100644 --- a/src/helper/css/index.test.tsx +++ b/src/helper/css/index.test.tsx @@ -12,8 +12,12 @@ import { css, cx, keyframes, viewTransition, rawCssString, Style, createCssConte async function toString( template: JSXNode | Promise | Promise | HtmlEscapedString ) { - if (template instanceof Promise) template = (await template) as HtmlEscapedString - if (template instanceof JSXNode) template = template.toString() as Promise + if (template instanceof Promise) { + template = (await template) as HtmlEscapedString + } + if (template instanceof JSXNode) { + template = template.toString() as Promise + } return resolveCallback(await template, HtmlEscapedCallbackPhase.Stringify, false, template) } diff --git a/src/helper/ssg/index.ts b/src/helper/ssg/index.ts index 721eb9f6d..3c434ad82 100644 --- a/src/helper/ssg/index.ts +++ b/src/helper/ssg/index.ts @@ -120,7 +120,9 @@ export const fetchRoutesContent = async < const baseURL = 'http://localhost' for (const route of inspectRoutes(app)) { - if (route.isMiddleware) continue + if (route.isMiddleware) { + continue + } // GET Route Info const thisRouteBaseURL = new URL(route.path, baseURL).toString() @@ -128,13 +130,17 @@ export const fetchRoutesContent = async < let forGetInfoURLRequest = new Request(thisRouteBaseURL) as AddedSSGDataRequest if (beforeRequestHook) { const maybeRequest = beforeRequestHook(forGetInfoURLRequest) - if (!maybeRequest) continue + if (!maybeRequest) { + continue + } forGetInfoURLRequest = maybeRequest as unknown as AddedSSGDataRequest } await app.fetch(forGetInfoURLRequest) if (!forGetInfoURLRequest.ssgParams) { - if (isDynamicRoute(route.path)) continue + if (isDynamicRoute(route.path)) { + continue + } forGetInfoURLRequest.ssgParams = [{}] } @@ -143,7 +149,9 @@ export const fetchRoutesContent = async < let response = await app.request(replacedUrlParam, forGetInfoURLRequest) if (afterResponseHook) { const maybeResponse = afterResponseHook(response) - if (!maybeResponse) continue + if (!maybeResponse) { + continue + } response = maybeResponse } const mimeType = response.headers.get('Content-Type')?.split(';')[0] || 'text/plain' diff --git a/src/hono-base.ts b/src/hono-base.ts index 8979b9beb..9e92de74e 100644 --- a/src/hono-base.ts +++ b/src/hono-base.ts @@ -130,7 +130,9 @@ class Hono< // Implementation of app.on(method, path, ...handlers[]) this.on = (method: string | string[], path: string | string[], ...handlers: H[]) => { - if (!method) return this + if (!method) { + return this + } for (const p of [path].flat()) { this.#path = p for (const m of [method].flat()) { @@ -188,7 +190,9 @@ class Hono< ): Hono> & S, BasePath> { const subApp = this.basePath(path) - if (!app) return subApp + if (!app) { + return subApp + } app.routes.map((r) => { let handler @@ -274,7 +278,9 @@ class Hono< ...optionsArray ) - if (res) return res + if (res) { + return res + } await next() } @@ -295,7 +301,9 @@ class Hono< } private handleError(err: unknown, c: Context) { - if (err instanceof Error) return this.errorHandler(err, c) + if (err instanceof Error) { + return this.errorHandler(err, c) + } throw err } @@ -325,7 +333,9 @@ class Hono< let res: ReturnType try { res = matchResult[0][0][0][0](c, async () => {}) - if (!res) return this.notFoundHandler(c) + if (!res) { + return this.notFoundHandler(c) + } } catch (err) { return this.handleError(err, c) } diff --git a/src/jsx/hooks/dom.test.tsx b/src/jsx/hooks/dom.test.tsx index a57f0ea9a..11de13d5c 100644 --- a/src/jsx/hooks/dom.test.tsx +++ b/src/jsx/hooks/dom.test.tsx @@ -231,7 +231,9 @@ describe('useDeferredValue()', () => { return (promiseMap[count] ||= new Promise((r) => setTimeout(() => r(count + 1)))) } const ShowCount = ({ count }: { count: number }) => { - if (count === 0) return

0
+ if (count === 0) { + return
0
+ } const c = use(getPromise(count)) return
{c}
diff --git a/src/middleware/jsx-renderer/index.ts b/src/middleware/jsx-renderer/index.ts index 5c5552632..c2bf1eb9f 100644 --- a/src/middleware/jsx-renderer/index.ts +++ b/src/middleware/jsx-renderer/index.ts @@ -67,7 +67,9 @@ export const jsxRenderer = ( ): MiddlewareHandler => function jsxRenderer(c, next) { const parentLayout = c.getLayout() - if (!parentLayout && component) c.setLayout(component) + if (!parentLayout && component) { + c.setLayout(component) + } /* eslint-disable @typescript-eslint/no-explicit-any */ c.setRenderer(createRenderer(c, component, options) as any) diff --git a/src/request.ts b/src/request.ts index 71f2d206a..c82584e2e 100644 --- a/src/request.ts +++ b/src/request.ts @@ -161,7 +161,9 @@ export class HonoRequest

{ header(name: string): string | undefined header(): Record header(name?: string) { - if (name) return this.raw.headers.get(name.toLowerCase()) ?? undefined + if (name) { + return this.raw.headers.get(name.toLowerCase()) ?? undefined + } const headerData: Record = {} this.raw.headers.forEach((value, key) => { @@ -181,7 +183,9 @@ export class HonoRequest

{ * @see https://hono.dev/api/request#parsebody */ async parseBody(options?: ParseBodyOptions): Promise { - if (this.bodyCache.parsedBody) return this.bodyCache.parsedBody as T + if (this.bodyCache.parsedBody) { + return this.bodyCache.parsedBody as T + } const parsedBody = await parseBody(this, options) this.bodyCache.parsedBody = parsedBody return parsedBody @@ -190,7 +194,9 @@ export class HonoRequest

{ private cachedBody = (key: keyof Body) => { const { bodyCache, raw } = this const cachedBody = bodyCache[key] - if (cachedBody) return cachedBody + if (cachedBody) { + return cachedBody + } /** * If an arrayBuffer cache is exist, * use it for creating a text, json, and others. diff --git a/src/router/reg-exp-router/router.ts b/src/router/reg-exp-router/router.ts index 51ab473ec..8e2cf056b 100644 --- a/src/router/reg-exp-router/router.ts +++ b/src/router/reg-exp-router/router.ts @@ -137,7 +137,9 @@ export class RegExpRouter implements Router { throw new Error(MESSAGE_MATCHER_IS_ALREADY_BUILT) } - if (methodNames.indexOf(method) === -1) methodNames.push(method) + if (methodNames.indexOf(method) === -1) { + methodNames.push(method) + } if (!middleware[method]) { ;[middleware, routes].forEach((handlerMap) => { handlerMap[method] = {} diff --git a/src/router/trie-router/node.ts b/src/router/trie-router/node.ts index 5929459de..3f7bd9e2e 100644 --- a/src/router/trie-router/node.ts +++ b/src/router/trie-router/node.ts @@ -53,7 +53,9 @@ export class Node { parentPatterns.push(...curNode.patterns) curNode = curNode.children[p] const pattern = getPattern(p) - if (pattern) possibleKeys.push(pattern[1]) + if (pattern) { + possibleKeys.push(pattern[1]) + } continue } @@ -160,7 +162,9 @@ export class Node { continue } - if (part === '') continue + if (part === '') { + continue + } const [key, name, matcher] = pattern diff --git a/src/utils/cookie.ts b/src/utils/cookie.ts index e654964f7..5d33869b5 100644 --- a/src/utils/cookie.ts +++ b/src/utils/cookie.ts @@ -36,8 +36,9 @@ const verifySignature = async ( try { const signatureBinStr = atob(base64Signature) const signature = new Uint8Array(signatureBinStr.length) - for (let i = 0, len = signatureBinStr.length; i < len; i++) + for (let i = 0, len = signatureBinStr.length; i < len; i++) { signature[i] = signatureBinStr.charCodeAt(i) + } return await crypto.subtle.verify(algorithm, secret, signature, new TextEncoder().encode(value)) } catch (e) { return false @@ -60,16 +61,22 @@ export const parse = (cookie: string, name?: string): Cookie => { return pairs.reduce((parsedCookie, pairStr) => { pairStr = pairStr.trim() const valueStartPos = pairStr.indexOf('=') - if (valueStartPos === -1) return parsedCookie + if (valueStartPos === -1) { + return parsedCookie + } const cookieName = pairStr.substring(0, valueStartPos).trim() - if ((name && name !== cookieName) || !validCookieNameRegEx.test(cookieName)) return parsedCookie + if ((name && name !== cookieName) || !validCookieNameRegEx.test(cookieName)) { + return parsedCookie + } let cookieValue = pairStr.substring(valueStartPos + 1).trim() - if (cookieValue.startsWith('"') && cookieValue.endsWith('"')) + if (cookieValue.startsWith('"') && cookieValue.endsWith('"')) { cookieValue = cookieValue.slice(1, -1) - if (validCookieValueRegEx.test(cookieValue)) + } + if (validCookieValueRegEx.test(cookieValue)) { parsedCookie[cookieName] = decodeURIComponent_(cookieValue) + } return parsedCookie }, {} as Cookie) @@ -85,11 +92,15 @@ export const parseSigned = async ( for (const [key, value] of Object.entries(parse(cookie, name))) { const signatureStartPos = value.lastIndexOf('.') - if (signatureStartPos < 1) continue + if (signatureStartPos < 1) { + continue + } const signedValue = value.substring(0, signatureStartPos) const signature = value.substring(signatureStartPos + 1) - if (signature.length !== 44 || !signature.endsWith('=')) continue + if (signature.length !== 44 || !signature.endsWith('=')) { + continue + } const isVerified = await verifySignature(signature, signedValue, secretKey) parsedCookie[key] = isVerified ? signedValue : false diff --git a/src/utils/filepath.ts b/src/utils/filepath.ts index 8ac30685a..3a9edefd0 100644 --- a/src/utils/filepath.ts +++ b/src/utils/filepath.ts @@ -6,7 +6,9 @@ type FilePathOptions = { export const getFilePath = (options: FilePathOptions): string | undefined => { let filename = options.filename - if (/(?:^|[\/\\])\.\.(?:$|[\/\\])/.test(filename)) return + if (/(?:^|[\/\\])\.\.(?:$|[\/\\])/.test(filename)) { + return + } let root = options.root || '' const defaultDocument = options.defaultDocument || 'index.html' diff --git a/src/utils/mime.ts b/src/utils/mime.ts index 07a8d25c9..76374efaf 100644 --- a/src/utils/mime.ts +++ b/src/utils/mime.ts @@ -1,7 +1,9 @@ export const getMimeType = (filename: string): string | undefined => { const regexp = /\.([a-zA-Z0-9]+?)$/ const match = filename.match(regexp) - if (!match) return + if (!match) { + return + } let mimeType = mimes[match[1]] if ((mimeType && mimeType.startsWith('text')) || mimeType === 'application/json') { mimeType += '; charset=utf-8' diff --git a/src/utils/url.ts b/src/utils/url.ts index 785948ee0..86daf2bf5 100644 --- a/src/utils/url.ts +++ b/src/utils/url.ts @@ -126,7 +126,9 @@ export const checkOptionalParameter = (path: string): string[] | null => { in other cases it will return null */ - if (!path.match(/\:.+\?$/)) return null + if (!path.match(/\:.+\?$/)) { + return null + } const segments = path.split('/') const results: string[] = [] diff --git a/yarn.lock b/yarn.lock index a1892a84b..cc6aeafc6 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1,6 +1,6 @@ # THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. # yarn lockfile v1 -# bun ./bun.lockb --hash: 3995C127B04DDD41-bfdd864d617affd3-E99993CB3734F693-3c066ee99651cb0a +# bun ./bun.lockb --hash: 71DE5A52207AB6DA-7e1bfe1f417d1f54-AEA1FB1F9EC7B654-4b7f874b4eade45b "@aashutoshrathi/word-wrap@^1.2.3": @@ -462,10 +462,10 @@ magic-string "^0.30.0" regexpu-core "^5.3.2" -"@hono/eslint-config@^0.0.3": - version "0.0.3" - resolved "https://registry.npmjs.org/@hono/eslint-config/-/eslint-config-0.0.3.tgz" - integrity sha512-A4pbMilmx+HpY9TPZuC7+1eEhdTfTWKo7wJjWULOkJiH3pf580ZhaRZ+GvArCDPW6YkvTVvaGxr0wkt8VApzDg== +"@hono/eslint-config@^0.0.4": + version "0.0.4" + resolved "https://registry.npmjs.org/@hono/eslint-config/-/eslint-config-0.0.4.tgz" + integrity sha512-CaL3LBdI2tw7Luo4vGDhhrdntA02Nsts6P0FjAz3U5piy3UhWzgEvEN+L9M0fsG7Mm1cgd+kM3hF8CRJOH0aGA== dependencies: "@typescript-eslint/eslint-plugin" "^6.14.0" "@typescript-eslint/parser" "^6.14.0"