From d4e0981d120fa8675af878c6f8755e36cf94c2e1 Mon Sep 17 00:00:00 2001 From: Kitson Kelly Date: Thu, 11 Jan 2024 19:28:13 +1100 Subject: [PATCH] fix: fast check fixes --- application.ts | 11 +++++++---- context.ts | 7 +++++-- http_server_native.ts | 11 ----------- multipart.ts | 7 +++++-- range.ts | 2 +- request.ts | 7 +++++-- response.ts | 7 +++++-- router.ts | 20 +++++++++++++------- testing.ts | 6 +++--- 9 files changed, 44 insertions(+), 34 deletions(-) diff --git a/application.ts b/application.ts index bdd5b468..891d3f55 100644 --- a/application.ts +++ b/application.ts @@ -544,7 +544,7 @@ export class Application> * context gets set to not to respond, then the method resolves with * `undefined`, otherwise it resolves with a request that is compatible with * `std/http/server`. */ - handle = (async ( + handle: HandleMethod = (async ( request: Request, secureOrConn: Deno.Conn | boolean | undefined, secure: boolean | undefined = false, @@ -582,7 +582,7 @@ export class Application> this.#handleError(context, err); throw err; } - }) as HandleMethod; + }); /** Start listening for requests, processing registered middleware on each * request. If the options `.secure` is undefined or `false`, the listening @@ -701,7 +701,9 @@ export class Application> return this as Application; } - [Symbol.for("Deno.customInspect")](inspect: (value: unknown) => string) { + [Symbol.for("Deno.customInspect")]( + inspect: (value: unknown) => string, + ): string { const { keys, proxy, state } = this; return `${this.constructor.name} ${ inspect({ "#middleware": this.#middleware, keys, proxy, state }) @@ -713,7 +715,8 @@ export class Application> // deno-lint-ignore no-explicit-any options: any, inspect: (value: unknown, options?: unknown) => string, - ) { + // deno-lint-ignore no-explicit-any + ): any { if (depth < 0) { return options.stylize(`[${this.constructor.name}]`, "special"); } diff --git a/context.ts b/context.ts index 32a2c1e2..35e14410 100644 --- a/context.ts +++ b/context.ts @@ -312,7 +312,9 @@ export class Context< return this.#socket; } - [Symbol.for("Deno.customInspect")](inspect: (value: unknown) => string) { + [Symbol.for("Deno.customInspect")]( + inspect: (value: unknown) => string, + ): string { const { app, cookies, @@ -342,7 +344,8 @@ export class Context< // deno-lint-ignore no-explicit-any options: any, inspect: (value: unknown, options?: unknown) => string, - ) { + // deno-lint-ignore no-explicit-any + ): any { if (depth < 0) { return options.stylize(`[${this.constructor.name}]`, "special"); } diff --git a/http_server_native.ts b/http_server_native.ts index 67855912..e9a5f7cf 100644 --- a/http_server_native.ts +++ b/http_server_native.ts @@ -5,17 +5,6 @@ import { NativeRequest } from "./http_server_native_request.ts"; import type { HttpConn, Listener, Server } from "./types.d.ts"; import { assert, isListenTlsOptions } from "./util.ts"; -// this is included so when down-emitting to npm/Node.js, ReadableStream has -// async iterators -declare global { - // deno-lint-ignore no-explicit-any - interface ReadableStream { - [Symbol.asyncIterator](options?: { - preventCancel?: boolean; - }): AsyncIterableIterator; - } -} - export type Respond = (r: Response | Promise) => void; // This type is part of Deno, but not part of lib.dom.d.ts, therefore add it here diff --git a/multipart.ts b/multipart.ts index 5b3e5d81..8ae98ae6 100644 --- a/multipart.ts +++ b/multipart.ts @@ -488,7 +488,9 @@ export class FormDataReader { } } - [Symbol.for("Deno.customInspect")](inspect: (value: unknown) => string) { + [Symbol.for("Deno.customInspect")]( + inspect: (value: unknown) => string, + ): string { return `${this.constructor.name} ${inspect({})}`; } @@ -497,7 +499,8 @@ export class FormDataReader { // deno-lint-ignore no-explicit-any options: any, inspect: (value: unknown, options?: unknown) => string, - ) { + // deno-lint-ignore no-explicit-any + ): any { if (depth < 0) { return options.stylize(`[${this.constructor.name}]`, "special"); } diff --git a/range.ts b/range.ts index a33482ce..cd86ac9b 100644 --- a/range.ts +++ b/range.ts @@ -163,7 +163,7 @@ export class MultiPartStream extends ReadableStream { } /** The content length of the entire streamed body. */ - contentLength() { + contentLength(): number { return this.#contentLength; } } diff --git a/request.ts b/request.ts index 8398d28c..34a7a8c0 100644 --- a/request.ts +++ b/request.ts @@ -243,7 +243,9 @@ export class Request { return this.#body.get(options); } - [Symbol.for("Deno.customInspect")](inspect: (value: unknown) => string) { + [Symbol.for("Deno.customInspect")]( + inspect: (value: unknown) => string, + ): string { const { hasBody, headers, ip, ips, method, secure, url } = this; return `${this.constructor.name} ${ inspect({ @@ -263,7 +265,8 @@ export class Request { // deno-lint-ignore no-explicit-any options: any, inspect: (value: unknown, options?: unknown) => string, - ) { + // deno-lint-ignore no-explicit-any + ): any { if (depth < 0) { return options.stylize(`[${this.constructor.name}]`, "special"); } diff --git a/response.ts b/response.ts index 6e8cd4bf..880a068b 100644 --- a/response.ts +++ b/response.ts @@ -323,7 +323,9 @@ export class Response { return this.#domResponse = new DomResponse(bodyInit, responseInit); } - [Symbol.for("Deno.customInspect")](inspect: (value: unknown) => string) { + [Symbol.for("Deno.customInspect")]( + inspect: (value: unknown) => string, + ): string { const { body, headers, status, type, writable } = this; return `${this.constructor.name} ${ inspect({ body, headers, status, type, writable }) @@ -335,7 +337,8 @@ export class Response { // deno-lint-ignore no-explicit-any options: any, inspect: (value: unknown, options?: unknown) => string, - ) { + // deno-lint-ignore no-explicit-any + ): any { if (depth < 0) { return options.stylize(`[${this.constructor.name}]`, "special"); } diff --git a/router.ts b/router.ts index 1e6e21cb..27cffd52 100644 --- a/router.ts +++ b/router.ts @@ -300,7 +300,7 @@ class Layer< params( captures: string[], - existingParams = {} as RouteParams, + existingParams: RouteParams = {} as RouteParams, ): RouteParams { const params = existingParams; for (let i = 0; i < captures.length; i++) { @@ -320,7 +320,7 @@ class Layer< } url( - params = {} as RouteParams, + params: RouteParams = {} as RouteParams, options?: UrlOptions, ): string { const url = this.path.replace(/\(\.\*\)/g, ""); @@ -331,7 +331,7 @@ class Layer< param: string, // deno-lint-ignore no-explicit-any fn: RouterParamMiddleware, - ) { + ): this { const stack = this.stack; const params = this.#paramNames; const middleware: RouterMiddleware = function ( @@ -383,7 +383,9 @@ class Layer< }; } - [Symbol.for("Deno.customInspect")](inspect: (value: unknown) => string) { + [Symbol.for("Deno.customInspect")]( + inspect: (value: unknown) => string, + ): string { return `${this.constructor.name} ${ inspect({ methods: this.methods, @@ -401,7 +403,8 @@ class Layer< // deno-lint-ignore no-explicit-any options: any, inspect: (value: unknown, options?: unknown) => string, - ) { + // deno-lint-ignore no-explicit-any + ): any { if (depth < 0) { return options.stylize(`[${this.constructor.name}]`, "special"); } @@ -1400,7 +1403,9 @@ export class Router< return toUrl(path, params, options); } - [Symbol.for("Deno.customInspect")](inspect: (value: unknown) => string) { + [Symbol.for("Deno.customInspect")]( + inspect: (value: unknown) => string, + ): string { return `${this.constructor.name} ${ inspect({ "#params": this.#params, "#stack": this.#stack }) }`; @@ -1411,7 +1416,8 @@ export class Router< // deno-lint-ignore no-explicit-any options: any, inspect: (value: unknown, options?: unknown) => string, - ) { + // deno-lint-ignore no-explicit-any + ): any { if (depth < 0) { return options.stylize(`[${this.constructor.name}]`, "special"); } diff --git a/testing.ts b/testing.ts index 08ff9b27..6befeaaf 100644 --- a/testing.ts +++ b/testing.ts @@ -24,7 +24,7 @@ import { Response } from "./response.ts"; export function createMockApp< S extends Record = Record, >( - state = {} as S, + state: S = {} as S, ): Application { const app = { state, @@ -91,7 +91,7 @@ export function createMockContext< app = createMockApp(state), headers: requestHeaders, }: MockContextOptions = {}, -) { +): RouterContext { function createMockRequest(): Request { const headers = new Headers(requestHeaders); return { @@ -178,6 +178,6 @@ export function createMockContext< /** Creates a mock `next()` function which can be used when calling * middleware. */ -export function createMockNext() { +export function createMockNext(): () => Promise { return async function next() {}; }