From b134d543196d8019002055195fb2e40dd4fdd0db Mon Sep 17 00:00:00 2001 From: Yusuke Tanaka Date: Tue, 2 Mar 2021 15:31:37 +0900 Subject: [PATCH] refactor: fix codes to pass `no-unused-vars` lint (#764) --- encoding/_yaml/schema.ts | 2 +- examples/chat/server_test.ts | 2 +- fmt/printf.ts | 2 +- http/cookie_test.ts | 2 +- http/file_server.ts | 2 +- http/file_server_test.ts | 1 - http/server.ts | 6 +++--- node/_crypto/pbkdf2_test.ts | 6 +----- node/_crypto/randomBytes_test.ts | 1 - node/_fs/_fs_access.ts | 2 +- node/_fs/_fs_dir_test.ts | 2 +- node/_fs/_fs_mkdtemp.ts | 2 +- node/_fs/_fs_readdir.ts | 4 ++-- node/_fs/_fs_watch_test.ts | 2 +- node/_stream/duplex_internal.ts | 2 +- node/_util/_util_callbackify_test.ts | 2 +- node/assert_test.ts | 1 - node/assertion_error.ts | 2 +- node/crypto.ts | 2 +- node/events_test.ts | 2 +- node/os.ts | 1 + testing/asserts.ts | 8 ++++---- wasi/snapshot_preview1.ts | 1 + wasi/snapshot_preview1_test.ts | 2 +- ws/mod.ts | 2 +- 25 files changed, 28 insertions(+), 33 deletions(-) diff --git a/encoding/_yaml/schema.ts b/encoding/_yaml/schema.ts index 512f9f643b19..5459c989a585 100644 --- a/encoding/_yaml/schema.ts +++ b/encoding/_yaml/schema.ts @@ -36,7 +36,7 @@ function compileList( result.push(currentType); } - return result.filter((type, index): unknown => !exclude.includes(index)); + return result.filter((_type, index): unknown => !exclude.includes(index)); } export type TypeMap = { [k in KindType | "fallback"]: ArrayObject }; diff --git a/examples/chat/server_test.ts b/examples/chat/server_test.ts index 80a66cb2fa51..9f05806478c5 100644 --- a/examples/chat/server_test.ts +++ b/examples/chat/server_test.ts @@ -27,7 +27,7 @@ async function startServer(): Promise< const r = new TextProtoReader(new BufReader(server.stdout)); const s = await r.readLine(); assert(s !== null && s.includes("chat server starting")); - } catch (err) { + } catch { server.stdout.close(); server.close(); } diff --git a/fmt/printf.ts b/fmt/printf.ts index 6a821f208913..c014b2dc4d9b 100644 --- a/fmt/printf.ts +++ b/fmt/printf.ts @@ -468,7 +468,7 @@ class Printf { let s = ""; try { s = String.fromCodePoint(n); - } catch (RangeError) { + } catch { s = UNICODE_REPLACEMENT_CHARACTER; } return this.pad(s); diff --git a/http/cookie_test.ts b/http/cookie_test.ts index 1973eed01ee4..eaa1392695ea 100644 --- a/http/cookie_test.ts +++ b/http/cookie_test.ts @@ -187,7 +187,7 @@ Deno.test({ secure: true, maxAge: 0, }); - } catch (e) { + } catch { error = true; } assert(error); diff --git a/http/file_server.ts b/http/file_server.ts index 499d40bf7921..8b8d7daaadc9 100644 --- a/http/file_server.ts +++ b/http/file_server.ts @@ -199,7 +199,7 @@ async function serveDir( return res; } -function serveFallback(req: ServerRequest, e: Error): Promise { +function serveFallback(_req: ServerRequest, e: Error): Promise { if (e instanceof URIError) { return Promise.resolve({ status: 400, diff --git a/http/file_server_test.ts b/http/file_server_test.ts index 4f96b656ec88..8ae4d6f3f70a 100644 --- a/http/file_server_test.ts +++ b/http/file_server_test.ts @@ -2,7 +2,6 @@ import { assert, assertEquals, - assertNotEquals, assertStringIncludes, } from "../testing/asserts.ts"; import { BufReader } from "../io/bufio.ts"; diff --git a/http/server.ts b/http/server.ts index 7beb566538d7..d14b48d7b990 100644 --- a/http/server.ts +++ b/http/server.ts @@ -160,7 +160,7 @@ export class Server implements AsyncIterable { status: 400, body: new TextEncoder().encode(`${error.message}\r\n\r\n`), }); - } catch (error) { + } catch { // The connection is broken. } } @@ -187,7 +187,7 @@ export class Server implements AsyncIterable { try { // Consume unread body and trailers if receiver didn't consume those data await request.finalize(); - } catch (error) { + } catch { // Invalid data was received or the connection was closed. break; } @@ -196,7 +196,7 @@ export class Server implements AsyncIterable { this.untrackConnection(conn); try { conn.close(); - } catch (e) { + } catch { // might have been already closed } } diff --git a/node/_crypto/pbkdf2_test.ts b/node/_crypto/pbkdf2_test.ts index 29f149cbe87e..b43b65ea5192 100644 --- a/node/_crypto/pbkdf2_test.ts +++ b/node/_crypto/pbkdf2_test.ts @@ -3,11 +3,7 @@ import { pbkdf2, pbkdf2Sync, } from "./pbkdf2.ts"; -import { - assert, - assertEquals, - assertStringIncludes, -} from "../../testing/asserts.ts"; +import { assert, assertEquals } from "../../testing/asserts.ts"; import { assertCallbackErrorUncaught } from "../_utils.ts"; type Pbkdf2Fixture = { diff --git a/node/_crypto/randomBytes_test.ts b/node/_crypto/randomBytes_test.ts index 6dd2091e15f3..178f2f8d8637 100644 --- a/node/_crypto/randomBytes_test.ts +++ b/node/_crypto/randomBytes_test.ts @@ -1,7 +1,6 @@ import { assert, assertEquals, - assertStringIncludes, assertThrows, assertThrowsAsync, } from "../../testing/asserts.ts"; diff --git a/node/_fs/_fs_access.ts b/node/_fs/_fs_access.ts index 3211e1640070..5ab6e49cc1fa 100644 --- a/node/_fs/_fs_access.ts +++ b/node/_fs/_fs_access.ts @@ -17,6 +17,6 @@ export function access( // TODO(bartlomieju) 'path' can also be a Buffer. Neither of these polyfills // is available yet. See https://github.com/denoland/deno/issues/3403 // eslint-disable-next-line @typescript-eslint/no-unused-vars -export function accessSync(path: string | URL, mode?: number): void { +export function accessSync(_path: string | URL, _mode?: number): void { notImplemented("Not yet available"); } diff --git a/node/_fs/_fs_dir_test.ts b/node/_fs/_fs_dir_test.ts index f12563fd51db..930c9de9e2df 100644 --- a/node/_fs/_fs_dir_test.ts +++ b/node/_fs/_fs_dir_test.ts @@ -83,7 +83,7 @@ Deno.test({ const firstRead: Dirent | null = await dir.read(); const secondRead: Dirent | null = await dir.read( // deno-lint-ignore no-explicit-any - (err: any, secondResult: Dirent) => { + (_err: any, secondResult: Dirent) => { assert( secondResult.name === "bar.txt" || secondResult.name === "foo.txt", diff --git a/node/_fs/_fs_mkdtemp.ts b/node/_fs/_fs_mkdtemp.ts index 226399aa4dea..697c6a894698 100644 --- a/node/_fs/_fs_mkdtemp.ts +++ b/node/_fs/_fs_mkdtemp.ts @@ -64,7 +64,7 @@ function parseEncoding( if (encoding) { try { new TextDecoder(encoding); - } catch (error) { + } catch { throw new ERR_INVALID_OPT_VALUE_ENCODING(encoding); } } diff --git a/node/_fs/_fs_readdir.ts b/node/_fs/_fs_readdir.ts index e36bf5ecf94c..8dd46bce932d 100644 --- a/node/_fs/_fs_readdir.ts +++ b/node/_fs/_fs_readdir.ts @@ -50,7 +50,7 @@ export function readdir( if (options?.encoding) { try { new TextDecoder(options.encoding); - } catch (error) { + } catch { throw new Error( `TypeError [ERR_INVALID_OPT_VALUE_ENCODING]: The value "${options.encoding}" is invalid for option "encoding"`, ); @@ -100,7 +100,7 @@ export function readdirSync( if (options?.encoding) { try { new TextDecoder(options.encoding); - } catch (error) { + } catch { throw new Error( `TypeError [ERR_INVALID_OPT_VALUE_ENCODING]: The value "${options.encoding}" is invalid for option "encoding"`, ); diff --git a/node/_fs/_fs_watch_test.ts b/node/_fs/_fs_watch_test.ts index 00fce4ffdce2..298c1b31b62c 100644 --- a/node/_fs/_fs_watch_test.ts +++ b/node/_fs/_fs_watch_test.ts @@ -1,5 +1,5 @@ import { watch } from "./_fs_watch.ts"; -import { assertEquals, fail } from "../../testing/asserts.ts"; +import { assertEquals } from "../../testing/asserts.ts"; function wait(time: number) { return new Promise((resolve) => { diff --git a/node/_stream/duplex_internal.ts b/node/_stream/duplex_internal.ts index bfd9749f8bb8..9c6e56c133ca 100644 --- a/node/_stream/duplex_internal.ts +++ b/node/_stream/duplex_internal.ts @@ -59,7 +59,7 @@ function endReadableNT(state: ReadableState, stream: Duplex) { } } -function endWritableNT(state: ReadableState, stream: Duplex) { +function endWritableNT(_state: ReadableState, stream: Duplex) { const writable = stream.writable && !stream.writableEnded && !stream.destroyed; diff --git a/node/_util/_util_callbackify_test.ts b/node/_util/_util_callbackify_test.ts index 9e5281409f79..135f9d847916 100644 --- a/node/_util/_util_callbackify_test.ts +++ b/node/_util/_util_callbackify_test.ts @@ -204,7 +204,7 @@ Deno.test( const thenableFn = (): PromiseLike => { return { - then(onfulfilled, onrejected): PromiseLike { + then(_onfulfilled, onrejected): PromiseLike { assert(onrejected); onrejected(value); return this; diff --git a/node/assert_test.ts b/node/assert_test.ts index ab4bec79bcba..49beb2fafb8a 100644 --- a/node/assert_test.ts +++ b/node/assert_test.ts @@ -1,6 +1,5 @@ // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. import { - assert as denoAssert, assertEquals, assertMatch, assertNotEquals, diff --git a/node/assertion_error.ts b/node/assertion_error.ts index dcce1478b16f..1ebac83d56d4 100644 --- a/node/assertion_error.ts +++ b/node/assertion_error.ts @@ -537,7 +537,7 @@ export class AssertionError extends Error { return `${this.name} [${this.code}]: ${this.message}`; } - [inspect.custom](recurseTimes: number, ctx: Record) { + [inspect.custom](_recurseTimes: number, ctx: Record) { // Long strings should not be fully inspected. const tmpActual = this.actual; const tmpExpected = this.expected; diff --git a/node/crypto.ts b/node/crypto.ts index f3f1354ea0da..95603dacc3ee 100644 --- a/node/crypto.ts +++ b/node/crypto.ts @@ -23,7 +23,7 @@ import { encodeToString as encodeToHexString } from "../encoding/hex.ts"; */ export class Hash extends Transform { public hash: Hasher; - constructor(algorithm: SupportedAlgorithm, opts?: TransformOptions) { + constructor(algorithm: SupportedAlgorithm, _opts?: TransformOptions) { super({ transform(chunk: string, _encoding: string, callback: () => void): void { hash.update(chunk); diff --git a/node/events_test.ts b/node/events_test.ts index 6942fe8471ff..42b3f7b801bc 100644 --- a/node/events_test.ts +++ b/node/events_test.ts @@ -681,7 +681,7 @@ Deno.test("Elements that extend EventEmitter listener alias don't end up in a de const x = new X(); try { x.on("x", () => {}); - } catch (e) { + } catch { fail(); } }); diff --git a/node/os.ts b/node/os.ts index 776eff92d6ef..05958e73bd4b 100644 --- a/node/os.ts +++ b/node/os.ts @@ -211,6 +211,7 @@ export function uptime(): number { /** Not yet implemented */ export function userInfo( + // deno-lint-ignore no-unused-vars options: UserInfoOptions = { encoding: "utf-8" }, ): UserInfo { notImplemented(SEE_GITHUB_ISSUE); diff --git a/testing/asserts.ts b/testing/asserts.ts index 6cf12e9d37df..7657d427ceab 100644 --- a/testing/asserts.ts +++ b/testing/asserts.ts @@ -210,7 +210,7 @@ export function assertEquals( ); const diffMsg = buildMessage(diffResult).join("\n"); message = `Values are not equal:\n${diffMsg}`; - } catch (e) { + } catch { message = `\n${red(CAN_NOT_DISPLAY)} + \n\n`; } if (msg) { @@ -247,12 +247,12 @@ export function assertNotEquals( let expectedString: string; try { actualString = String(actual); - } catch (e) { + } catch { actualString = "[Cannot display]"; } try { expectedString = String(expected); - } catch (e) { + } catch { expectedString = "[Cannot display]"; } if (!msg) { @@ -312,7 +312,7 @@ export function assertStrictEquals( ); const diffMsg = buildMessage(diffResult).join("\n"); message = `Values are not strictly equal:\n${diffMsg}`; - } catch (e) { + } catch { message = `\n${red(CAN_NOT_DISPLAY)} + \n\n`; } } diff --git a/wasi/snapshot_preview1.ts b/wasi/snapshot_preview1.ts index 9a1796e2ee7c..70902593c35e 100644 --- a/wasi/snapshot_preview1.ts +++ b/wasi/snapshot_preview1.ts @@ -1,4 +1,5 @@ // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. +// deno-lint-ignore-file no-unused-vars import { relative, resolve } from "../path/mod.ts"; diff --git a/wasi/snapshot_preview1_test.ts b/wasi/snapshot_preview1_test.ts index b6835b285804..5fc04f70b6b0 100644 --- a/wasi/snapshot_preview1_test.ts +++ b/wasi/snapshot_preview1_test.ts @@ -1,6 +1,6 @@ // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. import Context from "./snapshot_preview1.ts"; -import { assert, assertEquals, assertThrows } from "../testing/asserts.ts"; +import { assertEquals, assertThrows } from "../testing/asserts.ts"; import { copy } from "../fs/mod.ts"; import * as path from "../path/mod.ts"; diff --git a/ws/mod.ts b/ws/mod.ts index 012a9eb3260a..784134936360 100644 --- a/ws/mod.ts +++ b/ws/mod.ts @@ -228,7 +228,7 @@ class WebSocketImpl implements WebSocket { let frame: WebSocketFrame; try { frame = await readFrame(this.bufReader); - } catch (e) { + } catch { this.ensureSocketClosed(); break; }