Skip to content

Commit

Permalink
chore(lint): ESLint v9 (#3393)
Browse files Browse the repository at this point in the history
* chore(lint): ESLint v9

* run prettier
  • Loading branch information
yusukebe authored Sep 12, 2024
1 parent e0d17a3 commit 5f78e4e
Show file tree
Hide file tree
Showing 60 changed files with 410 additions and 792 deletions.
1 change: 0 additions & 1 deletion .eslintignore

This file was deleted.

9 changes: 0 additions & 9 deletions .eslintrc.cjs

This file was deleted.

Binary file modified bun.lockb
Binary file not shown.
3 changes: 3 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import baseConfig from '@hono/eslint-config'

export default [...baseConfig]
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
"test:lambda": "vitest --run --config ./runtime_tests/lambda/vitest.config.ts",
"test:lambda-edge": "vitest --run --config ./runtime_tests/lambda-edge/vitest.config.ts",
"test:all": "bun run test && bun test:deno && bun test:bun && bun test:fastly && bun test:node && bun test:workerd && bun test:lambda && bun test:lambda-edge",
"lint": "eslint --ext js,ts,tsx src runtime_tests",
"lint:fix": "eslint --ext js,ts,tsx src runtime_tests --fix",
"lint": "eslint src runtime_tests",
"lint:fix": "eslint src runtime_tests --fix",
"format": "prettier --check --cache \"src/**/*.{js,ts,tsx}\" \"runtime_tests/**/*.{js,ts,tsx}\"",
"format:fix": "prettier --write --cache --cache-strategy metadata \"src/**/*.{js,ts,tsx}\" \"runtime_tests/**/*.{js,ts,tsx}\"",
"copy:package.cjs.json": "cp ./package.cjs.json ./dist/cjs/package.json && cp ./package.cjs.json ./dist/types/package.json ",
Expand Down Expand Up @@ -618,7 +618,7 @@
"nodejs"
],
"devDependencies": {
"@hono/eslint-config": "^0.0.6",
"@hono/eslint-config": "^1.0.1",
"@hono/node-server": "^1.8.2",
"@types/crypto-js": "^4.1.1",
"@types/glob": "^8.0.0",
Expand All @@ -629,7 +629,7 @@
"arg": "^5.0.2",
"crypto-js": "^4.1.1",
"esbuild": "^0.15.12",
"eslint": "^8.55.0",
"eslint": "^9.10.0",
"glob": "7.2.3",
"jsdom": "^22.1.0",
"msw": "^2.3.0",
Expand All @@ -645,6 +645,6 @@
"zod": "^3.20.2"
},
"engines": {
"node": ">=16.0.0"
"node": ">=16.9.0"
}
}
}
2 changes: 1 addition & 1 deletion runtime_tests/bun/index.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { afterAll, afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { stream, streamSSE } from '../..//src/helper/streaming'
import { serveStatic, toSSG } from '../../src/adapter/bun'
import { createBunWebSocket } from '../../src/adapter/bun/websocket'
import type { BunWebSocketData } from '../../src/adapter/bun/websocket'
Expand All @@ -11,7 +12,6 @@ import { jsx } from '../../src/jsx'
import { basicAuth } from '../../src/middleware/basic-auth'
import { jwt } from '../../src/middleware/jwt'
import { HonoRequest } from '../../src/request'
import { stream, streamSSE } from '../..//src/helper/streaming'

// Test just only minimal patterns.
// Because others are tested well in Cloudflare Workers environment already.
Expand Down
2 changes: 1 addition & 1 deletion runtime_tests/deno-jsx/jsx.test.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/** @jsxImportSource ../../src/jsx */
import { assertEquals } from '@std/assert'
import { Style, css } from '../../src/helper/css/index.ts'
import { Suspense, renderToReadableStream } from '../../src/jsx/streaming.ts'
import type { HtmlEscapedString } from '../../src/utils/html.ts'
import { HtmlEscapedCallbackPhase, resolveCallback } from '../../src/utils/html.ts'
import { assertEquals } from '@std/assert'

Deno.test('JSX', () => {
const Component = ({ name }: { name: string }) => <span>{name}</span>
Expand Down
2 changes: 1 addition & 1 deletion runtime_tests/deno/hono.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { assertEquals } from '@std/assert'
import { Context } from '../../src/context.ts'
import { env, getRuntimeKey } from '../../src/helper/adapter/index.ts'
import { Hono } from '../../src/hono.ts'
import { assertEquals } from '@std/assert'

// Test just only minimal patterns.
// Because others are tested well in Cloudflare Workers environment already.
Expand Down
4 changes: 2 additions & 2 deletions runtime_tests/deno/middleware.test.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { assertEquals, assertMatch } from '@std/assert'
import { assertSpyCall, assertSpyCalls, spy } from '@std/testing/mock'
import { serveStatic } from '../../src/adapter/deno/index.ts'
import { Hono } from '../../src/hono.ts'
import { basicAuth } from '../../src/middleware/basic-auth/index.ts'
import { jwt } from '../../src/middleware/jwt/index.ts'
import { assertSpyCall, assertSpyCalls, spy } from '@std/testing/mock'
import { assertEquals, assertMatch } from '@std/assert'

// Test just only minimal patterns.
// Because others are already tested well in Cloudflare Workers environment.
Expand Down
2 changes: 1 addition & 1 deletion runtime_tests/deno/ssg.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { assertEquals } from '@std/assert'
import { toSSG } from '../../src/adapter/deno/ssg.ts'
import { Hono } from '../../src/hono.ts'
import { assertEquals } from '@std/assert'

Deno.test('toSSG function', async () => {
const app = new Hono()
Expand Down
4 changes: 2 additions & 2 deletions runtime_tests/deno/stream.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Hono } from '../../src/hono.ts'
import { stream, streamSSE } from '../../src/helper/streaming/index.ts'
import { assertEquals } from '@std/assert'
import { stream, streamSSE } from '../../src/helper/streaming/index.ts'
import { Hono } from '../../src/hono.ts'

Deno.test('Shuld call onAbort via stream', async () => {
const app = new Hono()
Expand Down
2 changes: 1 addition & 1 deletion runtime_tests/lambda/stream-mock.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Writable } from 'node:stream'
import { vi } from 'vitest'
import { Writable } from 'node:stream'
import type {
APIGatewayProxyEvent,
APIGatewayProxyEventV2,
Expand Down
8 changes: 4 additions & 4 deletions runtime_tests/node/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import type { Server } from 'node:http'
import { createAdaptorServer, serve } from '@hono/node-server'
import request from 'supertest'
import type { Server } from 'node:http'
import type { AddressInfo } from 'node:net'
import { Hono } from '../../src'
import { Context } from '../../src/context'
import { env, getRuntimeKey } from '../../src/helper/adapter'
import { stream, streamSSE } from '../../src/helper/streaming'
import { basicAuth } from '../../src/middleware/basic-auth'
import { jwt } from '../../src/middleware/jwt'
import { compress } from '../../src/middleware/compress'
import { stream, streamSSE } from '../../src/helper/streaming'
import type { AddressInfo } from 'node:net'
import { jwt } from '../../src/middleware/jwt'

// Test only minimal patterns.
// See <https://github.com/honojs/node-server> for more tests and information.
Expand Down
2 changes: 1 addition & 1 deletion runtime_tests/workerd/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { env, getRuntimeKey } from '../../src/helper/adapter'
import { upgradeWebSocket } from '../../src/adapter/cloudflare-workers'
import { env, getRuntimeKey } from '../../src/helper/adapter'
import { Hono } from '../../src/hono'

const app = new Hono()
Expand Down
2 changes: 1 addition & 1 deletion src/adapter/aws-lambda/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export interface CognitoIdentity {

export interface ClientContext {
client: ClientContextClient
// eslint-disable-next-line @typescript-eslint/no-explicit-any

Custom?: any
env: ClientContextEnv
}
Expand Down
2 changes: 1 addition & 1 deletion src/adapter/bun/conninfo.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Context } from '../../context'
import { getConnInfo } from './conninfo'
import type { AddressType } from '../../helper/conninfo'
import { getConnInfo } from './conninfo'

const createRandomBunServer = ({
address = Math.random().toString(),
Expand Down
2 changes: 1 addition & 1 deletion src/adapter/bun/serve-static.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* eslint-disable @typescript-eslint/ban-ts-comment */
import { stat } from 'node:fs/promises'
import { serveStatic as baseServeStatic } from '../../middleware/serve-static'
import type { ServeStaticOptions } from '../../middleware/serve-static'
import type { Env, MiddlewareHandler } from '../../types'
import { stat } from 'node:fs/promises'

export const serveStatic = <E extends Env = Env>(
options: ServeStaticOptions<E>
Expand Down
2 changes: 1 addition & 1 deletion src/adapter/lambda-edge/conninfo.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Context } from '../../context'
import type { CloudFrontEdgeEvent } from './handler'
import { getConnInfo } from './conninfo'
import type { CloudFrontEdgeEvent } from './handler'

describe('getConnInfo', () => {
it('Should info is valid', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/adapter/lambda-edge/conninfo.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Context } from '../../context'
import type { GetConnInfo } from '../../helper/conninfo'
import type { CloudFrontEdgeEvent } from './handler'
import type { Context } from '../../context'

type Env = {
Bindings: {
Expand Down
2 changes: 1 addition & 1 deletion src/client/client.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
/* eslint-disable @typescript-eslint/no-explicit-any */

/* eslint-disable @typescript-eslint/ban-ts-comment */
import { HttpResponse, http } from 'msw'
import { setupServer } from 'msw/node'
Expand Down
2 changes: 1 addition & 1 deletion src/compose.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ describe('Compose', function () {
arr.push(6)
await next()
arr.push(7)
} catch (err) {
} catch {
arr.push(2)
}
arr.push(3)
Expand Down
2 changes: 1 addition & 1 deletion src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ import type {
} from './types'
import { HtmlEscapedCallbackPhase, resolveCallback } from './utils/html'
import type { RedirectStatusCode, StatusCode } from './utils/http-status'
import type { BaseMime } from './utils/mime'
import type {
InvalidJSONValue,
IsAny,
JSONParsed,
JSONValue,
SimplifyDeepArray,
} from './utils/types'
import type { BaseMime } from './utils/mime'

type HeaderRecord =
| Record<'Content-Type', BaseMime>
Expand Down
1 change: 0 additions & 1 deletion src/helper/css/index.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable quotes */
/** @jsxImportSource ../../jsx */
import { Hono } from '../../'
import { html } from '../../helper/html'
Expand Down
2 changes: 1 addition & 1 deletion src/helper/css/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export const createCssContext = ({ id }: { id: Readonly<string> }): DefaultConte
;(className as HtmlEscapedString).callbacks = [addClassNameToContext]
const promise = Promise.resolve(className)
Object.assign(promise, cssClassName)
// eslint-disable-next-line @typescript-eslint/unbound-method

promise.toString = cssJsxDomObject.toString
return promise
}
Expand Down
2 changes: 1 addition & 1 deletion src/helper/ssg/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const SSG_DISABLED_RESPONSE = (() => {
status: 404,
headers: { [X_HONO_DISABLE_SSG_HEADER_KEY]: 'true' },
})
} catch (e) {
} catch {
return null
}
})() as Response
Expand Down
1 change: 0 additions & 1 deletion src/helper/ssg/ssg.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/unbound-method */
/** @jsxImportSource ../../jsx */
import { Hono } from '../../hono'
import { poweredBy } from '../../middleware/powered-by'
Expand Down
2 changes: 1 addition & 1 deletion src/helper/streaming/sse.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/** @jsxImportSource ../../jsx */
import { ErrorBoundary } from '../../jsx'
import { Context } from '../../context'
import { ErrorBoundary } from '../../jsx'
import { streamSSE } from '.'

describe('SSE Streaming helper', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/helper/streaming/sse.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Context } from '../../context'
import { StreamingApi } from '../../utils/stream'
import { HtmlEscapedCallbackPhase, resolveCallback } from '../../utils/html'
import { StreamingApi } from '../../utils/stream'

export interface SSEMessage {
data: string | Promise<string>
Expand Down
10 changes: 5 additions & 5 deletions src/hono.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1599,7 +1599,7 @@ describe('Request methods with custom middleware', () => {

app.use('*', async (c, next) => {
const query = c.req.query('foo')
// eslint-disable-next-line @typescript-eslint/ban-ts-comment

// @ts-ignore
const param = c.req.param('foo') // This will cause a type error.
const header = c.req.header('User-Agent')
Expand Down Expand Up @@ -2210,7 +2210,7 @@ describe('Lack returning response with a single handler', () => {
describe('Context is not finalized', () => {
it('should throw error - lack `await next()`', async () => {
const app = new Hono()
// eslint-disable-next-line @typescript-eslint/ban-ts-comment

// @ts-ignore
app.use('*', () => {})
app.get('/foo', (c) => {
Expand All @@ -2229,7 +2229,7 @@ describe('Context is not finalized', () => {
app.use('*', async (_c, next) => {
await next()
})
// eslint-disable-next-line @typescript-eslint/ban-ts-comment

// @ts-ignore
app.get('/foo', () => {})
app.onError((err, c) => {
Expand Down Expand Up @@ -2672,10 +2672,10 @@ describe('app.mount()', () => {
},
{
// Force mocking!
// eslint-disable-next-line @typescript-eslint/ban-ts-comment

// @ts-ignore
waitUntil: 'waitUntil',
// eslint-disable-next-line @typescript-eslint/ban-ts-comment

// @ts-ignore
passThroughOnException: 'passThroughOnException',
}
Expand Down
6 changes: 3 additions & 3 deletions src/jsx/base.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { raw } from '../helper/html'
import { escapeToBuffer, resolveCallbackSync, stringBufferToString } from '../utils/html'
import type { HtmlEscaped, HtmlEscapedString, StringBufferWithCallbacks } from '../utils/html'
import { DOM_RENDERER } from './constants'
import type { Context } from './context'
import { createContext, globalContexts, useContext } from './context'
import { DOM_RENDERER } from './constants'
import { domRenderers } from './intrinsic-element/common'
import * as intrinsicElementTags from './intrinsic-element/components'
import type {
JSX as HonoJSX,
IntrinsicElements as IntrinsicElementsDefined,
} from './intrinsic-elements'
import { normalizeIntrinsicElementKey, styleObjectForEach } from './utils'
import * as intrinsicElementTags from './intrinsic-element/components'
import { domRenderers } from './intrinsic-element/common'

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export type Props = Record<string, any>
Expand Down
2 changes: 1 addition & 1 deletion src/jsx/dom/css.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { JSDOM } from 'jsdom'
// run tests by old style jsx default
// hono/jsx/jsx-runtime and hono/jsx/dom/jsx-runtime are tested in their respective settings
// eslint-disable-next-line @typescript-eslint/no-unused-vars

import type { JSXNode } from '..'
import { Style, createCssContext, css, rawCssString } from '../../helper/css'
import { minify } from '../../helper/css/common'
Expand Down
2 changes: 0 additions & 2 deletions src/jsx/dom/css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ export const createCssJsxDomObjects: CreateCssJsxDomObjectsType = ({ id }) => {
},
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const Style: FC<PropsWithChildren<void>> = ({ children }) =>
({
tag: 'style',
Expand Down Expand Up @@ -173,7 +172,6 @@ export const createCssContext = ({ id }: { id: Readonly<string> }): DefaultConte
const [cssObject, Style] = createCssJsxDomObjects({ id })

const newCssClassNameObject = (cssClassName: CssClassName): string => {
// eslint-disable-next-line @typescript-eslint/unbound-method
cssClassName.toString = cssObject.toString
return cssClassName as unknown as string
}
Expand Down
4 changes: 2 additions & 2 deletions src/jsx/dom/hooks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
* Provide hooks used only in jsx/dom
*/

import { PERMALINK } from '../../constants'
import type { Context } from '../../context'
import { useContext } from '../../context'
import { createContext } from '../context'
import { useCallback, useState } from '../../hooks'
import { PERMALINK } from '../../constants'
import { createContext } from '../context'

type FormStatus =
| {
Expand Down
2 changes: 1 addition & 1 deletion src/jsx/dom/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ import {
useTransition,
useViewTransition,
} from '../hooks'
import { useActionState, useFormStatus, useOptimistic } from './hooks'
import { ErrorBoundary, Suspense } from './components'
import { createContext } from './context'
import { useActionState, useFormStatus, useOptimistic } from './hooks'
import { Fragment, jsx } from './jsx-runtime'
import { createPortal, flushSync } from './render'

Expand Down
3 changes: 1 addition & 2 deletions src/jsx/dom/intrinsic-element/components.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/** @jsxImportSource ../../ */
import { JSDOM, ResourceLoader } from 'jsdom'
import { useState } from '../../hooks'
import { Suspense, render } from '..'
import { useState } from '../../hooks'
import { clearCache, composeRef } from './components'

describe('intrinsic element', () => {
Expand All @@ -10,7 +10,6 @@ describe('intrinsic element', () => {
global.requestAnimationFrame = (cb) => setTimeout(cb)

CustomResourceLoader = class CustomResourceLoader extends ResourceLoader {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
fetch(url: string) {
return url.includes('invalid')
? Promise.reject('Invalid URL')
Expand Down
Loading

0 comments on commit 5f78e4e

Please sign in to comment.