diff --git a/cli/tests/integration_tests.rs b/cli/tests/integration_tests.rs index 9bdc1db60f..89b46acf35 100644 --- a/cli/tests/integration_tests.rs +++ b/cli/tests/integration_tests.rs @@ -31,6 +31,19 @@ fn std_tests() { assert!(status.success()); } +#[test] +fn std_lint() { + let status = util::deno_cmd() + .arg("lint") + .arg("--unstable") + .arg(util::root_path().join("std")) + .spawn() + .unwrap() + .wait() + .unwrap(); + assert!(status.success()); +} + #[test] fn x_deno_warning() { let g = util::http_server(); diff --git a/std/encoding/_yaml/loader/loader.ts b/std/encoding/_yaml/loader/loader.ts index f0d5356246..39954c2803 100644 --- a/std/encoding/_yaml/loader/loader.ts +++ b/std/encoding/_yaml/loader/loader.ts @@ -1417,7 +1417,7 @@ function readAlias(state: LoaderState): boolean { const alias = state.input.slice(_position, state.position); if ( typeof state.anchorMap !== "undefined" && - !state.anchorMap.hasOwnProperty(alias) + !Object.prototype.hasOwnProperty.call(state.anchorMap, alias) ) { return throwError(state, `unidentified alias "${alias}"`); } diff --git a/std/encoding/_yaml/utils.ts b/std/encoding/_yaml/utils.ts index 4630a45a27..e009ae3cf2 100644 --- a/std/encoding/_yaml/utils.ts +++ b/std/encoding/_yaml/utils.ts @@ -3,7 +3,7 @@ // Copyright 2011-2015 by Vitaly Puzrin. All rights reserved. MIT license. // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. -/* eslint-disable-next-line @typescript-eslint/no-explicit-any */ +// eslint-disable-next-line @typescript-eslint/no-explicit-any export type Any = any; export function isNothing(subject: unknown): subject is never { diff --git a/std/fmt/printf.ts b/std/fmt/printf.ts index 8c2f8d0344..bf5feaaedd 100644 --- a/std/fmt/printf.ts +++ b/std/fmt/printf.ts @@ -221,7 +221,7 @@ class Printf { flags.width += val; } // switch c break; - case State.PRECISION: + case State.PRECISION: { if (c === "*") { this.handleWidthOrPrecisionRef(WorP.PRECISION); break; @@ -236,6 +236,7 @@ class Printf { flags.precision *= 10; flags.precision += val; break; + } default: throw new Error("can't be here. bug."); } // switch state @@ -627,8 +628,7 @@ class Printf { switch (typeof val) { case "number": return this.fmtNumber(val as number, 16, upper); - break; - case "string": + case "string": { const sharp = this.flags.sharp && val.length !== 0; let hex = sharp ? "0x" : ""; const prec = this.flags.precision; @@ -647,7 +647,7 @@ class Printf { hex = hex.toUpperCase(); } return this.pad(hex); - break; + } default: throw new Error( "currently only number and string are implemented for hex" diff --git a/std/fs/write_json.ts b/std/fs/write_json.ts index e382fa3062..28eb80d443 100644 --- a/std/fs/write_json.ts +++ b/std/fs/write_json.ts @@ -1,5 +1,5 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. -/* eslint-disable @typescript-eslint/no-explicit-any */ +// eslint-disable-next-line @typescript-eslint/no-explicit-any type Replacer = (key: string, value: any) => any; export interface WriteJsonOptions { @@ -10,6 +10,7 @@ export interface WriteJsonOptions { /* Writes an object to a JSON file. */ export async function writeJson( filePath: string, + // eslint-disable-next-line @typescript-eslint/no-explicit-any object: any, options: WriteJsonOptions = {} ): Promise { @@ -32,6 +33,7 @@ export async function writeJson( /* Writes an object to a JSON file. */ export function writeJsonSync( filePath: string, + // eslint-disable-next-line @typescript-eslint/no-explicit-any object: any, options: WriteJsonOptions = {} ): void { diff --git a/std/hash/md5.ts b/std/hash/md5.ts index 9415b5f805..f7e55d9613 100644 --- a/std/hash/md5.ts +++ b/std/hash/md5.ts @@ -235,13 +235,14 @@ export class Md5 { switch (format) { case "hex": return hex.encodeToString(new Uint8Array(hash)); - case "base64": + case "base64": { const data = new Uint8Array(hash); let dataString = ""; for (let i = 0; i < data.length; ++i) { dataString += String.fromCharCode(data[i]); } return window.btoa(dataString); + } default: throw new Error("md5: invalid format"); } diff --git a/std/http/file_server.ts b/std/http/file_server.ts index 66babfd570..d9ed562364 100755 --- a/std/http/file_server.ts +++ b/std/http/file_server.ts @@ -135,7 +135,9 @@ async function serveDir( let fileInfo = null; try { fileInfo = await stat(filePath); - } catch (e) {} + } catch (e) { + // Pass + } listEntry.push({ mode: modeToString(entry.isDirectory, fileInfo?.mode ?? null), size: entry.isFile ? fileLenToString(fileInfo?.size ?? 0) : "", diff --git a/std/http/server.ts b/std/http/server.ts index 18bfc4731d..d2736cb439 100644 --- a/std/http/server.ts +++ b/std/http/server.ts @@ -90,7 +90,9 @@ export class ServerRequest { try { // Eagerly close on error. this.conn.close(); - } catch {} + } catch { + // Pass + } err = e; } // Signal that this request has been processed and the next pipelined @@ -108,7 +110,9 @@ export class ServerRequest { // Consume unread body const body = this.body; const buf = new Uint8Array(1024); - while ((await body.read(buf)) !== null) {} + while ((await body.read(buf)) !== null) { + // Pass + } this.finalized = true; } } diff --git a/std/log/mod_test.ts b/std/log/mod_test.ts index ceedcc8586..30576011b9 100644 --- a/std/log/mod_test.ts +++ b/std/log/mod_test.ts @@ -9,7 +9,9 @@ try { // Need to initialize it here // otherwise it will be already initialized on Deno.test logger = getLogger(); -} catch {} +} catch { + // Pass +} test("logger is initialized", function (): void { assert(logger instanceof Logger); diff --git a/std/node/_util/_util_callbackify_test.ts b/std/node/_util/_util_callbackify_test.ts index c68a2ed50c..630e4d0e71 100644 --- a/std/node/_util/_util_callbackify_test.ts +++ b/std/node/_util/_util_callbackify_test.ts @@ -21,8 +21,6 @@ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE // USE OR OTHER DEALINGS IN THE SOFTWARE. -/* eslint-disable @typescript-eslint/no-explicit-any */ - const { test } = Deno; import { assert, assertStrictEquals } from "../../testing/asserts.ts"; import { callbackify } from "./_util_callbackify.ts"; @@ -107,8 +105,10 @@ test("callbackify passes the resolution value as the second argument to the call }); }); + // eslint-disable-next-line @typescript-eslint/no-explicit-any function thenableFn(): PromiseLike { return { + // eslint-disable-next-line @typescript-eslint/no-explicit-any then(onfulfilled): PromiseLike { assert(onfulfilled); onfulfilled(value); @@ -146,7 +146,9 @@ test("callbackify passes the rejection value as the first argument to the callba if (err instanceof Error) { if ("reason" in err) { assert(!value); + // eslint-disable-next-line @typescript-eslint/no-explicit-any assertStrictEquals((err as any).code, "ERR_FALSY_VALUE_REJECTION"); + // eslint-disable-next-line @typescript-eslint/no-explicit-any assertStrictEquals((err as any).reason, value); } else { assertStrictEquals(String(value).endsWith(err.message), true); @@ -177,7 +179,9 @@ test("callbackify passes the rejection value as the first argument to the callba if (err instanceof Error) { if ("reason" in err) { assert(!value); + // eslint-disable-next-line @typescript-eslint/no-explicit-any assertStrictEquals((err as any).code, "ERR_FALSY_VALUE_REJECTION"); + // eslint-disable-next-line @typescript-eslint/no-explicit-any assertStrictEquals((err as any).reason, value); } else { assertStrictEquals(String(value).endsWith(err.message), true); @@ -206,7 +210,9 @@ test("callbackify passes the rejection value as the first argument to the callba if (err instanceof Error) { if ("reason" in err) { assert(!value); + // eslint-disable-next-line @typescript-eslint/no-explicit-any assertStrictEquals((err as any).code, "ERR_FALSY_VALUE_REJECTION"); + // eslint-disable-next-line @typescript-eslint/no-explicit-any assertStrictEquals((err as any).reason, value); } else { assertStrictEquals(String(value).endsWith(err.message), true); @@ -322,10 +328,12 @@ test("callbackify preserves the `this` binding", async () => { test("callbackify throws with non-function inputs", () => { ["foo", null, undefined, false, 0, {}, Symbol(), []].forEach((value) => { try { + // eslint-disable-next-line @typescript-eslint/no-explicit-any callbackify(value as any); throw Error("We should never reach this error"); } catch (err) { assert(err instanceof TypeError); + // eslint-disable-next-line @typescript-eslint/no-explicit-any assertStrictEquals((err as any).code, "ERR_INVALID_ARG_TYPE"); assertStrictEquals(err.name, "TypeError"); assertStrictEquals( @@ -342,6 +350,7 @@ test("callbackify returns a function that throws if the last argument is not a f return 42; } + // eslint-disable-next-line @typescript-eslint/no-explicit-any const cb = callbackify(asyncFn) as any; const args: unknown[] = []; @@ -353,6 +362,7 @@ test("callbackify returns a function that throws if the last argument is not a f throw Error("We should never reach this error"); } catch (err) { assert(err instanceof TypeError); + // eslint-disable-next-line @typescript-eslint/no-explicit-any assertStrictEquals((err as any).code, "ERR_INVALID_ARG_TYPE"); assertStrictEquals(err.name, "TypeError"); assertStrictEquals( diff --git a/std/node/_util/_util_promisify.ts b/std/node/_util/_util_promisify.ts index d7ca55be86..e3cc36a0c1 100644 --- a/std/node/_util/_util_promisify.ts +++ b/std/node/_util/_util_promisify.ts @@ -69,7 +69,7 @@ export function promisify(original: Function): Function { function fn(...args: unknown[]): Promise { return new Promise((resolve, reject) => { - // @ts-ignore + // @ts-ignore: 'this' implicitly has type 'any' because it does not have a type annotation original.call(this, ...args, (err: Error, ...values: unknown[]) => { if (err) { return reject(err); diff --git a/std/node/_utils.ts b/std/node/_utils.ts index b8c4fa00e0..463d4e67ca 100644 --- a/std/node/_utils.ts +++ b/std/node/_utils.ts @@ -16,10 +16,10 @@ export type MaybeDefined = T | undefined; export type MaybeEmpty = T | null | undefined; export function intoCallbackAPI( - /* eslint-disable-next-line @typescript-eslint/no-explicit-any */ + // eslint-disable-next-line @typescript-eslint/no-explicit-any func: (...args: any[]) => Promise, cb: MaybeEmpty<(err: MaybeNull, value: MaybeEmpty) => void>, - /* eslint-disable-next-line @typescript-eslint/no-explicit-any */ + // eslint-disable-next-line @typescript-eslint/no-explicit-any ...args: any[] ): void { func(...args) @@ -28,11 +28,11 @@ export function intoCallbackAPI( } export function intoCallbackAPIWithIntercept( - /* eslint-disable-next-line @typescript-eslint/no-explicit-any */ + // eslint-disable-next-line @typescript-eslint/no-explicit-any func: (...args: any[]) => Promise, interceptor: (v: T1) => T2, cb: MaybeEmpty<(err: MaybeNull, value: MaybeEmpty) => void>, - /* eslint-disable-next-line @typescript-eslint/no-explicit-any */ + // eslint-disable-next-line @typescript-eslint/no-explicit-any ...args: any[] ): void { func(...args) diff --git a/std/node/events.ts b/std/node/events.ts index fee715f0c6..8d6e90abdc 100644 --- a/std/node/events.ts +++ b/std/node/events.ts @@ -226,7 +226,8 @@ export default class EventEmitter { rawListener: Function; context: EventEmitter; }, - ...args: any[] // eslint-disable-line @typescript-eslint/no-explicit-any + // eslint-disable-next-line @typescript-eslint/no-explicit-any + ...args: any[] ): void { this.context.removeListener(this.eventName, this.rawListener); this.listener.apply(this.context, args); @@ -434,7 +435,6 @@ export function on( const unconsumedEventValues: any[] = []; // eslint-disable-next-line @typescript-eslint/no-explicit-any const unconsumedPromises: any[] = []; - // eslint-disable-next-line @typescript-eslint/no-explicit-any let error: Error | null = null; let finished = false; diff --git a/std/node/module.ts b/std/node/module.ts index daa01d2b24..55c5f2d32b 100644 --- a/std/node/module.ts +++ b/std/node/module.ts @@ -659,7 +659,9 @@ function readPackage(requestPath: string): PackageInfo | null { json = new TextDecoder().decode( Deno.readFileSync(path.toNamespacedPath(jsonPath)) ); - } catch {} + } catch { + // pass + } if (json === undefined) { packageJsonCache.set(jsonPath, null); @@ -839,7 +841,7 @@ function applyExports(basePath: string, expansion: string): string { } if (typeof pkgExports === "object") { - if (pkgExports.hasOwnProperty(mappingKey)) { + if (Object.prototype.hasOwnProperty.call(pkgExports, mappingKey)) { const mapping = pkgExports[mappingKey]; return resolveExportsTarget( pathToFileURL(basePath + "/"), @@ -910,7 +912,6 @@ function resolveExports( return path.resolve(nmPath, request); } -// eslint-disable-next-line @typescript-eslint/no-explicit-any function resolveExportsTarget( pkgPath: URL, // eslint-disable-next-line @typescript-eslint/no-explicit-any @@ -959,7 +960,7 @@ function resolveExportsTarget( } } else if (typeof target === "object" && target !== null) { // removed experimentalConditionalExports - if (target.hasOwnProperty("default")) { + if (Object.prototype.hasOwnProperty.call(target, "default")) { try { return resolveExportsTarget( pkgPath, @@ -1012,7 +1013,7 @@ const CircularRequirePrototypeWarningProxy = new Proxy( }, getOwnPropertyDescriptor(target, prop): PropertyDescriptor | undefined { - if (target.hasOwnProperty(prop)) { + if (Object.prototype.hasOwnProperty.call(target, prop)) { return Object.getOwnPropertyDescriptor(target, prop); } emitCircularRequireWarning(prop); @@ -1114,7 +1115,6 @@ interface RequireResolveFunction extends RequireResolve { } interface RequireFunction extends Require { - // eslint-disable-next-line @typescript-eslint/no-explicit-any resolve: RequireResolveFunction; // eslint-disable-next-line @typescript-eslint/no-explicit-any extensions: { [key: string]: (module: Module, filename: string) => any }; diff --git a/std/path/parse_format_test.ts b/std/path/parse_format_test.ts index 2bd5105519..bc58679cf4 100644 --- a/std/path/parse_format_test.ts +++ b/std/path/parse_format_test.ts @@ -1,6 +1,6 @@ // Copyright the Browserify authors. MIT License. // Ported from https://github.com/browserify/path-browserify/ -/* eslint-disable @typescript-eslint/no-explicit-any */ + // TODO(kt3k): fix any types in this file const { test } = Deno; @@ -80,6 +80,7 @@ const unixSpecialCaseFormatTests = [ [{}, ""], ]; +// eslint-disable-next-line @typescript-eslint/no-explicit-any function checkParseFormat(path: any, paths: any): void { paths.forEach(function (p: Array>) { const element = p[0]; @@ -96,6 +97,7 @@ function checkParseFormat(path: any, paths: any): void { }); } +// eslint-disable-next-line @typescript-eslint/no-explicit-any function checkSpecialCaseParseFormat(path: any, testCases: any): void { testCases.forEach(function (testCase: Array>) { const element = testCase[0]; @@ -107,6 +109,7 @@ function checkSpecialCaseParseFormat(path: any, testCases: any): void { }); } +// eslint-disable-next-line @typescript-eslint/no-explicit-any function checkFormat(path: any, testCases: unknown[][]): void { testCases.forEach(function (testCase) { assertEquals(path.format(testCase[0]), testCase[1]); diff --git a/std/textproto/mod.ts b/std/textproto/mod.ts index 48bbed8bf5..e5645a9ed0 100644 --- a/std/textproto/mod.ts +++ b/std/textproto/mod.ts @@ -114,7 +114,9 @@ export class TextProtoReader { // example: "Audio Mode" => invalid due to space in the key try { m.append(key, value); - } catch {} + } catch { + // Pass + } } } diff --git a/std/ws/mod.ts b/std/ws/mod.ts index f58828aea8..4d3f79f74e 100644 --- a/std/ws/mod.ts +++ b/std/ws/mod.ts @@ -262,7 +262,7 @@ class WebSocketImpl implements WebSocket { payloadsLength = 0; } break; - case OpCode.Close: + case OpCode.Close: { // [0x12, 0x34] -> 0x1234 const code = (frame.payload[0] << 8) | frame.payload[1]; const reason = decode( @@ -271,6 +271,7 @@ class WebSocketImpl implements WebSocket { await this.close(code, reason); yield { code, reason }; return; + } case OpCode.Ping: await this.enqueue({ opcode: OpCode.Pong,