Skip to content

Commit

Permalink
fix: fast check fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
kitsonk committed Jan 11, 2024
1 parent f7e9cb8 commit d4e0981
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 34 deletions.
11 changes: 7 additions & 4 deletions application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ export class Application<AS extends State = Record<string, any>>
* 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,
Expand Down Expand Up @@ -582,7 +582,7 @@ export class Application<AS extends State = Record<string, any>>
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
Expand Down Expand Up @@ -701,7 +701,9 @@ export class Application<AS extends State = Record<string, any>>
return this as Application<any>;
}

[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 })
Expand All @@ -713,7 +715,8 @@ export class Application<AS extends State = Record<string, any>>
// 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");
}
Expand Down
7 changes: 5 additions & 2 deletions context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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");
}
Expand Down
11 changes: 0 additions & 11 deletions http_server_native.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<R = any> {
[Symbol.asyncIterator](options?: {
preventCancel?: boolean;
}): AsyncIterableIterator<R>;
}
}

export type Respond = (r: Response | Promise<Response>) => void;

// This type is part of Deno, but not part of lib.dom.d.ts, therefore add it here
Expand Down
7 changes: 5 additions & 2 deletions multipart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({})}`;
}

Expand All @@ -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");
}
Expand Down
2 changes: 1 addition & 1 deletion range.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ export class MultiPartStream extends ReadableStream<Uint8Array> {
}

/** The content length of the entire streamed body. */
contentLength() {
contentLength(): number {
return this.#contentLength;
}
}
7 changes: 5 additions & 2 deletions request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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");
}
Expand Down
7 changes: 5 additions & 2 deletions response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
Expand All @@ -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");
}
Expand Down
20 changes: 13 additions & 7 deletions router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ class Layer<

params(
captures: string[],
existingParams = {} as RouteParams<R>,
existingParams: RouteParams<R> = {} as RouteParams<R>,
): RouteParams<R> {
const params = existingParams;
for (let i = 0; i < captures.length; i++) {
Expand All @@ -320,7 +320,7 @@ class Layer<
}

url(
params = {} as RouteParams<R>,
params: RouteParams<R> = {} as RouteParams<R>,
options?: UrlOptions,
): string {
const url = this.path.replace(/\(\.\*\)/g, "");
Expand All @@ -331,7 +331,7 @@ class Layer<
param: string,
// deno-lint-ignore no-explicit-any
fn: RouterParamMiddleware<any, any, any>,
) {
): this {
const stack = this.stack;
const params = this.#paramNames;
const middleware: RouterMiddleware<R> = function (
Expand Down Expand Up @@ -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,
Expand All @@ -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");
}
Expand Down Expand Up @@ -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 })
}`;
Expand All @@ -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");
}
Expand Down
6 changes: 3 additions & 3 deletions testing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { Response } from "./response.ts";
export function createMockApp<
S extends Record<string | number | symbol, any> = Record<string, any>,
>(
state = {} as S,
state: S = {} as S,
): Application<S> {
const app = {
state,
Expand Down Expand Up @@ -91,7 +91,7 @@ export function createMockContext<
app = createMockApp(state),
headers: requestHeaders,
}: MockContextOptions<R> = {},
) {
): RouterContext<R, P, S> {
function createMockRequest(): Request {
const headers = new Headers(requestHeaders);
return {
Expand Down Expand Up @@ -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<void> {
return async function next() {};
}

0 comments on commit d4e0981

Please sign in to comment.