chore: fix lint warnings (#694)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Dario Piotrowicz · committed by GitHub · parent 0774067 · Browse files · 11 files·+41 added−32 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
11 files+41 added−32 removed
- tests:+14 added−13 removed
- other:+27 added−19 removed
Provenance
- Commit
9d73771- Tree
d263559- Author
Dario Piotrowicz <dario.piotrowicz@gmail.com>- Committer
GitHub <noreply@github.com>- Parent
0774067
11 files changed+41 added−32 removed
modified:src/middleware/cache/index.test.ts+1 added-1 removed
4 unmodified lines5678991011121340 unmodified lines4 unmodified linesclass Context implements ExecutionContext { passThroughOnException(): void { throw new Error('Method not implemented.') } async waitUntil(promise: Promise<any>): Promise<void> { async waitUntil(promise: Promise<unknown>): Promise<void> { await promise }}
40 unmodified linesmodified:src/middleware/html/index.ts+3 added-3 removed
1234456789101111121314151617171819202116 unmodified linesimport { escapeToBuffer } from '../../utils/html'import type { StringBuffer, HtmlEscaped, HtmlEscapedString } from '../../utils/html'
export const raw = (value: any): HtmlEscapedString => {export const raw = (value: unknown): HtmlEscapedString => { const escapedString = new String(value) as HtmlEscapedString escapedString.isEscaped = true
return escapedString}
export const html = (strings: TemplateStringsArray, ...values: any[]): HtmlEscapedString => {export const html = (strings: TemplateStringsArray, ...values: unknown[]): HtmlEscapedString => { const buffer: StringBuffer = ['']
for (let i = 0, len = strings.length - 1; i < len; i++) { buffer[0] += strings[i]
const children = values[i] instanceof Array ? values[i].flat(Infinity) : [values[i]] const children = values[i] instanceof Array ? (values[i] as Array<unknown>).flat(Infinity) : [values[i]] for (let i = 0, len = children.length; i < len; i++) { const child = children[i] if (typeof child === 'string') { escapeToBuffer(child, buffer)16 unmodified linesmodified:src/middleware/jsx/index.ts+11 added-8 removed
1 import { escapeToBuffer } from '../../utils/html'2 import type { StringBuffer, HtmlEscaped, HtmlEscapedString } from '../../utils/html'3 4+// eslint-disable-next-line @typescript-eslint/no-explicit-any5+type Props = Record<string, any>;6+7 declare global {8 // eslint-disable-next-line @typescript-eslint/no-namespace9 namespace jsx.JSX {10 interface IntrinsicElements {8- [tagName: string]: Record<string, any>11+ [tagName: string]: Props,12 }13 }14 }15 50 unmodified lines66 } else if (typeof child === 'boolean' || child === null || child === undefined) {67 continue68 } else if (child instanceof JSXNode) {69 child.toStringToBuffer(buffer)67- } else if (typeof child === 'number' || (child as any).isEscaped) {70+ } else if (typeof child === 'number' || (child as unknown as { isEscaped: boolean }).isEscaped) {71 buffer[0] += child72 } else {73 // `child` type is `Child[]`, so stringify recursively74 childrenToStringToBuffer(child, buffer)3 unmodified lines78 79 type Child = string | number | JSXNode | Child[]80 export class JSXNode implements HtmlEscaped {81 tag: string | Function79- props: Record<string, any>82+ props: Props83 children: Child[]84 isEscaped: true = true82- constructor(tag: string | Function, props: Record<string, any>, children: Child[]) {85+ constructor(tag: string | Function, props: Props, children: Child[]) {86 this.tag = tag87 this.props = props88 this.children = children89 }82 unmodified lines172 173 export { jsxFn as jsx }174 const jsxFn = (175 tag: string | Function,173- props: Record<string, any>,176+ props: Props,177 ...children: (string | HtmlEscapedString)[]178 ): JSXNode => {179 if (typeof tag === 'function') {180 return new JSXFunctionNode(tag, props, children)1 unmodified line182 return new JSXNode(tag, props, children)183 }184 }185 183-type FC<T = Record<string, any>> = (props: T) => HtmlEscapedString186+type FC<T = Props> = (props: T) => HtmlEscapedString187 185-const shallowEqual = (a: Record<string, any>, b: Record<string, any>): boolean => {188+const shallowEqual = (a: Props, b: Props): boolean => {189 if (a === b) {190 return true191 }192 26 unmodified lines219 return (computed ||= component(props))220 }) as FC<T>221 }222 220-export const Fragment = (props: { key?: string; children?: any }): JSXNode => {223+export const Fragment = (props: { key?: string; children?: Child[] }): JSXNode => {224 return new JSXFragmentNode('', {}, props.children || [])225 }modified:src/middleware/jsx/jsx-dev-runtime.ts+3 added-2 removed
1234556678910import type { HtmlEscapedString } from '../../utils/html'import { jsx } from '.'import type { JSXNode } from '.'export { Fragment } from '.'
export function jsxDEV(tag: string | Function, props: Record<string, any>): JSXNode { const children = props.children ?? []export function jsxDEV(tag: string | Function, props: Record<string, unknown>): JSXNode { const children = (props.children ?? []) as (string | HtmlEscapedString) delete props['children'] return jsx(tag, props, children)}modified:src/middleware/validator/middleware.ts+1 added-1 removed
39 unmodified lines40 }41 42 const schema = validationFunction(v, c)43 const validatorList = getValidatorList(schema)44- let data: any = {}44+ let data: Record<string, unknown> = {}45 46 for (const [keys, validator] of validatorList) {47 let results: ValidateResult[]48 try {104 unmodified linesmodified:src/router/reg-exp-router/router.ts+1 added
10 unmodified lines11 type HandlerData<T> = [T[], ParamMap | null]12 type Matcher<T> = [RegExp, HandlerData<T>[]]13 14 const emptyParam = {}15+// eslint-disable-next-line @typescript-eslint/no-explicit-any16 const nullMatcher: Matcher<any> = [/^$/, []]17 18 function buildWildcardRegExp(path: string): RegExp {19 return new RegExp(path === '*' ? '' : `^${path.replace(/\/\*/, '(?:|/.*)')}$`)199 unmodified linesmodified:src/compose.test.ts+9 added-12 removed
134 unmodified lines135 const composed = compose<Context>(middleware)136 const context = await composed(c)137 expect(context.res).not.toBeNull()138 expect(context.res.status).toBe(200)139- expect(await context.res!.text()).toBe('Hello')139+ expect(await context.res.text()).toBe('Hello')140 })141 })142 143 describe('compose with Context - 404 not found', () => {24 unmodified lines168 const middleware: Function[] = []169 170 const req = new Request('http://localhost/')171 const c: Context = new Context(req)172- const handler = (c: Context, _next: Function) => {172+ const handler = (c: Context) => {173 return c.text('Hello')174 }175 const mHandler = async (c: Context, next: Function) => {176 await next()127 unmodified lines304 })305 })306 307 describe('Compose', function () {308- function isPromise(x: any) {309- return x && typeof x.then === 'function'310- }311-308 it('should get executed order one by one', async () => {309 const arr: number[] = []310 const stack = []311 const called: boolean[] = []95 unmodified lines407 expect(out).toEqual(ctx2.arr)408 })409 410 it('should create next functions that return a Promise', async () => {415- const stack: any[] = []416- const arr: any[] = []411+ const stack: Function[] = []412+ const arr: unknown[] = []413 for (let i = 0; i < 5; i++) {414 stack.push((_context: C, next: Function) => {415 arr.push(next())416 })1 unmodified line418 419 await compose(stack)({ res: null, finalized: false })420 421 for (const next of arr) {422+ const isPromise = !!(next as { then?: Function })?.then426- expect(isPromise(next)).toBe(true)423+ expect(isPromise).toBe(true)424 }425 })426 427 it('should work with 0 middleware', async () => {51 unmodified lines479 await compose(stack)(ctx)480 })481 482 it('should catch downstream errors', async () => {486- const arr: any[] = []483+ const arr: number[] = []484 const stack = []485 486 stack.push(async (_ctx: C, next: Function) => {487 arr.push(1)103 unmodified lines591 it('should return last return value', async () => {592 type C = {593 val: number594 finalized: boolean598- res: any595+ res: unknown596 }597 const stack = []598 599 stack.push(async (ctx: C, next: Function) => {34 unmodified lines634 type C = {635 middleware: number636 next: number637 finalized: boolean641- res: any638+ res: unknown639 }640 641 const middleware = [642 (ctx: C, next: Function) => {20 unmodified linesmodified:src/mod.ts+2 added-2 removed
12345667891011121314141516171820 unmodified linesimport { Hono } from './hono'
declare global { class ExtendableEvent extends Event { constructor(type: string, init?: EventInit) waitUntil(promise: Promise<any>): void waitUntil(promise: Promise<void>): void } abstract class FetchEvent extends ExtendableEvent { readonly request: Request respondWith(promise: Response | Promise<Response>): void passThroughOnException(): void } interface ExecutionContext { waitUntil(promise: Promise<any>): void waitUntil(promise: Promise<void>): void passThroughOnException(): void }}
20 unmodified linesmodified:src/request.ts+2 added-2 removed
2 unmodified lines3 import type { Cookie } from './utils/cookie'4 import { parse } from './utils/cookie'5 import { getQueryStringFromURL } from './utils/url'6 7-type ValidatedData = Record<string, any>7+type ValidatedData = Record<string, unknown>8 9 declare global {10 interface Request<11 // eslint-disable-next-line @typescript-eslint/no-unused-vars151 unmodified lines163 keys = [keys]164 }165 let data = this.data166 for (let i = 0; i < keys.length - 1; i++) {167- data = data[keys[i]] ||= {}167+ data = (data[keys[i]] ||= {}) as ValidatedData168 }169 data[keys[keys.length - 1]] = value170 }171 return this.data2 unmodified linesmodified:src/types.test.ts+4 added
25 unmodified lines26 27 test('No arguments', async () => {28 const handler: Handler = (c) => {29 const data = c.req.valid()30+ // eslint-disable-next-line @typescript-eslint/no-explicit-any31 type verifySchema = Expect<Equal<typeof data['foo'], any>>32 return c.text('Hi')33 }34 app.get('/', handler)5 unmodified lines40 const handler: Handler<'id'> = (c) => {41 const id = c.req.param('id')42 type verifyPath = Expect<Equal<typeof id, string>>43 const data = c.req.valid()44+ // eslint-disable-next-line @typescript-eslint/no-explicit-any45 type verifySchema = Expect<Equal<typeof data['foo'], any>>46 return c.text('Hi')47 }48 app.get('/', handler)7 unmodified lines56 type verifyPath = Expect<Equal<typeof id, string>>57 const foo = c.get('foo')58 type verifyEnv = Expect<Equal<typeof foo, string>>59 const data = c.req.valid()60+ // eslint-disable-next-line @typescript-eslint/no-explicit-any61 type verifySchema = Expect<Equal<typeof data['foo'], any>>62 return c.text('Hi')63 }64 app.get('/', handler)58 unmodified lines123 const handler: Handler<Env> = (c) => {124 const foo = c.get('foo')125 type verifyEnv = Expect<Equal<typeof foo, string>>126 const data = c.req.valid()127+ // eslint-disable-next-line @typescript-eslint/no-explicit-any128 type verifySchema = Expect<Equal<typeof data['foo'], any>>129 return c.text(foo)130 }131 app.get(21 unmodified linesmodified:src/types.ts+4 added-1 removed
1 unmodified line2 import type { Schema } from './validator/schema'3 4 export interface ContextVariableMap {}5 6+// eslint-disable-next-line @typescript-eslint/no-explicit-any7 export type Bindings = Record<string, any> // For Cloudflare Workers8+// eslint-disable-next-line @typescript-eslint/no-explicit-any9 export type Variables = Record<string, any> // For c.set/c.get functions10 export type Environment = {11 Bindings: Bindings12 Variables: Variables61 unmodified lines74 : E75 : E extends Partial<Schema>76 ? Partial<Environment>77 : Environment,78+ // eslint-disable-next-line @typescript-eslint/no-explicit-any79 S extends Schema ? S : P extends Schema ? P : E extends Schema ? E : any80 >,81 next: Next82 ): Response | Promise<Response | undefined | void>83 }84 85 export interface ExecutionContext {83- waitUntil(promise: Promise<any>): void86+ waitUntil(promise: Promise<void>): void87 passThroughOnException(): void88 }