1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-26 16:09:27 -05:00

bump prettier to 1.18.2 (denoland/deno_std#592)

Original: 06958a4ada
This commit is contained in:
Axetroy 2019-09-12 11:31:23 +08:00 committed by Ryan Dahl
parent 08087e921e
commit 878a9a29e7
37 changed files with 775 additions and 711 deletions

View file

@ -384,8 +384,7 @@ export class Tar {
*/ */
getReader(): Deno.Reader { getReader(): Deno.Reader {
const readers: Deno.Reader[] = []; const readers: Deno.Reader[] = [];
this.data.forEach( this.data.forEach((tarData): void => {
(tarData): void => {
let { filePath, reader } = tarData, let { filePath, reader } = tarData,
headerArr = formatHeader(tarData); headerArr = formatHeader(tarData);
readers.push(new Deno.Buffer(headerArr)); readers.push(new Deno.Buffer(headerArr));
@ -403,8 +402,7 @@ export class Tar {
) )
) )
); );
} });
);
// append 2 empty records // append 2 empty records
readers.push(new Deno.Buffer(clean(recordSize * 2))); readers.push(new Deno.Buffer(clean(recordSize * 2)));
@ -461,22 +459,18 @@ export class Untar {
"mtime", "mtime",
"uid", "uid",
"gid" "gid"
]).forEach( ]).forEach((key): void => {
(key): void => {
const arr = trim(header[key]); const arr = trim(header[key]);
if (arr.byteLength > 0) { if (arr.byteLength > 0) {
meta[key] = parseInt(decoder.decode(arr), 8); meta[key] = parseInt(decoder.decode(arr), 8);
} }
} });
); (["owner", "group"] as ["owner", "group"]).forEach((key): void => {
(["owner", "group"] as ["owner", "group"]).forEach(
(key): void => {
const arr = trim(header[key]); const arr = trim(header[key]);
if (arr.byteLength > 0) { if (arr.byteLength > 0) {
meta[key] = decoder.decode(arr); meta[key] = decoder.decode(arr);
} }
} });
);
// read the file content // read the file content
const len = parseInt(decoder.decode(header.fileSize), 8); const len = parseInt(decoder.decode(header.fileSize), 8);

View file

