diff options
Diffstat (limited to 'std/node')
43 files changed, 346 insertions, 327 deletions
diff --git a/std/node/_fs/_fs_access.ts b/std/node/_fs/_fs_access.ts index 79e4ca96d..df84eac9c 100644 --- a/std/node/_fs/_fs_access.ts +++ b/std/node/_fs/_fs_access.ts @@ -10,7 +10,7 @@ import { notImplemented } from "../_utils.ts"; export function access( path: string | URL, // eslint-disable-line @typescript-eslint/no-unused-vars modeOrCallback: number | Function, // eslint-disable-line @typescript-eslint/no-unused-vars - callback?: CallbackWithError // eslint-disable-line @typescript-eslint/no-unused-vars + callback?: CallbackWithError, // eslint-disable-line @typescript-eslint/no-unused-vars ): void { notImplemented("Not yet available"); } diff --git a/std/node/_fs/_fs_appendFile.ts b/std/node/_fs/_fs_appendFile.ts index c057c1f65..bc30de609 100644 --- a/std/node/_fs/_fs_appendFile.ts +++ b/std/node/_fs/_fs_appendFile.ts @@ -17,7 +17,7 @@ export function appendFile( pathOrRid: string | number | URL, data: string, optionsOrCallback: Encodings | WriteFileOptions | CallbackWithError, - callback?: CallbackWithError + callback?: CallbackWithError, ): void { pathOrRid = pathOrRid instanceof URL ? fromFileUrl(pathOrRid) : pathOrRid; const callbackFn: CallbackWithError | undefined = @@ -80,7 +80,7 @@ function closeRidIfNecessary(isPathString: boolean, rid: number): void { export function appendFileSync( pathOrRid: string | number | URL, data: string, - options?: Encodings | WriteFileOptions + options?: Encodings | WriteFileOptions, ): void { let rid = -1; @@ -116,7 +116,7 @@ export function appendFileSync( } function validateEncoding( - encodingOption: Encodings | WriteFileOptions | undefined + encodingOption: Encodings | WriteFileOptions | undefined, ): void { if (!encodingOption) return; diff --git a/std/node/_fs/_fs_appendFile_test.ts b/std/node/_fs/_fs_appendFile_test.ts index 9c0ccb666..d41065205 100644 --- a/std/node/_fs/_fs_appendFile_test.ts +++ b/std/node/_fs/_fs_appendFile_test.ts @@ -13,7 +13,7 @@ Deno.test({ appendFile("some/path", "some data", "utf8"); }, Error, - "No callback function supplied" + "No callback function supplied", ); }, }); @@ -27,7 +27,7 @@ Deno.test({ appendFile("some/path", "some data", "made-up-encoding", () => {}); }, Error, - "Only 'utf8' encoding is currently supported" + "Only 'utf8' encoding is currently supported", ); assertThrows( () => { @@ -36,17 +36,17 @@ Deno.test({ "some data", // @ts-expect-error Type '"made-up-encoding"' is not assignable to type { encoding: "made-up-encoding" }, - () => {} + () => {}, ); }, Error, - "Only 'utf8' encoding is currently supported" + "Only 'utf8' encoding is currently supported", ); assertThrows( // @ts-expect-error Type '"made-up-encoding"' is not assignable to type () => appendFileSync("some/path", "some data", "made-up-encoding"), Error, - "Only 'utf8' encoding is currently supported" + "Only 'utf8' encoding is currently supported", ); assertThrows( () => @@ -55,7 +55,7 @@ Deno.test({ encoding: "made-up-encoding", }), Error, - "Only 'utf8' encoding is currently supported" + "Only 'utf8' encoding is currently supported", ); }, }); @@ -200,7 +200,7 @@ Deno.test({ assertThrows( () => appendFileSync(tempFile, "hello world", { flag: "ax" }), Deno.errors.AlreadyExists, - "" + "", ); assertEquals(Deno.resources(), openResourcesBeforeAppend); Deno.removeSync(tempFile); diff --git a/std/node/_fs/_fs_chmod.ts b/std/node/_fs/_fs_chmod.ts index 844afd21d..9a8277b45 100644 --- a/std/node/_fs/_fs_chmod.ts +++ b/std/node/_fs/_fs_chmod.ts @@ -12,7 +12,7 @@ const allowedModes = /^[0-7]{3}/; export function chmod( path: string | URL, mode: string | number, - callback: CallbackWithError + callback: CallbackWithError, ): void { path = path instanceof URL ? fromFileUrl(path) : path; diff --git a/std/node/_fs/_fs_chown.ts b/std/node/_fs/_fs_chown.ts index 56068ef73..ae3af0121 100644 --- a/std/node/_fs/_fs_chown.ts +++ b/std/node/_fs/_fs_chown.ts @@ -11,7 +11,7 @@ export function chown( path: string | URL, uid: number, gid: number, - callback: CallbackWithError + callback: CallbackWithError, ): void { path = path instanceof URL ? fromFileUrl(path) : path; diff --git a/std/node/_fs/_fs_common.ts b/std/node/_fs/_fs_common.ts index 3c20ca73e..165b9aeca 100644 --- a/std/node/_fs/_fs_common.ts +++ b/std/node/_fs/_fs_common.ts @@ -35,7 +35,7 @@ export interface WriteFileOptions extends FileOptions { } export function isFileOptions( - fileOptions: string | WriteFileOptions | undefined + fileOptions: string | WriteFileOptions | undefined, ): fileOptions is FileOptions { if (!fileOptions) return false; @@ -47,14 +47,15 @@ export function isFileOptions( } export function getEncoding( - optOrCallback?: FileOptions | WriteFileOptions | Function | Encodings | null + optOrCallback?: FileOptions | WriteFileOptions | Function | Encodings | null, ): Encodings | null { if (!optOrCallback || typeof optOrCallback === "function") { return null; } - const encoding = - typeof optOrCallback === "string" ? optOrCallback : optOrCallback.encoding; + const encoding = typeof optOrCallback === "string" + ? optOrCallback + : optOrCallback.encoding; if (!encoding) return null; return encoding; } diff --git a/std/node/_fs/_fs_copy.ts b/std/node/_fs/_fs_copy.ts index 72f43d18f..ba530a85c 100644 --- a/std/node/_fs/_fs_copy.ts +++ b/std/node/_fs/_fs_copy.ts @@ -6,7 +6,7 @@ import { fromFileUrl } from "../path.ts"; export function copyFile( source: string | URL, destination: string, - callback: CallbackWithError + callback: CallbackWithError, ): void { source = source instanceof URL ? fromFileUrl(source) : source; diff --git a/std/node/_fs/_fs_dir_test.ts b/std/node/_fs/_fs_dir_test.ts index 2d2d5f585..4c2806389 100644 --- a/std/node/_fs/_fs_dir_test.ts +++ b/std/node/_fs/_fs_dir_test.ts @@ -49,7 +49,7 @@ Deno.test({ let calledBack = false; const fileFromCallback: Dirent | null = await new Dir( - testDir + testDir, // eslint-disable-next-line @typescript-eslint/no-explicit-any ).read((err: any, res: Dirent) => { assert(res === null); @@ -83,10 +83,11 @@ Deno.test({ // eslint-disable-next-line @typescript-eslint/no-explicit-any (err: any, secondResult: Dirent) => { assert( - secondResult.name === "bar.txt" || secondResult.name === "foo.txt" + secondResult.name === "bar.txt" || + secondResult.name === "foo.txt", ); secondCallback = true; - } + }, ); const thirdRead: Dirent | null = await dir.read(); const fourthRead: Dirent | null = await dir.read(); diff --git a/std/node/_fs/_fs_dirent.ts b/std/node/_fs/_fs_dirent.ts index 3ea1def42..24e43145c 100644 --- a/std/node/_fs/_fs_dirent.ts +++ b/std/node/_fs/_fs_dirent.ts @@ -10,7 +10,7 @@ export default class Dirent { isCharacterDevice(): boolean { notImplemented( - "Deno does not yet support identification of character devices" + "Deno does not yet support identification of character devices", ); return false; } @@ -21,7 +21,7 @@ export default class Dirent { isFIFO(): boolean { notImplemented( - "Deno does not yet support identification of FIFO named pipes" + "Deno does not yet support identification of FIFO named pipes", ); return false; } diff --git a/std/node/_fs/_fs_dirent_test.ts b/std/node/_fs/_fs_dirent_test.ts index 8c4b98214..aeb20f1d5 100644 --- a/std/node/_fs/_fs_dirent_test.ts +++ b/std/node/_fs/_fs_dirent_test.ts @@ -65,14 +65,14 @@ Deno.test({ new Dirent(entry).isFIFO(); }, Error, - "does not yet support" + "does not yet support", ); assertThrows( () => { new Dirent(entry).isSocket(); }, Error, - "does not yet support" + "does not yet support", ); }, }); diff --git a/std/node/_fs/_fs_link.ts b/std/node/_fs/_fs_link.ts index df08e13b1..42ca3de89 100644 --- a/std/node/_fs/_fs_link.ts +++ b/std/node/_fs/_fs_link.ts @@ -10,10 +10,11 @@ import { fromFileUrl } from "../path.ts"; export function link( existingPath: string | URL, newPath: string | URL, - callback: CallbackWithError + callback: CallbackWithError, ): void { - existingPath = - existingPath instanceof URL ? fromFileUrl(existingPath) : existingPath; + existingPath = existingPath instanceof URL + ? fromFileUrl(existingPath) + : existingPath; newPath = newPath instanceof URL ? fromFileUrl(newPath) : newPath; Deno.link(existingPath, newPath) @@ -27,10 +28,11 @@ export function link( */ export function linkSync( existingPath: string | URL, - newPath: string | URL + newPath: string | URL, ): void { - existingPath = - existingPath instanceof URL ? fromFileUrl(existingPath) : existingPath; + existingPath = existingPath instanceof URL + ? fromFileUrl(existingPath) + : existingPath; newPath = newPath instanceof URL ? fromFileUrl(newPath) : newPath; Deno.linkSync(existingPath, newPath); diff --git a/std/node/_fs/_fs_mkdir.ts b/std/node/_fs/_fs_mkdir.ts index 8578f4653..63aabd010 100644 --- a/std/node/_fs/_fs_mkdir.ts +++ b/std/node/_fs/_fs_mkdir.ts @@ -14,7 +14,7 @@ type MkdirOptions = export function mkdir( path: string | URL, options?: MkdirOptions | CallbackWithError, - callback?: CallbackWithError + callback?: CallbackWithError, ): void { path = path instanceof URL ? fromFileUrl(path) : path; @@ -33,7 +33,7 @@ export function mkdir( } if (typeof recursive !== "boolean") { throw new Deno.errors.InvalidData( - "invalid recursive option , must be a boolean" + "invalid recursive option , must be a boolean", ); } Deno.mkdir(path, { recursive, mode }) @@ -64,7 +64,7 @@ export function mkdirSync(path: string | URL, options?: MkdirOptions): void { } if (typeof recursive !== "boolean") { throw new Deno.errors.InvalidData( - "invalid recursive option , must be a boolean" + "invalid recursive option , must be a boolean", ); } diff --git a/std/node/_fs/_fs_readFile.ts b/std/node/_fs/_fs_readFile.ts index 39c3d8393..2aef28290 100644 --- a/std/node/_fs/_fs_readFile.ts +++ b/std/node/_fs/_fs_readFile.ts @@ -14,11 +14,11 @@ import { fromFileUrl } from "../path.ts"; function maybeDecode(data: Uint8Array, encoding: TextEncodings): string; function maybeDecode( data: Uint8Array, - encoding: BinaryEncodings | null + encoding: BinaryEncodings | null, ): Buffer; function maybeDecode( data: Uint8Array, - encoding: Encodings | null + encoding: Encodings | null, ): string | Buffer { const buffer = new Buffer(data.buffer, data.byteOffset, data.byteLength); if (encoding && encoding !== "binary") return buffer.toString(encoding); @@ -33,23 +33,23 @@ type Callback = TextCallback | BinaryCallback | GenericCallback; export function readFile( path: string | URL, options: TextOptionsArgument, - callback: TextCallback + callback: TextCallback, ): void; export function readFile( path: string | URL, options: BinaryOptionsArgument, - callback: BinaryCallback + callback: BinaryCallback, ): void; export function readFile( path: string | URL, options: null | undefined | FileOptionsArgument, - callback: BinaryCallback + callback: BinaryCallback, ): void; export function readFile(path: string | URL, callback: BinaryCallback): void; export function readFile( path: string | URL, optOrCallback?: FileOptionsArgument | Callback | null | undefined, - callback?: Callback + callback?: Callback, ): void { path = path instanceof URL ? fromFileUrl(path) : path; let cb: Callback | undefined; @@ -77,15 +77,15 @@ export function readFile( export function readFileSync( path: string | URL, - opt: TextOptionsArgument + opt: TextOptionsArgument, ): string; export function readFileSync( path: string | URL, - opt?: BinaryOptionsArgument + opt?: BinaryOptionsArgument, ): Buffer; export function readFileSync( path: string | URL, - opt?: FileOptionsArgument + opt?: FileOptionsArgument, ): string | Buffer { path = path instanceof URL ? fromFileUrl(path) : path; const data = Deno.readFileSync(path); diff --git a/std/node/_fs/_fs_readFile_test.ts b/std/node/_fs/_fs_readFile_test.ts index 076c4b276..ff449dbb2 100644 --- a/std/node/_fs/_fs_readFile_test.ts +++ b/std/node/_fs/_fs_readFile_test.ts @@ -3,7 +3,7 @@ import * as path from "../../path/mod.ts"; import { assertEquals, assert } from "../../testing/asserts.ts"; const testData = path.resolve( - path.join("node", "_fs", "testdata", "hello.txt") + path.join("node", "_fs", "testdata", "hello.txt"), ); Deno.test("readFileSuccess", async function () { diff --git a/std/node/_fs/_fs_readlink.ts b/std/node/_fs/_fs_readlink.ts index 11ce43f55..866ea187b 100644 --- a/std/node/_fs/_fs_readlink.ts +++ b/std/node/_fs/_fs_readlink.ts @@ -8,7 +8,7 @@ import { fromFileUrl } from "../path.ts"; type ReadlinkCallback = ( err: MaybeEmpty<Error>, - linkString: MaybeEmpty<string | Uint8Array> + linkString: MaybeEmpty<string | Uint8Array>, ) => void; interface ReadlinkOptions { @@ -17,7 +17,7 @@ interface ReadlinkOptions { function maybeEncode( data: string, - encoding: string | null + encoding: string | null, ): string | Uint8Array { if (encoding === "buffer") { return new TextEncoder().encode(data); @@ -26,7 +26,7 @@ function maybeEncode( } function getEncoding( - optOrCallback?: ReadlinkOptions | ReadlinkCallback + optOrCallback?: ReadlinkOptions | ReadlinkCallback, ): string | null { if (!optOrCallback || typeof optOrCallback === "function") { return null; @@ -50,7 +50,7 @@ function getEncoding( export function readlink( path: string | URL, optOrCallback: ReadlinkCallback | ReadlinkOptions, - callback?: ReadlinkCallback + callback?: ReadlinkCallback, ): void { path = path instanceof URL ? fromFileUrl(path) : path; @@ -67,13 +67,13 @@ export function readlink( Deno.readLink, (data: string): string | Uint8Array => maybeEncode(data, encoding), cb, - path + path, ); } export function readlinkSync( path: string | URL, - opt?: ReadlinkOptions + opt?: ReadlinkOptions, ): string | Uint8Array { path = path instanceof URL ? fromFileUrl(path) : path; diff --git a/std/node/_fs/_fs_writeFile.ts b/std/node/_fs/_fs_writeFile.ts index 8a66f3f3d..a8ae1f586 100644 --- a/std/node/_fs/_fs_writeFile.ts +++ b/std/node/_fs/_fs_writeFile.ts @@ -17,7 +17,7 @@ export function writeFile( pathOrRid: string | number | URL, data: string | Uint8Array, optOrCallback: Encodings | CallbackWithError | WriteFileOptions | undefined, - callback?: CallbackWithError + callback?: CallbackWithError, ): void { const callbackFn: CallbackWithError | undefined = optOrCallback instanceof Function ? optOrCallback : callback; @@ -72,7 +72,7 @@ export function writeFile( export function writeFileSync( pathOrRid: string | number | URL, data: string | Uint8Array, - options?: Encodings | WriteFileOptions + options?: Encodings | WriteFileOptions, ): void { pathOrRid = pathOrRid instanceof URL ? fromFileUrl(pathOrRid) : pathOrRid; diff --git a/std/node/_fs/_fs_writeFile_test.ts b/std/node/_fs/_fs_writeFile_test.ts index 015ed6553..a11e0fb67 100644 --- a/std/node/_fs/_fs_writeFile_test.ts +++ b/std/node/_fs/_fs_writeFile_test.ts @@ -18,7 +18,7 @@ Deno.test("Callback must be a function error", function fn() { writeFile("some/path", "some data", "utf8"); }, TypeError, - "Callback must be a function." + "Callback must be a function.", ); }); @@ -29,7 +29,7 @@ Deno.test("Invalid encoding results in error()", function testEncodingErrors() { writeFile("some/path", "some data", "made-up-encoding", () => {}); }, Error, - `The value "made-up-encoding" is invalid for option "encoding"` + `The value "made-up-encoding" is invalid for option "encoding"`, ); assertThrows( @@ -38,7 +38,7 @@ Deno.test("Invalid encoding results in error()", function testEncodingErrors() { writeFileSync("some/path", "some data", "made-up-encoding"); }, Error, - `The value "made-up-encoding" is invalid for option "encoding"` + `The value "made-up-encoding" is invalid for option "encoding"`, ); assertThrows( @@ -50,11 +50,11 @@ Deno.test("Invalid encoding results in error()", function testEncodingErrors() { // @ts-expect-error Type '"made-up-encoding"' is not assignable to type encoding: "made-up-encoding", }, - () => {} + () => {}, ); }, Error, - `The value "made-up-encoding" is invalid for option "encoding"` + `The value "made-up-encoding" is invalid for option "encoding"`, ); assertThrows( @@ -65,7 +65,7 @@ Deno.test("Invalid encoding results in error()", function testEncodingErrors() { }); }, Error, - `The value "made-up-encoding" is invalid for option "encoding"` + `The value "made-up-encoding" is invalid for option "encoding"`, ); }); @@ -77,7 +77,7 @@ Deno.test( writeFile("some/path", "some data", "utf16le", () => {}); }, Error, - `Not implemented: "utf16le" encoding` + `Not implemented: "utf16le" encoding`, ); assertThrows( @@ -85,9 +85,9 @@ Deno.test( writeFileSync("some/path", "some data", "utf16le"); }, Error, - `Not implemented: "utf16le" encoding` + `Not implemented: "utf16le" encoding`, ); - } + }, ); Deno.test( @@ -111,7 +111,7 @@ Deno.test( const data = await Deno.readFile(tempFile); await Deno.remove(tempFile); assertEquals(decoder.decode(data), "hello world"); - } + }, ); Deno.test( @@ -125,7 +125,7 @@ Deno.test( await Deno.remove("_fs_writeFile_test_file.txt"); assertEquals(res, null); assertEquals(decoder.decode(data), "hello world"); - } + }, ); Deno.test( @@ -146,7 +146,7 @@ Deno.test( "_fs_writeFile_test_file.txt", value, encoding as TextEncodings, - resolve + resolve, ); }); @@ -155,7 +155,7 @@ Deno.test( assertEquals(res, null); assertEquals(decoder.decode(data), "hello world"); } - } + }, ); Deno.test("Path can be an URL", async function testCorrectWriteUsingURL() { @@ -165,7 +165,7 @@ Deno.test("Path can be an URL", async function testCorrectWriteUsingURL() { path .join(testDataDir, "_fs_writeFile_test_file_url.txt") .replace(/\\/g, "/") - : "file://" + path.join(testDataDir, "_fs_writeFile_test_file_url.txt") + : "file://" + path.join(testDataDir, "_fs_writeFile_test_file_url.txt"), ); const filePath = path.fromFileUrl(url); const res = await new Promise((resolve) => { @@ -218,7 +218,7 @@ Deno.test( await Deno.remove(filename); assert(fileInfo.mode); assertNotEquals(fileInfo.mode & 0o777, 0o777); - } + }, ); Deno.test( @@ -237,7 +237,7 @@ Deno.test( const data = Deno.readFileSync(tempFile); Deno.removeSync(tempFile); assertEquals(decoder.decode(data), "hello world"); - } + }, ); Deno.test( @@ -260,7 +260,7 @@ Deno.test( Deno.removeSync(file); assertEquals(decoder.decode(data), "hello world"); } - } + }, ); Deno.test( @@ -273,18 +273,18 @@ Deno.test( const data = Deno.readFileSync(file); Deno.removeSync(file); assertEquals(decoder.decode(data), "hello world"); - } + }, ); Deno.test("sync: Path can be an URL", function testCorrectWriteSyncUsingURL() { const filePath = path.join( testDataDir, - "_fs_writeFileSync_test_file_url.txt" + "_fs_writeFileSync_test_file_url.txt", ); const url = new URL( Deno.build.os === "windows" ? "file:///" + filePath.replace(/\\/g, "/") - : "file://" + filePath + : "file://" + filePath, ); writeFileSync(url, "hello world"); @@ -305,5 +305,5 @@ Deno.test( Deno.removeSync(filename); assert(fileInfo && fileInfo.mode); assertEquals(fileInfo.mode & 0o777, 0o777); - } + }, ); diff --git a/std/node/_fs/promises/_fs_readFile.ts b/std/node/_fs/promises/_fs_readFile.ts index 8677e05cd..446c48625 100644 --- a/std/node/_fs/promises/_fs_readFile.ts +++ b/std/node/_fs/promises/_fs_readFile.ts @@ -8,15 +8,15 @@ import { readFile as readFileCallback } from "../_fs_readFile.ts"; export function readFile( path: string | URL, - options: TextOptionsArgument + options: TextOptionsArgument, ): Promise<string>; export function readFile( path: string | URL, - options?: BinaryOptionsArgument + options?: BinaryOptionsArgument, ): Promise<Uint8Array>; export function readFile( path: string | URL, - options?: FileOptionsArgument + options?: FileOptionsArgument, ): Promise<string | Uint8Array> { return new Promise((resolve, reject) => { readFileCallback(path, options, (err, data): void => { diff --git a/std/node/_fs/promises/_fs_readFile_test.ts b/std/node/_fs/promises/_fs_readFile_test.ts index 1d2097881..a5f5a1327 100644 --- a/std/node/_fs/promises/_fs_readFile_test.ts +++ b/std/node/_fs/promises/_fs_readFile_test.ts @@ -3,7 +3,7 @@ import * as path from "../../../path/mod.ts"; import { assertEquals, assert } from "../../../testing/asserts.ts"; const testData = path.resolve( - path.join("node", "_fs", "testdata", "hello.txt") + path.join("node", "_fs", "testdata", "hello.txt"), ); Deno.test("readFileSuccess", async function () { diff --git a/std/node/_fs/promises/_fs_writeFile.ts b/std/node/_fs/promises/_fs_writeFile.ts index 48b9bf0ea..1c9ea5032 100644 --- a/std/node/_fs/promises/_fs_writeFile.ts +++ b/std/node/_fs/promises/_fs_writeFile.ts @@ -6,7 +6,7 @@ import { writeFile as writeFileCallback } from "../_fs_writeFile.ts"; export function writeFile( pathOrRid: string | number | URL, data: string | Uint8Array, - options?: Encodings | WriteFileOptions + options?: Encodings | WriteFileOptions, ): Promise<void> { return new Promise((resolve, reject) => { writeFileCallback(pathOrRid, data, options, (err?: Error | null) => { diff --git a/std/node/_fs/promises/_fs_writeFile_test.ts b/std/node/_fs/promises/_fs_writeFile_test.ts index 6901fff22..698284057 100644 --- a/std/node/_fs/promises/_fs_writeFile_test.ts +++ b/std/node/_fs/promises/_fs_writeFile_test.ts @@ -17,7 +17,7 @@ Deno.test("Invalid encoding results in error()", function testEncodingErrors() { await writeFile("some/path", "some data", "made-up-encoding"); }, Error, - `The value "made-up-encoding" is invalid for option "encoding"` + `The value "made-up-encoding" is invalid for option "encoding"`, ); assertThrowsAsync( async () => { @@ -27,7 +27,7 @@ Deno.test("Invalid encoding results in error()", function testEncodingErrors() { }); }, Error, - `The value "made-up-encoding" is invalid for option "encoding"` + `The value "made-up-encoding" is invalid for option "encoding"`, ); }); @@ -39,9 +39,9 @@ Deno.test( await writeFile("some/path", "some data", "utf16le"); }, Error, - `Not implemented: "utf16le" encoding` + `Not implemented: "utf16le" encoding`, ); - } + }, ); Deno.test( @@ -60,7 +60,7 @@ Deno.test( const data = await Deno.readFile(tempFile); await Deno.remove(tempFile); assertEquals(decoder.decode(data), "hello world"); - } + }, ); Deno.test( @@ -74,7 +74,7 @@ Deno.test( const data = await Deno.readFile("_fs_writeFile_test_file.txt"); await Deno.remove("_fs_writeFile_test_file.txt"); assertEquals(decoder.decode(data), "hello world"); - } + }, ); Deno.test( @@ -93,14 +93,14 @@ Deno.test( await writeFile( "_fs_writeFile_test_file.txt", value, - encoding as TextEncodings + encoding as TextEncodings, ); const data = await Deno.readFile("_fs_writeFile_test_file.txt"); await Deno.remove("_fs_writeFile_test_file.txt"); assertEquals(decoder.decode(data), "hello world"); } - } + }, ); Deno.test("Mode is correctly set", async function testCorrectFileMode() { @@ -133,5 +133,5 @@ Deno.test( await Deno.remove(filename); assert(fileInfo.mode); assertNotEquals(fileInfo.mode & 0o777, 0o777); - } + }, ); diff --git a/std/node/_util/_util_callbackify.ts b/std/node/_util/_util_callbackify.ts index 4c752e7ef..b37bf829a 100644 --- a/std/node/_util/_util_callbackify.ts +++ b/std/node/_util/_util_callbackify.ts @@ -42,30 +42,30 @@ type Callback<ResultT> = | ((err: null, result: ResultT) => void); function callbackify<ResultT>( - fn: () => PromiseLike<ResultT> + fn: () => PromiseLike<ResultT>, ): (callback: Callback<ResultT>) => void; function callbackify<ArgT, ResultT>( - fn: (arg: ArgT) => PromiseLike<ResultT> + fn: (arg: ArgT) => PromiseLike<ResultT>, ): (arg: ArgT, callback: Callback<ResultT>) => void; function callbackify<Arg1T, Arg2T, ResultT>( - fn: (arg1: Arg1T, arg2: Arg2T) => PromiseLike<ResultT> + fn: (arg1: Arg1T, arg2: Arg2T) => PromiseLike<ResultT>, ): (arg1: Arg1T, arg2: Arg2T, callback: Callback<ResultT>) => void; function callbackify<Arg1T, Arg2T, Arg3T, ResultT>( - fn: (arg1: Arg1T, arg2: Arg2T, arg3: Arg3T) => PromiseLike<ResultT> + fn: (arg1: Arg1T, arg2: Arg2T, arg3: Arg3T) => PromiseLike<ResultT>, ): (arg1: Arg1T, arg2: Arg2T, arg3: Arg3T, callback: Callback<ResultT>) => void; function callbackify<Arg1T, Arg2T, Arg3T, Arg4T, ResultT>( fn: ( arg1: Arg1T, arg2: Arg2T, arg3: Arg3T, - arg4: Arg4T - ) => PromiseLike<ResultT> + arg4: Arg4T, + ) => PromiseLike<ResultT>, ): ( arg1: Arg1T, arg2: Arg2T, arg3: Arg3T, arg4: Arg4T, - callback: Callback<ResultT> + callback: Callback<ResultT>, ) => void; function callbackify<Arg1T, Arg2T, Arg3T, Arg4T, Arg5T, ResultT>( fn: ( @@ -73,15 +73,15 @@ function callbackify<Arg1T, Arg2T, Arg3T, Arg4T, Arg5T, ResultT>( arg2: Arg2T, arg3: Arg3T, arg4: Arg4T, - arg5: Arg5T - ) => PromiseLike<ResultT> + arg5: Arg5T, + ) => PromiseLike<ResultT>, ): ( arg1: Arg1T, arg2: Arg2T, arg3: Arg3T, arg4: Arg4T, arg5: Arg5T, - callback: Callback<ResultT> + callback: Callback<ResultT>, ) => void; // eslint-disable-next-line @typescript-eslint/no-explicit-any @@ -105,7 +105,7 @@ function callbackify(original: any): any { (rej: unknown) => { rej = rej || new NodeFalsyValueRejectionError(rej); queueMicrotask(cb.bind(this, rej)); - } + }, ); }; diff --git a/std/node/_util/_util_callbackify_test.ts b/std/node/_util/_util_callbackify_test.ts index e8a313905..d585f0551 100644 --- a/std/node/_util/_util_callbackify_test.ts +++ b/std/node/_util/_util_callbackify_test.ts @@ -58,7 +58,7 @@ class TestQueue { if (this.#queueSize === 0) { assert( this.#resolve, - "Test setup error; async queue is missing #resolve" + "Test setup error; async queue is missing #resolve", ); this.#resolve(); } @@ -127,7 +127,7 @@ Deno.test( } await testQueue.waitForCompletion(); - } + }, ); Deno.test( @@ -152,7 +152,7 @@ Deno.test( assertStrictEquals( // eslint-disable-next-line @typescript-eslint/no-explicit-any (err as any).code, - "ERR_FALSY_VALUE_REJECTION" + "ERR_FALSY_VALUE_REJECTION", ); // eslint-disable-next-line @typescript-eslint/no-explicit-any assertStrictEquals((err as any).reason, value); @@ -188,7 +188,7 @@ Deno.test( assertStrictEquals( // eslint-disable-next-line @typescript-eslint/no-explicit-any (err as any).code, - "ERR_FALSY_VALUE_REJECTION" + "ERR_FALSY_VALUE_REJECTION", ); // eslint-disable-next-line @typescript-eslint/no-explicit-any assertStrictEquals((err as any).reason, value); @@ -222,7 +222,7 @@ Deno.test( assertStrictEquals( // eslint-disable-next-line @typescript-eslint/no-explicit-any (err as any).code, - "ERR_FALSY_VALUE_REJECTION" + "ERR_FALSY_VALUE_REJECTION", ); // eslint-disable-next-line @typescript-eslint/no-explicit-any assertStrictEquals((err as any).reason, value); @@ -238,7 +238,7 @@ Deno.test( } await testQueue.waitForCompletion(); - } + }, ); Deno.test("callbackify passes arguments to the original", async () => { @@ -304,7 +304,7 @@ Deno.test("callbackify preserves the `this` binding", async () => { cbSyncFunction.call(objectWithSyncFunction, value, function ( this: unknown, err: unknown, - ret: unknown + ret: unknown, ) { assertStrictEquals(err, null); assertStrictEquals(ret, value); @@ -325,7 +325,7 @@ Deno.test("callbackify preserves the `this` binding", async () => { cbAsyncFunction.call(objectWithAsyncFunction, value, function ( this: unknown, err: unknown, - ret: unknown + ret: unknown, ) { assertStrictEquals(err, null); assertStrictEquals(ret, value); @@ -351,7 +351,7 @@ Deno.test("callbackify throws with non-function inputs", () => { assertStrictEquals(err.name, "TypeError"); assertStrictEquals( err.message, - 'The "original" argument must be of type function.' + 'The "original" argument must be of type function.', ); } }); @@ -382,9 +382,9 @@ Deno.test( assertStrictEquals(err.name, "TypeError"); assertStrictEquals( err.message, - "The last argument must be of type function." + "The last argument must be of type function.", ); } }); - } + }, ); diff --git a/std/node/_util/_util_promisify.ts b/std/node/_util/_util_promisify.ts index ea2fb6a5e..9e86b5a09 100644 --- a/std/node/_util/_util_promisify.ts +++ b/std/node/_util/_util_promisify.ts @@ -32,7 +32,7 @@ declare let Symbol: SymbolConstructor; interface SymbolConstructor { for(key: "nodejs.util.promisify.custom"): typeof _CustomPromisifiedSymbol; for( - key: "nodejs.util.promisify.customArgs" + key: "nodejs.util.promisify.customArgs", ): typeof _CustomPromisifyArgsSymbol; } // End hack. @@ -44,21 +44,22 @@ const kCustomPromisifiedSymbol = Symbol.for("nodejs.util.promisify.custom"); // This is an internal Node symbol used by functions returning multiple // arguments, e.g. ['bytesRead', 'buffer'] for fs.read(). const kCustomPromisifyArgsSymbol = Symbol.for( - "nodejs.util.promisify.customArgs" + "nodejs.util.promisify.customArgs", ); class NodeInvalidArgTypeError extends TypeError { public code = "ERR_INVALID_ARG_TYPE"; constructor(argumentName: string, type: string, received: unknown) { super( - `The "${argumentName}" argument must be of type ${type}. Received ${typeof received}` + `The "${argumentName}" argument must be of type ${type}. Received ${typeof received}`, ); } } export function promisify(original: Function): Function { - if (typeof original !== "function") + if (typeof original !== "function") { throw new NodeInvalidArgTypeError("original", "Function", original); + } // @ts-ignore TypeScript (as of 3.7) does not support indexing namespaces by symbol if (original[kCustomPromisifiedSymbol]) { @@ -68,7 +69,7 @@ export function promisify(original: Function): Function { throw new NodeInvalidArgTypeError( "util.promisify.custom", "Function", - fn + fn, ); } return Object.defineProperty(fn, kCustomPromisifiedSymbol, { @@ -115,7 +116,7 @@ export function promisify(original: Function): Function { }); return Object.defineProperties( fn, - Object.getOwnPropertyDescriptors(original) + Object.getOwnPropertyDescriptors(original), ); } diff --git a/std/node/_util/_util_promisify_test.ts b/std/node/_util/_util_promisify_test.ts index 4369a0132..5148bc609 100644 --- a/std/node/_util/_util_promisify_test.ts +++ b/std/node/_util/_util_promisify_test.ts @@ -36,7 +36,7 @@ Deno.test( "Errors should reject the promise", async function testPromiseRejection() { await assertThrowsAsync(() => readFile("/dontexist"), Deno.errors.NotFound); - } + }, ); Deno.test("Promisify.custom", async function testPromisifyCustom() { @@ -106,7 +106,7 @@ Deno.test( } const value = await promisify(fn)(); assertStrictEquals(value, "foo"); - } + }, ); Deno.test( @@ -117,7 +117,7 @@ Deno.test( } const value = await promisify(fn)(); assertStrictEquals(value, undefined); - } + }, ); Deno.test( @@ -128,7 +128,7 @@ Deno.test( } const value = await promisify(fn)(); assertStrictEquals(value, undefined); - } + }, ); Deno.test( @@ -139,7 +139,7 @@ Deno.test( } const value = await promisify(fn)(null, 42); assertStrictEquals(value, 42); - } + }, ); Deno.test( @@ -151,9 +151,9 @@ Deno.test( await assertThrowsAsync( () => promisify(fn)(new Error("oops"), null), Error, - "oops" + "oops", ); - } + }, ); Deno.test("Rejected value", async function testPromisifyWithAsObjectMethod() { @@ -173,7 +173,7 @@ Deno.test( "Multiple callback", async function testPromisifyWithMultipleCallback() { const err = new Error( - "Should not have called the callback with the error." + "Should not have called the callback with the error.", ); const stack = err.stack; @@ -185,7 +185,7 @@ Deno.test( await fn(); await Promise.resolve(); return assertStrictEquals(stack, err.stack); - } + }, ); Deno.test("Promisify a promise", function testPromisifyPromise() { @@ -203,7 +203,7 @@ Deno.test("Test error", async function testInvalidArguments() { a: number, b: number, c: number, - cb: Function + cb: Function, ): void { errToThrow = new Error(`${a}-${b}-${c}-${cb}`); throw errToThrow; @@ -227,7 +227,7 @@ Deno.test("Test invalid arguments", function testInvalidArguments() { assert(e instanceof TypeError); assertEquals( e.message, - `The "original" argument must be of type Function. Received ${typeof input}` + `The "original" argument must be of type Function. Received ${typeof input}`, ); } }); diff --git a/std/node/_util/_util_types.ts b/std/node/_util/_util_types.ts index df8ccbb05..eaf955b35 100644 --- a/std/node/_util/_util_types.ts +++ b/std/node/_util/_util_types.ts @@ -194,7 +194,8 @@ export function isSymbolObject(value: unknown): boolean { // Adapted from Lodash export function isTypedArray(value: unknown): boolean { /** Used to match `toStringTag` values of typed arrays. */ - const reTypedTag = /^\[object (?:Float(?:32|64)|(?:Int|Uint)(?:8|16|32)|Uint8Clamped)Array\]$/; + const reTypedTag = + /^\[object (?:Float(?:32|64)|(?:Int|Uint)(?:8|16|32)|Uint8Clamped)Array\]$/; return _isObjectLike(value) && reTypedTag.test(_toString.call(value)); } diff --git a/std/node/_util/_util_types_test.ts b/std/node/_util/_util_types_test.ts index f6dfcfe89..fff0dad0c 100644 --- a/std/node/_util/_util_types_test.ts +++ b/std/node/_util/_util_types_test.ts @@ -229,14 +229,14 @@ Deno.test("Should return false for invalid Float64Array types", () => { Deno.test("Should return true for valid generator functions", () => { assertStrictEquals( isGeneratorFunction(function* foo() {}), - true + true, ); }); Deno.test("Should return false for invalid generator functions", () => { assertStrictEquals( isGeneratorFunction(function foo() {}), - false + false, ); }); @@ -249,7 +249,7 @@ Deno.test("Should return true for valid generator object types", () => { Deno.test("Should return false for invalid generation object types", () => { assertStrictEquals( isGeneratorObject(function* foo() {}), - false + false, ); }); diff --git a/std/node/_utils.ts b/std/node/_utils.ts index 66b7b10d9..0e8b26fb5 100644 --- a/std/node/_utils.ts +++ b/std/node/_utils.ts @@ -65,8 +65,9 @@ function slowCases(enc: string): string | undefined { if (enc === "ucs2") return "utf16le"; break; case 3: - if (enc === "hex" || enc === "HEX" || `${enc}`.toLowerCase() === "hex") + if (enc === "hex" || enc === "HEX" || `${enc}`.toLowerCase() === "hex") { return "hex"; + } break; case 5: if (enc === "ascii") return "ascii"; @@ -93,16 +94,18 @@ function slowCases(enc: string): string | undefined { enc === "utf16le" || enc === "UTF16LE" || `${enc}`.toLowerCase() === "utf16le" - ) + ) { return "utf16le"; + } break; case 8: if ( enc === "utf-16le" || enc === "UTF-16LE" || `${enc}`.toLowerCase() === "utf-16le" - ) + ) { return "utf16le"; + } break; default: if (enc === "") return "utf8"; diff --git a/std/node/buffer.ts b/std/node/buffer.ts index 9c8d8784c..7656803d9 100644 --- a/std/node/buffer.ts +++ b/std/node/buffer.ts @@ -18,8 +18,9 @@ function checkEncoding(encoding = "utf8", strict = true): string { const normalized = normalizeEncoding(encoding); - if (normalized === undefined) + if (normalized === undefined) { throw new TypeError(`Unkown encoding: ${encoding}`); + } if (notImplementedEncodings.includes(encoding)) { notImplemented(`"${encoding}" encoding`); @@ -78,11 +79,11 @@ export default class Buffer extends Uint8Array { static alloc( size: number, fill?: number | string | Uint8Array | Buffer, - encoding = "utf8" + encoding = "utf8", ): Buffer { if (typeof size !== "number") { throw new TypeError( - `The "size" argument must be of type number. Received type ${typeof size}` + `The "size" argument must be of type number. Received type ${typeof size}`, ); } @@ -92,15 +93,17 @@ export default class Buffer extends Uint8Array { let bufFill; if (typeof fill === "string") { encoding = checkEncoding(encoding); - if (typeof fill === "string" && fill.length === 1 && encoding === "utf8") + if ( + typeof fill === "string" && fill.length === 1 && encoding === "utf8" + ) { buf.fill(fill.charCodeAt(0)); - else bufFill = Buffer.from(fill, encoding); + } else bufFill = Buffer.from(fill, encoding); } else if (typeof fill === "number") { buf.fill(fill); } else if (fill instanceof Uint8Array) { if (fill.length === 0) { throw new TypeError( - `The argument "value" is invalid. Received ${fill.constructor.name} []` + `The argument "value" is invalid. Received ${fill.constructor.name} []`, ); } @@ -108,8 +111,9 @@ export default class Buffer extends Uint8Array { } if (bufFill) { - if (bufFill.length > buf.length) + if (bufFill.length > buf.length) { bufFill = bufFill.subarray(0, buf.length); + } let offset = 0; while (offset < size) { @@ -136,7 +140,7 @@ export default class Buffer extends Uint8Array { */ static byteLength( string: string | Buffer | ArrayBufferView | ArrayBuffer | SharedArrayBuffer, - encoding = "utf8" + encoding = "utf8", ): number { if (typeof string != "string") return string.byteLength; @@ -180,7 +184,7 @@ export default class Buffer extends Uint8Array { static from( arrayBuffer: ArrayBuffer | SharedArrayBuffer, byteOffset?: number, - length?: number + length?: number, ): Buffer; /** * Copies the passed buffer data onto a new Buffer instance. @@ -194,12 +198,14 @@ export default class Buffer extends Uint8Array { // eslint-disable-next-line @typescript-eslint/no-explicit-any value: any, offsetOrEncoding?: number | string, - length?: number + length?: number, ): Buffer { - const offset = - typeof offsetOrEncoding === "string" ? undefined : offsetOrEncoding; - let encoding = - typeof offsetOrEncoding === "string" ? offsetOrEncoding : undefined; + const offset = typeof offsetOrEncoding === "string" + ? undefined + : offsetOrEncoding; + let encoding = typeof offsetOrEncoding === "string" + ? offsetOrEncoding + : undefined; if (typeof value == "string") { encoding = checkEncoding(encoding, false); @@ -236,7 +242,7 @@ export default class Buffer extends Uint8Array { targetBuffer: Buffer | Uint8Array, targetStart = 0, sourceStart = 0, - sourceEnd = this.length + sourceEnd = this.length, ): number { const sourceBuffer = this.subarray(sourceStart, sourceEnd); targetBuffer.set(sourceBuffer, targetStart); @@ -249,7 +255,7 @@ export default class Buffer extends Uint8Array { equals(otherBuffer: Uint8Array | Buffer): boolean { if (!(otherBuffer instanceof Uint8Array)) { throw new TypeError( - `The "otherBuffer" argument must be an instance of Buffer or Uint8Array. Received type ${typeof otherBuffer}` + `The "otherBuffer" argument must be an instance of Buffer or Uint8Array. Received type ${typeof otherBuffer}`, ); } @@ -267,14 +273,14 @@ export default class Buffer extends Uint8Array { return new DataView( this.buffer, this.byteOffset, - this.byteLength + this.byteLength, ).getBigInt64(offset); } readBigInt64LE(offset = 0): bigint { return new DataView( this.buffer, this.byteOffset, - this.byteLength + this.byteLength, ).getBigInt64(offset, true); } @@ -282,14 +288,14 @@ export default class Buffer extends Uint8Array { return new DataView( this.buffer, this.byteOffset, - this.byteLength + this.byteLength, ).getBigUint64(offset); } readBigUInt64LE(offset = 0): bigint { return new DataView( this.buffer, this.byteOffset, - this.byteLength + this.byteLength, ).getBigUint64(offset, true); } @@ -297,14 +303,14 @@ export default class Buffer extends Uint8Array { return new DataView( this.buffer, this.byteOffset, - this.byteLength + this.byteLength, ).getFloat64(offset); } readDoubleLE(offset = 0): number { return new DataView( this.buffer, this.byteOffset, - this.byteLength + this.byteLength, ).getFloat64(offset, true); } @@ -312,50 +318,50 @@ export default class Buffer extends Uint8Array { return new DataView( this.buffer, this.byteOffset, - this.byteLength + this.byteLength, ).getFloat32(offset); } readFloatLE(offset = 0): number { return new DataView( this.buffer, this.byteOffset, - this.byteLength + this.byteLength, ).getFloat32(offset, true); } readInt8(offset = 0): number { return new DataView(this.buffer, this.byteOffset, this.byteLength).getInt8( - offset + offset, ); } readInt16BE(offset = 0): number { return new DataView(this.buffer, this.byteOffset, this.byteLength).getInt16( - offset + offset, ); } readInt16LE(offset = 0): number { return new DataView(this.buffer, this.byteOffset, this.byteLength).getInt16( offset, - true + true, ); } readInt32BE(offset = 0): number { return new DataView(this.buffer, this.byteOffset, this.byteLength).getInt32( - offset + offset, ); } readInt32LE(offset = 0): number { return new DataView(this.buffer, this.byteOffset, this.byteLength).getInt32( offset, - true + true, ); } readUInt8(offset = 0): number { return new DataView(this.buffer, this.byteOffset, this.byteLength).getUint8( - offset + offset, ); } @@ -363,14 +369,14 @@ export default class Buffer extends Uint8Array { return new DataView( this.buffer, this.byteOffset, - this.byteLength + this.byteLength, ).getUint16(offset); } readUInt16LE(offset = 0): number { return new DataView( this.buffer, this.byteOffset, - this.byteLength + this.byteLength, ).getUint16(offset, true); } @@ -378,14 +384,14 @@ export default class Buffer extends Uint8Array { return new DataView( this.buffer, this.byteOffset, - this.byteLength + this.byteLength, ).getUint32(offset); } readUInt32LE(offset = 0): number { return new DataView( this.buffer, this.byteOffset, - this.byteLength + this.byteLength, ).getUint32(offset, true); } @@ -429,14 +435,14 @@ export default class Buffer extends Uint8Array { write(string: string, offset = 0, length = this.length): number { return new TextEncoder().encodeInto( string, - this.subarray(offset, offset + length) + this.subarray(offset, offset + length), ).written; } writeBigInt64BE(value: bigint, offset = 0): number { new DataView(this.buffer, this.byteOffset, this.byteLength).setBigInt64( offset, - value + value, ); return offset + 4; } @@ -444,7 +450,7 @@ export default class Buffer extends Uint8Array { new DataView(this.buffer, this.byteOffset, this.byteLength).setBigInt64( offset, value, - true + true, ); return offset + 4; } @@ -452,7 +458,7 @@ export default class Buffer extends Uint8Array { writeBigUInt64BE(value: bigint, offset = 0): number { new DataView(this.buffer, this.byteOffset, this.byteLength).setBigUint64( offset, - value + value, ); return offset + 4; } @@ -460,7 +466,7 @@ export default class Buffer extends Uint8Array { new DataView(this.buffer, this.byteOffset, this.byteLength).setBigUint64( offset, value, - true + true, ); return offset + 4; } @@ -468,7 +474,7 @@ export default class Buffer extends Uint8Array { writeDoubleBE(value: number, offset = 0): number { new DataView(this.buffer, this.byteOffset, this.byteLength).setFloat64( offset, - value + value, ); return offset + 8; } @@ -476,7 +482,7 @@ export default class Buffer extends Uint8Array { new DataView(this.buffer, this.byteOffset, this.byteLength).setFloat64( offset, value, - true + true, ); return offset + 8; } @@ -484,7 +490,7 @@ export default class Buffer extends Uint8Array { writeFloatBE(value: number, offset = 0): number { new DataView(this.buffer, this.byteOffset, this.byteLength).setFloat32( offset, - value + value, ); return offset + 4; } @@ -492,7 +498,7 @@ export default class Buffer extends Uint8Array { new DataView(this.buffer, this.byteOffset, this.byteLength).setFloat32( offset, value, - true + true, ); return offset + 4; } @@ -500,7 +506,7 @@ export default class Buffer extends Uint8Array { writeInt8(value: number, offset = 0): number { new DataView(this.buffer, this.byteOffset, this.byteLength).setInt8( offset, - value + value, ); return offset + 1; } @@ -508,7 +514,7 @@ export default class Buffer extends Uint8Array { writeInt16BE(value: number, offset = 0): number { new DataView(this.buffer, this.byteOffset, this.byteLength).setInt16( offset, - value + value, ); return offset + 2; } @@ -516,7 +522,7 @@ export default class Buffer extends Uint8Array { new DataView(this.buffer, this.byteOffset, this.byteLength).setInt16( offset, value, - true + true, ); return offset + 2; } @@ -524,7 +530,7 @@ export default class Buffer extends Uint8Array { writeInt32BE(value: number, offset = 0): number { new DataView(this.buffer, this.byteOffset, this.byteLength).setUint32( offset, - value + value, ); return offset + 4; } @@ -532,7 +538,7 @@ export default class Buffer extends Uint8Array { new DataView(this.buffer, this.byteOffset, this.byteLength).setInt32( offset, value, - true + true, ); return offset + 4; } @@ -540,7 +546,7 @@ export default class Buffer extends Uint8Array { writeUInt8(value: number, offset = 0): number { new DataView(this.buffer, this.byteOffset, this.byteLength).setUint8( offset, - value + value, ); return offset + 1; } @@ -548,7 +554,7 @@ export default class Buffer extends Uint8Array { writeUInt16BE(value: number, offset = 0): number { new DataView(this.buffer, this.byteOffset, this.byteLength).setUint16( offset, - value + value, ); return offset + 2; } @@ -556,7 +562,7 @@ export default class Buffer extends Uint8Array { new DataView(this.buffer, this.byteOffset, this.byteLength).setUint16( offset, value, - true + true, ); return offset + 2; } @@ -564,7 +570,7 @@ export default class Buffer extends Uint8Array { writeUInt32BE(value: number, offset = 0): number { new DataView(this.buffer, this.byteOffset, this.byteLength).setUint32( offset, - value + value, ); return offset + 4; } @@ -572,7 +578,7 @@ export default class Buffer extends Uint8Array { new DataView(this.buffer, this.byteOffset, this.byteLength).setUint32( offset, value, - true + true, ); return offset + 4; } diff --git a/std/node/buffer_test.ts b/std/node/buffer_test.ts index f96fa8e4b..5d01a4b67 100644 --- a/std/node/buffer_test.ts +++ b/std/node/buffer_test.ts @@ -22,7 +22,7 @@ Deno.test({ }, RangeError, "Invalid typed array length: -1", - "should throw on negative numbers" + "should throw on negative numbers", ); }, }); @@ -41,7 +41,7 @@ Deno.test({ }, TypeError, `The "size" argument must be of type number. Received type ${typeof size}`, - "should throw on non-number size" + "should throw on non-number size", ); } }, @@ -62,7 +62,7 @@ Deno.test({ }, TypeError, `The argument "value" is invalid. Received ${value.constructor.name} []`, - "should throw for empty Buffer/Uint8Array" + "should throw for empty Buffer/Uint8Array", ); } }, @@ -132,7 +132,7 @@ Deno.test({ fn() { assertEquals( Buffer.alloc(11, "aGVsbG8gd29ybGQ=", "base64"), - new Uint8Array([104, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100]) + new Uint8Array([104, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100]), ); }, }); @@ -142,7 +142,7 @@ Deno.test({ fn() { assertEquals( Buffer.alloc(4, "64656e6f", "hex"), - new Uint8Array([100, 101, 110, 111]) + new Uint8Array([100, 101, 110, 111]), ); }, }); @@ -152,7 +152,7 @@ Deno.test({ fn() { assertEquals( Buffer.alloc(13, "64656e6f", "hex").toString(), - "denodenodenod" + "denodenodenod", ); }, }); @@ -162,11 +162,11 @@ Deno.test({ fn() { assertEquals( Buffer.alloc(7, new Uint8Array([100, 101])), - new Uint8Array([100, 101, 100, 101, 100, 101, 100]) + new Uint8Array([100, 101, 100, 101, 100, 101, 100]), ); assertEquals( Buffer.alloc(6, new Uint8Array([100, 101])), - new Uint8Array([100, 101, 100, 101, 100, 101]) + new Uint8Array([100, 101, 100, 101, 100, 101]), ); }, }); @@ -176,7 +176,7 @@ Deno.test({ fn() { assertEquals( Buffer.alloc(1, new Uint8Array([100, 101])), - new Uint8Array([100]) + new Uint8Array([100]), ); }, }); @@ -186,11 +186,11 @@ Deno.test({ fn() { assertEquals( Buffer.alloc(6, new Buffer([100, 101])), - new Uint8Array([100, 101, 100, 101, 100, 101]) + new Uint8Array([100, 101, 100, 101, 100, 101]), ); assertEquals( Buffer.alloc(7, new Buffer([100, 101])), - new Uint8Array([100, 101, 100, 101, 100, 101, 100]) + new Uint8Array([100, 101, 100, 101, 100, 101, 100]), ); }, }); @@ -224,7 +224,7 @@ Deno.test({ assertEquals(Buffer.byteLength("aGkk", "base64"), 3); assertEquals( Buffer.byteLength("bHNrZGZsa3NqZmtsc2xrZmFqc2RsZmtqcw==", "base64"), - 25 + 25, ); // special padding assertEquals(Buffer.byteLength("aaa=", "base64"), 2); @@ -253,7 +253,7 @@ Deno.test({ assertEquals( Buffer.byteLength(Buffer.alloc(0)), Buffer.alloc(0).byteLength, - "Byte lenght differs on buffers" + "Byte lenght differs on buffers", ); }, }); @@ -306,7 +306,7 @@ Deno.test({ }, RangeError, "offset is out of bounds", - "should throw on negative numbers" + "should throw on negative numbers", ); }, }); @@ -319,7 +319,7 @@ Deno.test({ assertEquals( buffer.toString(), "test", - "Buffer to string should recover the string" + "Buffer to string should recover the string", ); }, }); @@ -330,13 +330,13 @@ Deno.test({ for (const encoding of ["hex", "HEX"]) { const buffer: Buffer = Buffer.from( "7468697320697320612074c3a97374", - encoding + encoding, ); assertEquals(buffer.length, 15, "Buffer length should be 15"); assertEquals( buffer.toString(), "this is a tést", - "Buffer to string should recover the string" + "Buffer to string should recover the string", ); } }, @@ -351,7 +351,7 @@ Deno.test({ assertEquals( buffer.toString(), "this is a tést", - "Buffer to string should recover the string" + "Buffer to string should recover the string", ); } }, @@ -365,7 +365,7 @@ Deno.test({ assertEquals( buffer.toString(encoding), "ZGVubyBsYW5k", - "Buffer to string should recover the string in base64" + "Buffer to string should recover the string in base64", ); } const b64 = "dGhpcyBpcyBhIHTDqXN0"; @@ -381,7 +381,7 @@ Deno.test({ assertEquals( buffer.toString(encoding), "64656e6f206c616e64", - "Buffer to string should recover the string" + "Buffer to string should recover the string", ); } const hex = "64656e6f206c616e64"; @@ -404,7 +404,7 @@ Deno.test({ }, TypeError, `Unkown encoding: ${encoding}`, - "Should throw on invalid encoding" + "Should throw on invalid encoding", ); } }, @@ -430,7 +430,7 @@ Deno.test({ Buffer.from("yes", encoding); }, TypeError, - `Unkown encoding: ${encoding}` + `Unkown encoding: ${encoding}`, ); } }, @@ -451,7 +451,7 @@ Deno.test({ }, Error, `"${encoding}" encoding`, - "Should throw on invalid encoding" + "Should throw on invalid encoding", ); assertThrows( @@ -462,7 +462,7 @@ Deno.test({ }, Error, `"${encoding}" encoding`, - "Should throw on invalid encoding" + "Should throw on invalid encoding", ); } }, @@ -476,7 +476,7 @@ Deno.test({ assertEquals( buffer.toString(), "test", - "Buffer to string should recover the string" + "Buffer to string should recover the string", ); }, }); @@ -501,7 +501,7 @@ Deno.test({ fn() { assertEquals( JSON.stringify(Buffer.from("deno")), - '{"type":"Buffer","data":[100,101,110,111]}' + '{"type":"Buffer","data":[100,101,110,111]}', ); }, }); @@ -578,7 +578,7 @@ Deno.test({ assertEquals(d.equals(d), true); assertEquals( d.equals(new Uint8Array([0x61, 0x62, 0x63, 0x64, 0x65])), - true + true, ); assertEquals(c.equals(d), false); @@ -589,7 +589,7 @@ Deno.test({ // @ts-ignore () => Buffer.alloc(1).equals("abc"), TypeError, - `The "otherBuffer" argument must be an instance of Buffer or Uint8Array. Received type string` + `The "otherBuffer" argument must be an instance of Buffer or Uint8Array. Received type string`, ); }, }); diff --git a/std/node/events.ts b/std/node/events.ts index ef547cc37..b267852aa 100644 --- a/std/node/events.ts +++ b/std/node/events.ts @@ -44,7 +44,7 @@ export default class EventEmitter { private _addListener( eventName: string | symbol, listener: Function | WrappedFunction, - prepend: boolean + prepend: boolean, ): this { this.emit("newListener", eventName, listener); if (this._events.has(eventName)) { @@ -64,7 +64,7 @@ export default class EventEmitter { const warning = new Error( `Possible EventEmitter memory leak detected. ${this.listenerCount(eventName)} ${eventName.toString()} listeners. - Use emitter.setMaxListeners() to increase limit` + Use emitter.setMaxListeners() to increase limit`, ); warning.name = "MaxListenersExceededWarning"; console.warn(warning); @@ -76,7 +76,7 @@ export default class EventEmitter { /** Alias for emitter.on(eventName, listener). */ public addListener( eventName: string | symbol, - listener: Function | WrappedFunction + listener: Function | WrappedFunction, ): this { return this._addListener(eventName, listener, false); } @@ -147,13 +147,13 @@ export default class EventEmitter { private _listeners( target: EventEmitter, eventName: string | symbol, - unwrap: boolean + unwrap: boolean, ): Function[] { if (!target._events.has(eventName)) { return []; } const eventListeners: Function[] = target._events.get( - eventName + eventName, ) as Function[]; return unwrap @@ -180,7 +180,7 @@ export default class EventEmitter { * including any wrappers (such as those created by .once()). */ public rawListeners( - eventName: string | symbol + eventName: string | symbol, ): Array<Function | WrappedFunction> { return this._listeners(this, eventName, false); } @@ -199,7 +199,7 @@ export default class EventEmitter { */ public on( eventName: string | symbol, - listener: Function | WrappedFunction + listener: Function | WrappedFunction, ): this { return this.addListener(eventName, listener); } @@ -217,7 +217,7 @@ export default class EventEmitter { // Wrapped function that calls EventEmitter.removeListener(eventName, self) on execution. private onceWrap( eventName: string | symbol, - listener: Function + listener: Function, ): WrappedFunction { const wrapper = function ( this: { @@ -239,7 +239,7 @@ export default class EventEmitter { context: this, }; const wrapped = (wrapper.bind( - wrapperContext + wrapperContext, ) as unknown) as WrappedFunction; wrapperContext.rawListener = wrapped; wrapped.listener = listener; @@ -255,7 +255,7 @@ export default class EventEmitter { */ public prependListener( eventName: string | symbol, - listener: Function | WrappedFunction + listener: Function | WrappedFunction, ): this { return this._addListener(eventName, listener, true); } @@ -267,7 +267,7 @@ export default class EventEmitter { */ public prependOnceListener( eventName: string | symbol, - listener: Function + listener: Function, ): this { const wrapped: WrappedFunction = this.onceWrap(eventName, listener); this.prependListener(eventName, wrapped); @@ -359,7 +359,7 @@ export { EventEmitter }; */ export function once( emitter: EventEmitter | EventTarget, - name: string + name: string, // eslint-disable-next-line @typescript-eslint/no-explicit-any ): Promise<any[]> { return new Promise((resolve, reject) => { @@ -371,7 +371,7 @@ export function once( (...args) => { resolve(args); }, - { once: true, passive: false, capture: false } + { once: true, passive: false, capture: false }, ); return; } else if (emitter instanceof EventEmitter) { @@ -429,7 +429,7 @@ interface AsyncInterable { */ export function on( emitter: EventEmitter, - event: string | symbol + event: string | symbol, ): AsyncInterable { // eslint-disable-next-line @typescript-eslint/no-explicit-any const unconsumedEventValues: any[] = []; diff --git a/std/node/events_test.ts b/std/node/events_test.ts index 58025ce84..62b20594c 100644 --- a/std/node/events_test.ts +++ b/std/node/events_test.ts @@ -93,9 +93,9 @@ Deno.test({ "event", (oneArg: string, twoArg: string, threeArg: string) => { eventsFired.push( - "event(" + oneArg + ", " + twoArg + ", " + threeArg + ")" + "event(" + oneArg + ", " + twoArg + ", " + threeArg + ")", ); - } + }, ); testEmitter.emit("event", 1, 2, 3); assertEquals(eventsFired, ["event(1)", "event(1, 2)", "event(1, 2, 3)"]); @@ -346,7 +346,7 @@ Deno.test({ assertEquals(rawListenersForEvent[0], listenerA); assertEquals( (rawListenersForOnceEvent[0] as WrappedFunction).listener, - listenerB + listenerB, ); }, }); @@ -361,7 +361,8 @@ Deno.test({ testEmitter.once("once-event", listenerA); const rawListenersForOnceEvent = testEmitter.rawListeners("once-event"); - const wrappedFn: WrappedFunction = rawListenersForOnceEvent[0] as WrappedFunction; + const wrappedFn: WrappedFunction = + rawListenersForOnceEvent[0] as WrappedFunction; wrappedFn.listener(); wrappedFn.listener(); wrappedFn.listener(); @@ -411,14 +412,14 @@ Deno.test({ ee.setMaxListeners(-1); }, Error, - "must be >= 0" + "must be >= 0", ); assertThrows( () => { ee.setMaxListeners(3.45); }, Error, - "must be 'an integer'" + "must be 'an integer'", ); }, }); @@ -434,7 +435,7 @@ Deno.test({ ee.emit("error"); }, Error, - "Unhandled error" + "Unhandled error", ); ee.on(EventEmitter.errorMonitor, () => { @@ -447,7 +448,7 @@ Deno.test({ ee.emit("error"); }, Error, - "Unhandled error" + "Unhandled error", ); assertEquals(events, ["errorMonitor event"]); diff --git a/std/node/module.ts b/std/node/module.ts index 8d13ff366..534fe88e4 100644 --- a/std/node/module.ts +++ b/std/node/module.ts @@ -71,7 +71,7 @@ function stat(filename: string): StatResult { function updateChildren( parent: Module | null, child: Module, - scan: boolean + scan: boolean, ): void { const children = parent && parent.children; if (children && !(scan && children.includes(child))) { @@ -164,7 +164,7 @@ class Module { require, this, filename, - dirname + dirname, ); if (requireDepth === 0) { statCache = null; @@ -177,7 +177,7 @@ class Module { * */ static _resolveLookupPaths( request: string, - parent: Module | null + parent: Module | null, ): string[] | null { if ( request.charAt(0) !== "." || @@ -208,7 +208,7 @@ class Module { request: string, parent: Module, isMain: boolean, - options?: { paths: string[] } + options?: { paths: string[] }, ): string { // Polyfills. if (nativeModuleCanBeRequiredByUsers(request)) { @@ -219,8 +219,7 @@ class Module { if (typeof options === "object" && options !== null) { if (Array.isArray(options.paths)) { - const isRelative = - request.startsWith("./") || + const isRelative = request.startsWith("./") || request.startsWith("../") || (isWindows && request.startsWith(".\\")) || request.startsWith("..\\"); @@ -278,7 +277,7 @@ class Module { static _findPath( request: string, paths: string[], - isMain: boolean + isMain: boolean, ): string | boolean { const absoluteRequest = path.isAbsolute(request); if (absoluteRequest) { @@ -287,16 +286,15 @@ class Module { return false; } - const cacheKey = - request + "\x00" + (paths.length === 1 ? paths[0] : paths.join("\x00")); + const cacheKey = request + "\x00" + + (paths.length === 1 ? paths[0] : paths.join("\x00")); const entry = Module._pathCache[cacheKey]; if (entry) { return entry; } let exts; - let trailingSlash = - request.length > 0 && + let trailingSlash = request.length > 0 && request.charCodeAt(request.length - 1) === CHAR_FORWARD_SLASH; if (!trailingSlash) { trailingSlash = /(?:^|\/)\.?\.$/.test(request); @@ -604,18 +602,18 @@ nativeModulePolyfill.set("os", createNativeModule("os", nodeOs)); nativeModulePolyfill.set("path", createNativeModule("path", nodePath)); nativeModulePolyfill.set( "querystring", - createNativeModule("querystring", nodeQueryString) + createNativeModule("querystring", nodeQueryString), ); nativeModulePolyfill.set( "string_decoder", - createNativeModule("string_decoder", nodeStringDecoder) + createNativeModule("string_decoder", nodeStringDecoder), ); nativeModulePolyfill.set("timers", createNativeModule("timers", nodeTimers)); nativeModulePolyfill.set("util", createNativeModule("util", nodeUtil)); function loadNativeModule( _filename: string, - request: string + request: string, ): Module | undefined { return nativeModulePolyfill.get(request); } @@ -662,7 +660,7 @@ function readPackage(requestPath: string): PackageInfo | null { let json: string | undefined; try { json = new TextDecoder().decode( - Deno.readFileSync(path.toNamespacedPath(jsonPath)) + Deno.readFileSync(path.toNamespacedPath(jsonPath)), ); } catch { // pass @@ -691,7 +689,7 @@ function readPackage(requestPath: string): PackageInfo | null { } function readPackageScope( - checkPath: string + checkPath: string, ): { path: string; data: PackageInfo } | false { const rootSeparatorIndex = checkPath.indexOf(path.sep); let separatorIndex; @@ -726,7 +724,7 @@ function tryPackage( requestPath: string, exts: string[], isMain: boolean, - _originalPath: string + _originalPath: string, ): string | false { const pkg = readPackageMain(requestPath); @@ -735,8 +733,7 @@ function tryPackage( } const filename = path.resolve(requestPath, pkg); - let actual = - tryFile(filename, isMain) || + let actual = tryFile(filename, isMain) || tryExtensions(filename, exts, isMain) || tryExtensions(path.resolve(filename, "index"), exts, isMain); if (actual === false) { @@ -744,7 +741,7 @@ function tryPackage( if (!actual) { const err = new Error( `Cannot find module '${filename}'. ` + - 'Please verify that the package.json has a valid "main" entry' + 'Please verify that the package.json has a valid "main" entry', ) as Error & { code: string }; err.code = "MODULE_NOT_FOUND"; throw err; @@ -779,7 +776,7 @@ function toRealPath(requestPath: string): string { function tryExtensions( p: string, exts: string[], - isMain: boolean + isMain: boolean, ): string | false { for (let i = 0; i < exts.length; i++) { const filename = tryFile(p + exts[i], isMain); @@ -826,7 +823,7 @@ function isConditionalDotExportSugar(exports: any, _basePath: string): boolean { '"exports" cannot ' + "contain some keys starting with '.' and some not. The exports " + "object must either be an object of package subpath keys or an " + - "object of main entry condition name keys only." + "object of main entry condition name keys only.", ); } } @@ -853,7 +850,7 @@ function applyExports(basePath: string, expansion: string): string { mapping, "", basePath, - mappingKey + mappingKey, ); } @@ -879,7 +876,7 @@ function applyExports(basePath: string, expansion: string): string { mapping, subpath, basePath, - mappingKey + mappingKey, ); } } @@ -888,7 +885,7 @@ function applyExports(basePath: string, expansion: string): string { const e = new Error( `Package exports for '${basePath}' do not define ` + - `a '${mappingKey}' subpath` + `a '${mappingKey}' subpath`, ) as Error & { code?: string }; e.code = "MODULE_NOT_FOUND"; throw e; @@ -901,7 +898,7 @@ const EXPORTS_PATTERN = /^((?:@[^/\\%]+\/)?[^./\\%][^/\\%]*)(\/.*)?$/; function resolveExports( nmPath: string, request: string, - absoluteRequest: boolean + absoluteRequest: boolean, ): string { // The implementation's behavior is meant to mirror resolution in ESM. if (!absoluteRequest) { @@ -923,7 +920,7 @@ function resolveExportsTarget( target: any, subpath: string, basePath: string, - mappingKey: string + mappingKey: string, ): string { if (typeof target === "string") { if ( @@ -957,7 +954,7 @@ function resolveExportsTarget( targetValue, subpath, basePath, - mappingKey + mappingKey, ); } catch (e) { if (e.code !== "MODULE_NOT_FOUND") throw e; @@ -972,7 +969,7 @@ function resolveExportsTarget( target.default, subpath, basePath, - mappingKey + mappingKey, ); } catch (e) { if (e.code !== "MODULE_NOT_FOUND") throw e; @@ -983,7 +980,7 @@ function resolveExportsTarget( if (mappingKey !== ".") { e = new Error( `Package exports for '${basePath}' do not define a ` + - `valid '${mappingKey}' target${subpath ? " for " + subpath : ""}` + `valid '${mappingKey}' target${subpath ? " for " + subpath : ""}`, ); } else { e = new Error(`No valid exports main found for '${basePath}'`); @@ -999,9 +996,9 @@ const nmLen = nmChars.length; // eslint-disable-next-line @typescript-eslint/no-explicit-any function emitCircularRequireWarning(prop: any): void { console.error( - `Accessing non-existent property '${String( - prop - )}' of module exports inside circular dependency` + `Accessing non-existent property '${ + String(prop) + }' of module exports inside circular dependency`, ); } @@ -1024,7 +1021,7 @@ const CircularRequirePrototypeWarningProxy = new Proxy( emitCircularRequireWarning(prop); return undefined; }, - } + }, ); // Object.prototype and ObjectProtoype refer to our 'primordials' versions @@ -1056,7 +1053,7 @@ type RequireWrapper = ( require: any, module: Module, __filename: string, - __dirname: string + __dirname: string, ) => void; function wrapSafe(filename: string, content: string): RequireWrapper { @@ -1099,8 +1096,8 @@ Module._extensions[".json"] = (module: Module, filename: string): void => { function createRequireFromPath(filename: string): RequireFunction { // Allow a directory to be passed as the filename - const trailingSlash = - filename.endsWith("/") || (isWindows && filename.endsWith("\\")); + const trailingSlash = filename.endsWith("/") || + (isWindows && filename.endsWith("\\")); const proxyPath = trailingSlash ? path.join(filename, "noop.js") : filename; diff --git a/std/node/module_test.ts b/std/node/module_test.ts index 30441a58d..bdc2f39d3 100644 --- a/std/node/module_test.ts +++ b/std/node/module_test.ts @@ -34,7 +34,7 @@ Deno.test("requireBuiltin", function () { const { readFileSync, isNull, extname } = require("./tests/cjs/cjs_builtin"); assertEquals( readFileSync("./node/_fs/testdata/hello.txt", { encoding: "utf8" }), - "hello world" + "hello world", ); assert(isNull(null)); assertEquals(extname("index.html"), ".html"); diff --git a/std/node/os.ts b/std/node/os.ts index afb472629..c312ffe0c 100644 --- a/std/node/os.ts +++ b/std/node/os.ts @@ -203,7 +203,7 @@ export function uptime(): number { /** Not yet implemented */ export function userInfo( /* eslint-disable-next-line @typescript-eslint/no-unused-vars */ - options: UserInfoOptions = { encoding: "utf-8" } + options: UserInfoOptions = { encoding: "utf-8" }, ): UserInfo { notImplemented(SEE_GITHUB_ISSUE); } diff --git a/std/node/os_test.ts b/std/node/os_test.ts index c5f39f635..34f8d0f87 100644 --- a/std/node/os_test.ts +++ b/std/node/os_test.ts @@ -54,14 +54,14 @@ Deno.test({ os.getPriority(3.15); }, Error, - "pid must be 'an integer'" + "pid must be 'an integer'", ); assertThrows( () => { os.getPriority(9999999999); }, Error, - "must be >= -2147483648 && <= 2147483647" + "must be >= -2147483648 && <= 2147483647", ); }, }); @@ -74,14 +74,14 @@ Deno.test({ os.setPriority(3.15, 0); }, Error, - "pid must be 'an integer'" + "pid must be 'an integer'", ); assertThrows( () => { os.setPriority(9999999999, 0); }, Error, - "pid must be >= -2147483648 && <= 2147483647" + "pid must be >= -2147483648 && <= 2147483647", ); }, }); @@ -94,28 +94,28 @@ Deno.test({ os.setPriority(0, 3.15); }, Error, - "priority must be 'an integer'" + "priority must be 'an integer'", ); assertThrows( () => { os.setPriority(0, -21); }, Error, - "priority must be >= -20 && <= 19" + "priority must be >= -20 && <= 19", ); assertThrows( () => { os.setPriority(0, 20); }, Error, - "priority must be >= -20 && <= 19" + "priority must be >= -20 && <= 19", ); assertThrows( () => { os.setPriority(0, 9999999999); }, Error, - "priority must be >= -20 && <= 19" + "priority must be >= -20 && <= 19", ); }, }); @@ -129,28 +129,28 @@ Deno.test({ os.setPriority(3.15); }, Error, - "priority must be 'an integer'" + "priority must be 'an integer'", ); assertThrows( () => { os.setPriority(-21); }, Error, - "priority must be >= -20 && <= 19" + "priority must be >= -20 && <= 19", ); assertThrows( () => { os.setPriority(20); }, Error, - "priority must be >= -20 && <= 19" + "priority must be >= -20 && <= 19", ); assertThrows( () => { os.setPriority(9999999999); }, Error, - "priority must be >= -20 && <= 19" + "priority must be >= -20 && <= 19", ); }, }); @@ -207,63 +207,63 @@ Deno.test({ os.cpus(); }, Error, - "Not implemented" + "Not implemented", ); assertThrows( () => { os.freemem(); }, Error, - "Not implemented" + "Not implemented", ); assertThrows( () => { os.getPriority(); }, Error, - "Not implemented" + "Not implemented", ); assertThrows( () => { os.networkInterfaces(); }, Error, - "Not implemented" + "Not implemented", ); assertThrows( () => { os.setPriority(0); }, Error, - "Not implemented" + "Not implemented", ); assertThrows( () => { os.totalmem(); }, Error, - "Not implemented" + "Not implemented", ); assertThrows( () => { os.type(); }, Error, - "Not implemented" + "Not implemented", ); assertThrows( () => { os.uptime(); }, Error, - "Not implemented" + "Not implemented", ); assertThrows( () => { os.userInfo(); }, Error, - "Not implemented" + "Not implemented", ); }, }); diff --git a/std/node/process_test.ts b/std/node/process_test.ts index c4332af33..2674b725f 100644 --- a/std/node/process_test.ts +++ b/std/node/process_test.ts @@ -44,7 +44,7 @@ Deno.test({ process.chdir("non-existent-directory-name"); }, Deno.errors.NotFound, - "file" + "file", // On every OS Deno returns: "No such file" except for Windows, where it's: // "The system cannot find the file specified. (os error 2)" so "file" is // the only common string here. @@ -95,7 +95,7 @@ Deno.test({ process.on("uncaughtException", (_err: Error) => {}); }, Error, - "implemented" + "implemented", ); }, }); @@ -107,7 +107,7 @@ Deno.test({ assert(Array.isArray(argv)); assert( process.argv[0].match(/[^/\\]*deno[^/\\]*$/), - "deno included in the file name of argv[0]" + "deno included in the file name of argv[0]", ); // we cannot test for anything else (we see test runner arguments here) }, diff --git a/std/node/querystring.ts b/std/node/querystring.ts index bed327337..4e3c728c1 100644 --- a/std/node/querystring.ts +++ b/std/node/querystring.ts @@ -5,14 +5,15 @@ interface ParseOptions { maxKeys?: number; } export const hexTable = new Array(256); -for (let i = 0; i < 256; ++i) +for (let i = 0; i < 256; ++i) { hexTable[i] = "%" + ((i < 16 ? "0" : "") + i.toString(16)).toUpperCase(); +} export function parse( str: string, sep = "&", eq = "=", - { decodeURIComponent = unescape, maxKeys = 1000 }: ParseOptions = {} + { decodeURIComponent = unescape, maxKeys = 1000 }: ParseOptions = {}, ): { [key: string]: string[] | string } { const entries = str .split(sep) @@ -49,7 +50,7 @@ interface StringifyOptions { export function encodeStr( str: string, noEscapeTable: number[], - hexTable: string[] + hexTable: string[], ): string { const len = str.length; if (len === 0) return ""; @@ -78,8 +79,7 @@ export function encodeStr( } if (c < 0xd800 || c >= 0xe000) { lastPos = i + 1; - out += - hexTable[0xe0 | (c >> 12)] + + out += hexTable[0xe0 | (c >> 12)] + hexTable[0x80 | ((c >> 6) & 0x3f)] + hexTable[0x80 | (c & 0x3f)]; continue; @@ -96,8 +96,7 @@ export function encodeStr( lastPos = i + 1; c = 0x10000 + (((c & 0x3ff) << 10) | c2); - out += - hexTable[0xf0 | (c >> 18)] + + out += hexTable[0xf0 | (c >> 18)] + hexTable[0x80 | ((c >> 12) & 0x3f)] + hexTable[0x80 | ((c >> 6) & 0x3f)] + hexTable[0x80 | (c & 0x3f)]; @@ -111,7 +110,7 @@ export function stringify( obj: object, sep = "&", eq = "=", - { encodeURIComponent = escape }: StringifyOptions = {} + { encodeURIComponent = escape }: StringifyOptions = {}, ): string { const final = []; diff --git a/std/node/querystring_test.ts b/std/node/querystring_test.ts index 63abf471b..6ce681ca5 100644 --- a/std/node/querystring_test.ts +++ b/std/node/querystring_test.ts @@ -11,7 +11,7 @@ Deno.test({ c: true, d: ["foo", "bar"], }), - "a=hello&b=5&c=true&d=foo&d=bar" + "a=hello&b=5&c=true&d=foo&d=bar", ); }, }); diff --git a/std/node/string_decoder.ts b/std/node/string_decoder.ts index 7f167ad3c..ce7c19538 100644 --- a/std/node/string_decoder.ts +++ b/std/node/string_decoder.ts @@ -31,8 +31,9 @@ enum NotImplemented { function normalizeEncoding(enc?: string): string { const encoding = castEncoding(enc ?? null); if (encoding && encoding in NotImplemented) notImplemented(encoding); - if (!encoding && typeof enc === "string" && enc.toLowerCase() !== "raw") + if (!encoding && typeof enc === "string" && enc.toLowerCase() !== "raw") { throw new Error(`Unknown encoding: ${enc}`); + } return String(encoding); } /* @@ -55,7 +56,7 @@ function utf8CheckByte(byte: number): number { function utf8CheckIncomplete( self: StringDecoderBase, buf: Buffer, - i: number + i: number, ): number { let j = buf.length - 1; if (j < i) return 0; @@ -94,7 +95,7 @@ function utf8CheckIncomplete( * */ function utf8CheckExtraBytes( self: StringDecoderBase, - buf: Buffer + buf: Buffer, ): string | undefined { if ((buf[0] & 0xc0) !== 0x80) { self.lastNeed = 0; @@ -119,7 +120,7 @@ function utf8CheckExtraBytes( * */ function utf8FillLastComplete( this: StringDecoderBase, - buf: Buffer + buf: Buffer, ): string | undefined { const p = this.lastTotal - this.lastNeed; const r = utf8CheckExtraBytes(this, buf); @@ -137,7 +138,7 @@ function utf8FillLastComplete( * */ function utf8FillLastIncomplete( this: StringDecoderBase, - buf: Buffer + buf: Buffer, ): string | undefined { if (this.lastNeed <= buf.length) { buf.copy(this.lastChar, this.lastTotal - this.lastNeed, 0, this.lastNeed); @@ -203,8 +204,9 @@ function base64Text(this: StringDecoderBase, buf: Buffer, i: number): string { function base64End(this: Base64Decoder, buf?: Buffer): string { const r = buf && buf.length ? this.write(buf) : ""; - if (this.lastNeed) + if (this.lastNeed) { return r + this.lastChar.toString("base64", 0, 3 - this.lastNeed); + } return r; } diff --git a/std/node/string_decoder_test.ts b/std/node/string_decoder_test.ts index 69bb8402a..de32b6815 100644 --- a/std/node/string_decoder_test.ts +++ b/std/node/string_decoder_test.ts @@ -22,7 +22,7 @@ Deno.test({ decoder = new StringDecoder("utf8"); assertEquals( decoder.write(Buffer.from("\ufffd\ufffd\ufffd")), - "\ufffd\ufffd\ufffd" + "\ufffd\ufffd\ufffd", ); assertEquals(decoder.end(), ""); @@ -60,7 +60,7 @@ Deno.test({ decoder = new StringDecoder("base64"); assertEquals( decoder.write(Buffer.from("\ufffd\ufffd\ufffd")), - "77+977+977+9" + "77+977+977+9", ); assertEquals(decoder.end(), ""); @@ -98,7 +98,7 @@ Deno.test({ decoder = new StringDecoder("hex"); assertEquals( decoder.write(Buffer.from("\ufffd\ufffd\ufffd")), - "efbfbdefbfbdefbfbd" + "efbfbdefbfbdefbfbd", ); assertEquals(decoder.end(), ""); diff --git a/std/node/url.ts b/std/node/url.ts index b0034d02d..826a274f8 100644 --- a/std/node/url.ts +++ b/std/node/url.ts @@ -38,12 +38,14 @@ const tabRegEx = /\t/g; export function fileURLToPath(path: string | URL): string { if (typeof path === "string") path = new URL(path); - else if (!(path instanceof URL)) + else if (!(path instanceof URL)) { throw new Deno.errors.InvalidData( - "invalid argument path , must be a string or URL" + "invalid argument path , must be a string or URL", ); - if (path.protocol !== "file:") + } + if (path.protocol !== "file:") { throw new Deno.errors.InvalidData("invalid url scheme"); + } return isWindows ? getPathFromURLWin(path) : getPathFromURLPosix(path); } @@ -59,7 +61,7 @@ function getPathFromURLWin(url: URL): string { ) { // 5c 5C \ throw new Deno.errors.InvalidData( - "must not include encoded \\ or / characters" + "must not include encoded \\ or / characters", ); } } @@ -95,7 +97,7 @@ function getPathFromURLPosix(url: URL): string { const third = pathname.codePointAt(n + 2) || 0x20; if (pathname[n + 1] === "2" && third === 102) { throw new Deno.errors.InvalidData( - "must not include encoded / characters" + "must not include encoded / characters", ); } } @@ -111,16 +113,19 @@ export function pathToFileURL(filepath: string): URL { (filePathLast === CHAR_FORWARD_SLASH || (isWindows && filePathLast === CHAR_BACKWARD_SLASH)) && resolved[resolved.length - 1] !== path.sep - ) + ) { resolved += "/"; + } const outURL = new URL("file://"); if (resolved.includes("%")) resolved = resolved.replace(percentRegEx, "%25"); // In posix, "/" is a valid character in paths - if (!isWindows && resolved.includes("\\")) + if (!isWindows && resolved.includes("\\")) { resolved = resolved.replace(backslashRegEx, "%5C"); + } if (resolved.includes("\n")) resolved = resolved.replace(newlineRegEx, "%0A"); - if (resolved.includes("\r")) + if (resolved.includes("\r")) { resolved = resolved.replace(carriageReturnRegEx, "%0D"); + } if (resolved.includes("\t")) resolved = resolved.replace(tabRegEx, "%09"); outURL.pathname = resolved; return outURL; diff --git a/std/node/util.ts b/std/node/util.ts index e046aba9c..8e3c50b87 100644 --- a/std/node/util.ts +++ b/std/node/util.ts @@ -62,7 +62,7 @@ export function validateIntegerRange( value: number, name: string, min = -2147483648, - max = 2147483647 + max = 2147483647, ): void { // The defaults for min and max correspond to the limits of 32-bit integers. if (!Number.isInteger(value)) { @@ -70,7 +70,7 @@ export function validateIntegerRange( } if (value < min || value > max) { throw new Error( - `${name} must be >= ${min} && <= ${max}. Value was ${value}` + `${name} must be >= ${min} && <= ${max}. Value was ${value}`, ); } } |