Skip to content
Myr

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

11 files+41 added−32 removed

modified:src/middleware/cache/index.test.ts+1 added-1 removed
modified:src/middleware/html/index.ts+3 added-3 removed
modified:src/middleware/jsx/index.ts+11 added-8 removed
1import { escapeToBuffer } from '../../utils/html'2import type { StringBuffer, HtmlEscaped, HtmlEscapedString } from '../../utils/html'34// eslint-disable-next-line @typescript-eslint/no-explicit-any5type Props = Record<string, any>;67declare 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 lines
66 } 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 lines
7879type Child = string | number | JSXNode | Child[]80export 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 lines
172173export { jsxFn as jsx }174const 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 line
182 return new JSXNode(tag, props, children)183 }184}185183type FC<T = Record<string, any>> = (props: T) => HtmlEscapedString186type FC<T = Props> = (props: T) => HtmlEscapedString187185const shallowEqual = (a: Record<string, any>, b: Record<string, any>): boolean => {188const shallowEqual = (a: Props, b: Props): boolean => {189 if (a === b) {190 return true191 }192
26 unmodified lines
219 return (computed ||= component(props))220 }) as FC<T>221}222220export const Fragment = (props: { key?: string; children?: any }): JSXNode => {223export 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
modified:src/middleware/validator/middleware.ts+1 added-1 removed
39 unmodified lines
40 }4142 const schema = validationFunction(v, c)43 const validatorList = getValidatorList(schema)44 let data: any = {}44 let data: Record<string, unknown> = {}4546 for (const [keys, validator] of validatorList) {47 let results: ValidateResult[]48 try {
104 unmodified lines
modified:src/router/reg-exp-router/router.ts+1 added
10 unmodified lines
11type HandlerData<T> = [T[], ParamMap | null]12type Matcher<T> = [RegExp, HandlerData<T>[]]1314const emptyParam = {}15// eslint-disable-next-line @typescript-eslint/no-explicit-any16const nullMatcher: Matcher<any> = [/^$/, []]1718function buildWildcardRegExp(path: string): RegExp {19 return new RegExp(path === '*' ? '' : `^${path.replace(/\/\*/, '(?:|/.*)')}$`)
199 unmodified lines
modified:src/compose.test.ts+9 added-12 removed
134 unmodified lines
135 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})142143describe('compose with Context - 404 not found', () => {
24 unmodified lines
168 const middleware: Function[] = []169170 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 lines
304 })305})306307describe('Compose', function () {308 function isPromise(x: any) {309 return x && typeof x.then === 'function'310 }311308 it('should get executed order one by one', async () => {309 const arr: number[] = []310 const stack = []311 const called: boolean[] = []
95 unmodified lines
407 expect(out).toEqual(ctx2.arr)408 })409410 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 line
418419 await compose(stack)({ res: null, finalized: false })420421 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 })426427 it('should work with 0 middleware', async () => {
51 unmodified lines
479 await compose(stack)(ctx)480 })481482 it('should catch downstream errors', async () => {486 const arr: any[] = []483 const arr: number[] = []484 const stack = []485486 stack.push(async (_ctx: C, next: Function) => {487 arr.push(1)
103 unmodified lines
591 it('should return last return value', async () => {592 type C = {593 val: number594 finalized: boolean598 res: any595 res: unknown596 }597 const stack = []598599 stack.push(async (ctx: C, next: Function) => {
34 unmodified lines
634 type C = {635 middleware: number636 next: number637 finalized: boolean641 res: any638 res: unknown639 }640641 const middleware = [642 (ctx: C, next: Function) => {
20 unmodified lines
modified:src/mod.ts+2 added-2 removed
modified:src/request.ts+2 added-2 removed
2 unmodified lines
3import type { Cookie } from './utils/cookie'4import { parse } from './utils/cookie'5import { getQueryStringFromURL } from './utils/url'67type ValidatedData = Record<string, any>7type ValidatedData = Record<string, unknown>89declare global {10 interface Request<11 // eslint-disable-next-line @typescript-eslint/no-unused-vars
151 unmodified lines
163 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.data
2 unmodified lines
modified:src/types.test.ts+4 added
25 unmodified lines
2627 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 lines
40 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 lines
56 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 lines
123 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 lines
modified:src/types.ts+4 added-1 removed
1 unmodified line
2import type { Schema } from './validator/schema'34export interface ContextVariableMap {}56// eslint-disable-next-line @typescript-eslint/no-explicit-any7export type Bindings = Record<string, any> // For Cloudflare Workers8// eslint-disable-next-line @typescript-eslint/no-explicit-any9export type Variables = Record<string, any> // For c.set/c.get functions10export type Environment = {11 Bindings: Bindings12 Variables: Variables
61 unmodified lines
74 : 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}8485export interface ExecutionContext {83 waitUntil(promise: Promise<any>): void86 waitUntil(promise: Promise<void>): void87 passThroughOnException(): void88}