@ -69,8 +69,7 @@ export function instantiate(
assert(module != null); assert(module != null);
assert(module.factory != null); assert(module.factory != null);
const dependencies = module.dependencies.map( const dependencies = module.dependencies.map((id): object => {
(id): object => {
if (id === "require") { if (id === "require") {
// TODO(kitsonk) support dynamic import by passing a `require()` that // TODO(kitsonk) support dynamic import by passing a `require()` that
// can return a local module or dynamically import one. // can return a local module or dynamically import one.
@ -81,8 +80,7 @@ export function instantiate(
const dep = modules.get(id)!; const dep = modules.get(id)!;
assert(dep != null); assert(dep != null);
return dep.exports; return dep.exports;
} });
);
if (typeof module.factory === "function") { if (typeof module.factory === "function") {
module.factory!(...dependencies); module.factory!(...dependencies);

View file

@ -84,8 +84,7 @@ async function read(
result = line.split(opt.comma!); result = line.split(opt.comma!);
let quoteError = false; let quoteError = false;
result = result.map( result = result.map((r): string => {
(r): string => {
if (opt.trimLeadingSpace) { if (opt.trimLeadingSpace) {
r = r.trimLeft(); r = r.trimLeft();
} }
@ -101,8 +100,7 @@ async function read(
} }
} }
return r; return r;
} });
);
if (quoteError) { if (quoteError) {
throw new ParseError(Startline, lineIndex, 'bare " in non-quoted-field'); throw new ParseError(Startline, lineIndex, 'bare " in non-quoted-field');
} }
@ -226,8 +224,7 @@ export async function parse(
); );
i++; i++;
} }
return r.map( return r.map((e): unknown => {
(e): unknown => {
if (e.length !== headers.length) { if (e.length !== headers.length) {
throw `Error number of fields line:${i}`; throw `Error number of fields line:${i}`;
} }
@ -245,8 +242,7 @@ export async function parse(
return opt.parse(out); return opt.parse(out);
} }
return out; return out;
} });
);
} }
if (opt.parse) { if (opt.parse) {
return r.map((e: string[]): unknown => opt.parse!(e)); return r.map((e: string[]): unknown => opt.parse!(e));

View file

@ -403,24 +403,20 @@ class Dumper {
_parse(obj: Record<string, unknown>, path: string = ""): string[] { _parse(obj: Record<string, unknown>, path: string = ""): string[] {
const out = []; const out = [];
const props = Object.keys(obj); const props = Object.keys(obj);
const propObj = props.filter( const propObj = props.filter((e: string): boolean => {
(e: string): boolean => {
if (obj[e] instanceof Array) { if (obj[e] instanceof Array) {
const d: unknown[] = obj[e] as unknown[]; const d: unknown[] = obj[e] as unknown[];
return !this._isSimplySerializable(d[0]); return !this._isSimplySerializable(d[0]);
} }
return !this._isSimplySerializable(obj[e]); return !this._isSimplySerializable(obj[e]);
} });
); const propPrim = props.filter((e: string): boolean => {
const propPrim = props.filter(
(e: string): boolean => {
if (obj[e] instanceof Array) { if (obj[e] instanceof Array) {
const d: unknown[] = obj[e] as unknown[]; const d: unknown[] = obj[e] as unknown[];
return this._isSimplySerializable(d[0]); return this._isSimplySerializable(d[0]);
} }
return this._isSimplySerializable(obj[e]); return this._isSimplySerializable(obj[e]);
} });
);
const k = propPrim.concat(propObj); const k = propPrim.concat(propObj);
for (let i = 0; i < k.length; i++) { for (let i = 0; i < k.length; i++) {
const prop = k[i]; const prop = k[i];

View file

@ -79,11 +79,9 @@ export function parse(
? [options.boolean] ? [options.boolean]
: options.boolean; : options.boolean;
booleanArgs.filter(Boolean).forEach( booleanArgs.filter(Boolean).forEach((key: string): void => {
(key: string): void => {
flags.bools[key] = true; flags.bools[key] = true;
} });
);
} }
} }
@ -114,11 +112,9 @@ export function parse(
flags.strings[key] = true; flags.strings[key] = true;
const alias = get(aliases, key); const alias = get(aliases, key);
if (alias) { if (alias) {
alias.forEach( alias.forEach((alias: string): void => {
(alias: string): void => {
flags.strings[alias] = true; flags.strings[alias] = true;
} });
);
} }
}); });
} }

View file

@ -587,8 +587,7 @@ const tests: Array<[string, any, string]> = [
]; ];
test(function testThorough(): void { test(function testThorough(): void {
tests.forEach( tests.forEach((t, i): void => {
(t, i): void => {
// p(t) // p(t)
let is = S(t[0], t[1]); let is = S(t[0], t[1]);
let should = t[2]; let should = t[2];
@ -597,8 +596,7 @@ test(function testThorough(): void {
should, should,
`failed case[${i}] : is >${is}< should >${should}<` `failed case[${i}] : is >${is}< should >${should}<`
); );
} });
);
}); });
test(function testWeirdos(): void { test(function testWeirdos(): void {

View file

@ -317,11 +317,9 @@ testCopySync(
(tempDir: string): void => { (tempDir: string): void => {
const srcFile = path.join(testdataDir, "copy_file_not_exists_sync.txt"); const srcFile = path.join(testdataDir, "copy_file_not_exists_sync.txt");
const destFile = path.join(tempDir, "copy_file_not_exists_1_sync.txt"); const destFile = path.join(tempDir, "copy_file_not_exists_1_sync.txt");
assertThrows( assertThrows((): void => {
(): void => {
copySync(srcFile, destFile); copySync(srcFile, destFile);
} });
);
} }
); );
@ -367,9 +365,7 @@ testCopySync(
} }
); );
testCopySync( testCopySync("[fs] copy file synchronously", (tempDir: string): void => {
"[fs] copy file synchronously",
(tempDir: string): void => {
const srcFile = path.join(testdataDir, "copy_file.txt"); const srcFile = path.join(testdataDir, "copy_file.txt");
const destFile = path.join(tempDir, "copy_file_copy_sync.txt"); const destFile = path.join(tempDir, "copy_file_copy_sync.txt");
@ -409,8 +405,7 @@ testCopySync(
// Make sure the file has been overwritten. // Make sure the file has been overwritten.
assertEquals(new TextDecoder().decode(Deno.readFileSync(destFile)), "txt"); assertEquals(new TextDecoder().decode(Deno.readFileSync(destFile)), "txt");
} });
);
testCopySync( testCopySync(
"[fs] copy directory synchronously to its subdirectory", "[fs] copy directory synchronously to its subdirectory",
@ -450,9 +445,7 @@ testCopySync(
} }
); );
testCopySync( testCopySync("[fs] copy directory synchronously", (tempDir: string): void => {
"[fs] copy directory synchronously",
(tempDir: string): void => {
const srcDir = path.join(testdataDir, "copy_dir"); const srcDir = path.join(testdataDir, "copy_dir");
const destDir = path.join(tempDir, "copy_dir_copy_sync"); const destDir = path.join(tempDir, "copy_dir_copy_sync");
const srcFile = path.join(srcDir, "0.txt"); const srcFile = path.join(srcDir, "0.txt");
@ -499,8 +492,7 @@ testCopySync(
new TextDecoder().decode(Deno.readFileSync(destNestFile)), new TextDecoder().decode(Deno.readFileSync(destNestFile)),
"nest" "nest"
); );
} });
);
testCopySync( testCopySync(
"[fs] copy symlink file synchronously", "[fs] copy symlink file synchronously",

View file

@ -110,18 +110,14 @@ test(function emptyDirSyncIfItExist(): void {
assertEquals(stat.isDirectory(), true); assertEquals(stat.isDirectory(), true);
// nest directory have been remove // nest directory have been remove
assertThrows( assertThrows((): void => {
(): void => {
Deno.statSync(testNestDir); Deno.statSync(testNestDir);
} });
);
// test file have been remove // test file have been remove
assertThrows( assertThrows((): void => {
(): void => {
Deno.statSync(testDirFile); Deno.statSync(testDirFile);
} });
);
} finally { } finally {
// remote test dir // remote test dir
Deno.removeSync(testDir, { recursive: true }); Deno.removeSync(testDir, { recursive: true });

View file

@ -15,11 +15,9 @@ test(async function ensureDirIfItNotExist(): Promise<void> {
await assertThrowsAsync( await assertThrowsAsync(
async (): Promise<void> => { async (): Promise<void> => {
await Deno.stat(testDir).then( await Deno.stat(testDir).then((): void => {
(): void => {
throw new Error("test dir should exists."); throw new Error("test dir should exists.");
} });
);
} }
); );
@ -48,11 +46,9 @@ test(async function ensureDirIfItExist(): Promise<void> {
await assertThrowsAsync( await assertThrowsAsync(
async (): Promise<void> => { async (): Promise<void> => {
await Deno.stat(testDir).then( await Deno.stat(testDir).then((): void => {
(): void => {
throw new Error("test dir should still exists."); throw new Error("test dir should still exists.");
} });
);
} }
); );
@ -68,12 +64,10 @@ test(function ensureDirSyncIfItExist(): void {
ensureDirSync(testDir); ensureDirSync(testDir);
assertThrows( assertThrows((): void => {
(): void => {
Deno.statSync(testDir); Deno.statSync(testDir);
throw new Error("test dir should still exists."); throw new Error("test dir should still exists.");
} });
);
Deno.removeSync(baseDir, { recursive: true }); Deno.removeSync(baseDir, { recursive: true });
}); });

View file

@ -14,11 +14,9 @@ test(async function ensureFileIfItNotExist(): Promise<void> {
await assertThrowsAsync( await assertThrowsAsync(
async (): Promise<void> => { async (): Promise<void> => {
await Deno.stat(testFile).then( await Deno.stat(testFile).then((): void => {
(): void => {
throw new Error("test file should exists."); throw new Error("test file should exists.");
} });
);
} }
); );
@ -31,12 +29,10 @@ test(function ensureFileSyncIfItNotExist(): void {
ensureFileSync(testFile); ensureFileSync(testFile);
assertThrows( assertThrows((): void => {
(): void => {
Deno.statSync(testFile); Deno.statSync(testFile);
throw new Error("test file should exists."); throw new Error("test file should exists.");
} });
);
Deno.removeSync(testDir, { recursive: true }); Deno.removeSync(testDir, { recursive: true });
}); });
@ -52,11 +48,9 @@ test(async function ensureFileIfItExist(): Promise<void> {
await assertThrowsAsync( await assertThrowsAsync(
async (): Promise<void> => { async (): Promise<void> => {
await Deno.stat(testFile).then( await Deno.stat(testFile).then((): void => {
(): void => {
throw new Error("test file should exists."); throw new Error("test file should exists.");
} });
);
} }
); );
@ -72,12 +66,10 @@ test(function ensureFileSyncIfItExist(): void {
ensureFileSync(testFile); ensureFileSync(testFile);
assertThrows( assertThrows((): void => {
(): void => {
Deno.statSync(testFile); Deno.statSync(testFile);
throw new Error("test file should exists."); throw new Error("test file should exists.");
} });
);
Deno.removeSync(testDir, { recursive: true }); Deno.removeSync(testDir, { recursive: true });
}); });

View file

@ -31,11 +31,9 @@ test(function ensureLinkSyncIfItNotExist(): void {
const testFile = path.join(testDir, "test.txt"); const testFile = path.join(testDir, "test.txt");
const linkFile = path.join(testDir, "link.txt"); const linkFile = path.join(testDir, "link.txt");
assertThrows( assertThrows((): void => {
(): void => {
ensureLinkSync(testFile, linkFile); ensureLinkSync(testFile, linkFile);
} });
);
Deno.removeSync(testDir, { recursive: true }); Deno.removeSync(testDir, { recursive: true });
}); });

View file

@ -24,11 +24,9 @@ test(async function ensureSymlinkIfItNotExist(): Promise<void> {
assertThrowsAsync( assertThrowsAsync(
async (): Promise<void> => { async (): Promise<void> => {
await Deno.stat(testFile).then( await Deno.stat(testFile).then((): void => {
(): void => {
throw new Error("test file should exists."); throw new Error("test file should exists.");
} });
);
} }
); );
}); });
@ -37,18 +35,14 @@ test(function ensureSymlinkSyncIfItNotExist(): void {
const testDir = path.join(testdataDir, "link_file_2"); const testDir = path.join(testdataDir, "link_file_2");
const testFile = path.join(testDir, "test.txt"); const testFile = path.join(testDir, "test.txt");
assertThrows( assertThrows((): void => {
(): void => {
ensureSymlinkSync(testFile, path.join(testDir, "test1.txt")); ensureSymlinkSync(testFile, path.join(testDir, "test1.txt"));
} });
);
assertThrows( assertThrows((): void => {
(): void => {
Deno.statSync(testFile); Deno.statSync(testFile);
throw new Error("test file should exists."); throw new Error("test file should exists.");
} });
);
}); });
test(async function ensureSymlinkIfItExist(): Promise<void> { test(async function ensureSymlinkIfItExist(): Promise<void> {

View file

@ -182,11 +182,9 @@ test(function moveSyncDirectoryIfSrcNotExists(): void {
const srcDir = path.join(testdataDir, "move_sync_test_src_1"); const srcDir = path.join(testdataDir, "move_sync_test_src_1");
const destDir = path.join(testdataDir, "move_sync_test_dest_1"); const destDir = path.join(testdataDir, "move_sync_test_dest_1");
// if src directory not exist // if src directory not exist
assertThrows( assertThrows((): void => {
(): void => {
moveSync(srcDir, destDir); moveSync(srcDir, destDir);
} });
);
}); });
test(function moveSyncDirectoryIfDestNotExists(): void { test(function moveSyncDirectoryIfDestNotExists(): void {
@ -213,11 +211,9 @@ test(function moveSyncFileIfSrcNotExists(): void {
const destFile = path.join(testdataDir, "move_sync_test_dest_3", "test.txt"); const destFile = path.join(testdataDir, "move_sync_test_dest_3", "test.txt");
// if src directory not exist // if src directory not exist
assertThrows( assertThrows((): void => {
(): void => {
moveSync(srcFile, destFile); moveSync(srcFile, destFile);
} });
);
}); });
test(function moveSyncFileIfDestExists(): void { test(function moveSyncFileIfDestExists(): void {

View file

@ -65,31 +65,25 @@ test(async function readValidObjJsonFileWithRelativePath(): Promise<void> {
test(function readJsonFileNotExistsSync(): void { test(function readJsonFileNotExistsSync(): void {
const emptyJsonFile = path.join(testdataDir, "json_not_exists.json"); const emptyJsonFile = path.join(testdataDir, "json_not_exists.json");
assertThrows( assertThrows((): void => {
(): void => {
readJsonSync(emptyJsonFile); readJsonSync(emptyJsonFile);
} });
);
}); });
test(function readEmptyJsonFileSync(): void { test(function readEmptyJsonFileSync(): void {
const emptyJsonFile = path.join(testdataDir, "json_empty.json"); const emptyJsonFile = path.join(testdataDir, "json_empty.json");
assertThrows( assertThrows((): void => {
(): void => {
readJsonSync(emptyJsonFile); readJsonSync(emptyJsonFile);
} });
);
}); });
test(function readInvalidJsonFile(): void { test(function readInvalidJsonFile(): void {
const invalidJsonFile = path.join(testdataDir, "json_invalid.json"); const invalidJsonFile = path.join(testdataDir, "json_invalid.json");
assertThrows( assertThrows((): void => {
(): void => {
readJsonSync(invalidJsonFile); readJsonSync(invalidJsonFile);
} });
);
}); });
test(function readValidArrayJsonFileSync(): void { test(function readValidArrayJsonFileSync(): void {

View file

@ -19,13 +19,11 @@ function patternTest(patterns: RegExp[], path: string): boolean {
// Forced to reset last index on regex while iterating for have // Forced to reset last index on regex while iterating for have
// consistent results. // consistent results.
// See: https://stackoverflow.com/a/1520853 // See: https://stackoverflow.com/a/1520853
return patterns.some( return patterns.some((pattern): boolean => {
(pattern): boolean => {
let r = pattern.test(path); let r = pattern.test(path);
pattern.lastIndex = 0; pattern.lastIndex = 0;
return r; return r;
} });
);
} }
function include(filename: string, options: WalkOptions): boolean { function include(filename: string, options: WalkOptions): boolean {

View file

@ -75,11 +75,9 @@ function modeToString(isDir: boolean, maybeMode: number | null): string {
.split("") .split("")
.reverse() .reverse()
.slice(0, 3) .slice(0, 3)
.forEach( .forEach((v): void => {
(v): void => {
output = modeMap[+v] + output; output = modeMap[+v] + output;
} });
);
output = `(${isDir ? "d" : "-"}${output})`; output = `(${isDir ? "d" : "-"}${output})`;
return output; return output;
} }
@ -179,8 +177,7 @@ async function serveDir(
dirViewerTemplate.replace("<%DIRNAME%>", formattedDirUrl).replace( dirViewerTemplate.replace("<%DIRNAME%>", formattedDirUrl).replace(
"<%CONTENTS%>", "<%CONTENTS%>",
listEntry listEntry
.sort( .sort((a, b): number =>
(a, b): number =>
a.name.toLowerCase() > b.name.toLowerCase() ? 1 : -1 a.name.toLowerCase() > b.name.toLowerCase() ? 1 : -1
) )
.map((v): string => v.template) .map((v): string => v.template)

View file

@ -504,11 +504,9 @@ test({
let serverIsRunning = true; let serverIsRunning = true;
p.status() p.status()
.then( .then((): void => {
(): void => {
serverIsRunning = false; serverIsRunning = false;
} })
)
.catch((_): void => {}); // Ignores the error when closing the process. .catch((_): void => {}); // Ignores the error when closing the process.
await delay(100); await delay(100);

View file

@ -37,9 +37,7 @@ export class BaseHandler {
return this.formatter(logRecord); return this.formatter(logRecord);
} }
return this.formatter.replace( return this.formatter.replace(/{(\S+)}/g, (match, p1): string => {
/{(\S+)}/g,
(match, p1): string => {
const value = logRecord[p1 as keyof LogRecord]; const value = logRecord[p1 as keyof LogRecord];
// do not interpolate missing values // do not interpolate missing values
@ -48,8 +46,7 @@ export class BaseHandler {
} }
return String(value); return String(value);
} });
);
} }
log(_msg: string): void {} log(_msg: string): void {}

View file

@ -36,11 +36,9 @@ export class Logger {
level: level, level: level,
levelName: getLevelName(level) levelName: getLevelName(level)
}; };
this.handlers.forEach( this.handlers.forEach((handler): void => {
(handler): void => {
handler.handle(record); handler.handle(record);
} });
);
} }
debug(msg: string, ...args: unknown[]): void { debug(msg: string, ...args: unknown[]): void {

View file

@ -80,11 +80,9 @@ export async function setup(config: LogConfig): Promise<void> {
}; };
// tear down existing handlers // tear down existing handlers
state.handlers.forEach( state.handlers.forEach((handler): void => {
(handler): void => {
handler.destroy(); handler.destroy();
} });
);
state.handlers.clear(); state.handlers.clear();
// setup handlers // setup handlers
@ -106,13 +104,11 @@ export async function setup(config: LogConfig): Promise<void> {
const handlerNames = loggerConfig.handlers || []; const handlerNames = loggerConfig.handlers || [];
const handlers: BaseHandler[] = []; const handlers: BaseHandler[] = [];
handlerNames.forEach( handlerNames.forEach((handlerName): void => {
(handlerName): void => {
if (state.handlers.has(handlerName)) { if (state.handlers.has(handlerName)) {
handlers.push(state.handlers.get(handlerName)!); handlers.push(state.handlers.get(handlerName)!);
} }
} });
);
const levelName = loggerConfig.level || DEFAULT_LEVEL; const levelName = loggerConfig.level || DEFAULT_LEVEL;
const logger = new Logger(levelName, handlers); const logger = new Logger(levelName, handlers);

View file

@ -188,8 +188,7 @@ class PartReader implements Reader, Closer {
comps comps
.slice(1) .slice(1)
.map((v: string): string => v.trim()) .map((v: string): string => v.trim())
.map( .map((kv: string): void => {
(kv: string): void => {
const [k, v] = kv.split("="); const [k, v] = kv.split("=");
if (v) { if (v) {
const s = v.charAt(0); const s = v.charAt(0);
@ -200,8 +199,7 @@ class PartReader implements Reader, Closer {
params[k] = v; params[k] = v;
} }
} }
} });
);
return (this.contentDispositionParams = params); return (this.contentDispositionParams = params);
} }

File diff suppressed because one or more lines are too long

View file

@ -1,4 +1,4 @@
// This file is copied from prettier@1.17.1 // This file is copied from prettier@1.18.2
/** /**
* Copyright © James Long and contributors * Copyright © James Long and contributors
* *

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load diff

View file

@ -89,11 +89,9 @@ Using `assertThrows()`:
```ts ```ts
test(function doesThrow(): void { test(function doesThrow(): void {
assertThrows( assertThrows((): void => {
(): void => {
throw new TypeError("hello world!"); throw new TypeError("hello world!");
} });
);
assertThrows((): void => { assertThrows((): void => {
throw new TypeError("hello world!"); throw new TypeError("hello world!");
}, TypeError); }, TypeError);
@ -108,11 +106,9 @@ test(function doesThrow(): void {
// This test will not pass // This test will not pass
test(function fails(): void { test(function fails(): void {
assertThrows( assertThrows((): void => {
(): void => {
console.log("Hello world"); console.log("Hello world");
} });
);
}); });
``` ```

View file

@ -56,12 +56,10 @@ function buildMessage(diffResult: ReadonlyArray<DiffResult<string>>): string[] {
); );
messages.push(""); messages.push("");
messages.push(""); messages.push("");
diffResult.forEach( diffResult.forEach((result: DiffResult<string>): void => {
(result: DiffResult<string>): void => {
const c = createColor(result.type); const c = createColor(result.type);
messages.push(c(`${createSign(result.type)}${result.value}`)); messages.push(c(`${createSign(result.type)}${result.value}`));
} });
);
messages.push(""); messages.push("");
return messages; return messages;

View file

@ -360,13 +360,11 @@ const getKeysOfEnumerableProperties = (object: {}): Array<string | symbol> => {
const keys: Array<string | symbol> = Object.keys(object).sort(); const keys: Array<string | symbol> = Object.keys(object).sort();
if (Object.getOwnPropertySymbols) { if (Object.getOwnPropertySymbols) {
Object.getOwnPropertySymbols(object).forEach( Object.getOwnPropertySymbols(object).forEach((symbol): void => {
(symbol): void => {
if (Object.getOwnPropertyDescriptor(object, symbol)!.enumerable) { if (Object.getOwnPropertyDescriptor(object, symbol)!.enumerable) {
keys.push(symbol); keys.push(symbol);
} }
} });
);
} }
return keys; return keys;

View file

@ -203,14 +203,12 @@ function report(result: TestResult): void {
} }
function printFailedSummary(results: TestResults): void { function printFailedSummary(results: TestResults): void {
results.cases.forEach( results.cases.forEach((v): void => {
(v): void => {
if (!v.ok) { if (!v.ok) {
console.error(`${RED_BG_FAIL} ${red(v.name)}`); console.error(`${RED_BG_FAIL} ${red(v.name)}`);
console.error(v.error); console.error(v.error);
} }
} });
);
} }
function printResults( function printResults(
@ -322,14 +320,12 @@ async function runTestsSerial(
print( print(
GREEN_OK + " " + name + " " + promptTestTime(end - start, true) GREEN_OK + " " + name + " " + promptTestTime(end - start, true)
); );
results.cases.forEach( results.cases.forEach((v): void => {
(v): void => {
if (v.name === name) { if (v.name === name) {
v.ok = true; v.ok = true;
v.printed = true; v.printed = true;
} }
} });
);
} catch (err) { } catch (err) {
if (disableLog) { if (disableLog) {
print(CLEAR_LINE, false); print(CLEAR_LINE, false);
@ -337,15 +333,13 @@ async function runTestsSerial(
print(`${RED_FAILED} ${name}`); print(`${RED_FAILED} ${name}`);
print(err.stack); print(err.stack);
stats.failed++; stats.failed++;
results.cases.forEach( results.cases.forEach((v): void => {
(v): void => {
if (v.name === name) { if (v.name === name) {
v.error = err; v.error = err;
v.ok = false; v.ok = false;
v.printed = true; v.printed = true;
} }
} });
);
if (exitOnFail) { if (exitOnFail) {
break; break;
} }

View file

@ -85,13 +85,11 @@ export async function getMatchingUrls(
); );
const matchingRemoteUrls = includeRemote.filter( const matchingRemoteUrls = includeRemote.filter(
(candidateUrl: string): boolean => { (candidateUrl: string): boolean => {
return !excludeRemotePatterns.some( return !excludeRemotePatterns.some((pattern: RegExp): boolean => {
(pattern: RegExp): boolean => {
const r = pattern.test(candidateUrl); const r = pattern.test(candidateUrl);
pattern.lastIndex = 0; pattern.lastIndex = 0;
return r; return r;
} });
);
} }
); );
@ -135,11 +133,9 @@ export async function main(root: string = cwd()): Promise<void> {
if (parsedArgs._.length) { if (parsedArgs._.length) {
includeFiles = (parsedArgs._ as string[]) includeFiles = (parsedArgs._ as string[])
.map( .map((fileGlob: string): string[] => {
(fileGlob: string): string[] => {
return fileGlob.split(","); return fileGlob.split(",");
} })
)
.flat(); .flat();
} else { } else {
includeFiles = DEFAULT_GLOBS; includeFiles = DEFAULT_GLOBS;

View file

@ -51,12 +51,10 @@ test(function testingAssertNotStrictEqual(): void {
test(function testingDoesThrow(): void { test(function testingDoesThrow(): void {
let count = 0; let count = 0;
assertThrows( assertThrows((): void => {
(): void => {
count++; count++;
throw new Error(); throw new Error();
} });
);
assert(count === 1); assert(count === 1);
}); });
@ -64,12 +62,10 @@ test(function testingDoesNotThrow(): void {
let count = 0; let count = 0;
let didThrow = false; let didThrow = false;
try { try {
assertThrows( assertThrows((): void => {
(): void => {
count++; count++;
console.log("Hello world"); console.log("Hello world");
} });
);
} catch (e) { } catch (e) {
assert(e.message === "Expected function to throw."); assert(e.message === "Expected function to throw.");
didThrow = true; didThrow = true;

View file

@ -114,11 +114,9 @@ test({
assertEquals(m.get("SID"), "0"); assertEquals(m.get("SID"), "0");
assertEquals(m.get("Privilege"), "127"); assertEquals(m.get("Privilege"), "127");
// Not a legal http header // Not a legal http header
assertThrows( assertThrows((): void => {
(): void => {
assertEquals(m.get("Audio Mode"), "None"); assertEquals(m.get("Audio Mode"), "None");
} });
);
} }
}); });

View file

@ -20,11 +20,9 @@ export interface Deferred<T> extends Promise<T> {
*/ */
export function deferred<T>(): Deferred<T> { export function deferred<T>(): Deferred<T> {
let methods; let methods;
const promise = new Promise<T>( const promise = new Promise<T>((resolve, reject): void => {
(resolve, reject): void => {
methods = { resolve, reject }; methods = { resolve, reject };
} });
);
return Object.assign(promise, methods)! as Deferred<T>; return Object.assign(promise, methods)! as Deferred<T>;
} }
@ -111,8 +109,7 @@ export async function collectUint8Arrays(
// Delays the given milliseconds and resolves. // Delays the given milliseconds and resolves.
export function delay(ms: number): Promise<void> { export function delay(ms: number): Promise<void> {
return new Promise( return new Promise((res): number =>
(res): number =>
setTimeout((): void => { setTimeout((): void => {
res(); res();
}, ms) }, ms)

View file

@ -8,8 +8,7 @@ export function deepAssign(
if (!source || typeof source !== `object`) { if (!source || typeof source !== `object`) {
return; return;
} }
Object.entries(source).forEach( Object.entries(source).forEach(([key, value]: [string, unknown]): void => {
([key, value]: [string, unknown]): void => {
if (value instanceof Date) { if (value instanceof Date) {
target[key] = new Date(value); target[key] = new Date(value);
return; return;
@ -26,8 +25,7 @@ export function deepAssign(
target[key] = {}; target[key] = {};
} }
deepAssign(target[key] as Record<string, unknown>, value!); deepAssign(target[key] as Record<string, unknown>, value!);
} });
);
} }
return target; return target;
} }

View file

@ -15,12 +15,10 @@ export default function generate(): string {
rnds[6] = (rnds[6] & 0x0f) | 0x40; // Version 4 rnds[6] = (rnds[6] & 0x0f) | 0x40; // Version 4
rnds[8] = (rnds[8] & 0x3f) | 0x80; // Variant 10 rnds[8] = (rnds[8] & 0x3f) | 0x80; // Variant 10
const bits: string[] = [...rnds].map( const bits: string[] = [...rnds].map((bit): string => {
(bit): string => {
const s: string = bit.toString(16); const s: string = bit.toString(16);
return bit < 0x10 ? "0" + s : s; return bit < 0x10 ? "0" + s : s;
} });
);
return [ return [
...bits.slice(0, 4), ...bits.slice(0, 4),
"-", "-",

View file

@ -60,11 +60,9 @@ async function main(): Promise<void> {
} }
} }
) )
.catch( .catch((err: Error): void => {
(err: Error): void => {
console.error(`failed to accept websocket: ${err}`); console.error(`failed to accept websocket: ${err}`);
} });
);
} }
} }

View file

@ -53,11 +53,9 @@ async function main(): Promise<void> {
} }
} }
) )
.catch( .catch((err: Error): void => {
(err: Error): void => {
console.error(`failed to accept websocket: ${err}`); console.error(`failed to accept websocket: ${err}`);
} });
);
} }
} }