diff options
67 files changed, 197 insertions, 197 deletions
diff --git a/.eslintrc.json b/.eslintrc.json index 7c9588412..43a0b8cae 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -22,7 +22,8 @@ ], "@typescript-eslint/ban-ts-ignore": ["off"], "@typescript-eslint/no-empty-function": ["off"], - "no-return-await": "error" + "no-return-await": "error", + "require-await": "error" }, "overrides": [ { diff --git a/cli/js/buffer.ts b/cli/js/buffer.ts index 91c06a202..db2bb22e4 100644 --- a/cli/js/buffer.ts +++ b/cli/js/buffer.ts @@ -106,7 +106,7 @@ export class Buffer implements Reader, SyncReader, Writer, SyncWriter { return nread; } - async read(p: Uint8Array): Promise<number | EOF> { + read(p: Uint8Array): Promise<number | EOF> { const rr = this.readSync(p); return Promise.resolve(rr); } @@ -116,7 +116,7 @@ export class Buffer implements Reader, SyncReader, Writer, SyncWriter { return copyBytes(this.buf, p, m); } - async write(p: Uint8Array): Promise<number> { + write(p: Uint8Array): Promise<number> { const n = this.writeSync(p); return Promise.resolve(n); } diff --git a/cli/js/compiler.ts b/cli/js/compiler.ts index 914a0baf0..419f07063 100644 --- a/cli/js/compiler.ts +++ b/cli/js/compiler.ts @@ -302,7 +302,7 @@ async function runtimeCompile( } } -async function runtimeTranspile( +function runtimeTranspile( request: CompilerRequestRuntimeTranspile ): Promise<Record<string, TranspileOnlyResult>> { const result: Record<string, TranspileOnlyResult> = {}; @@ -325,7 +325,7 @@ async function runtimeTranspile( ); result[fileName] = { source, map }; } - return result; + return Promise.resolve(result); } async function tsCompilerOnMessage({ diff --git a/cli/js/ops/fetch.ts b/cli/js/ops/fetch.ts index 8d6a461ab..09b9ac1ec 100644 --- a/cli/js/ops/fetch.ts +++ b/cli/js/ops/fetch.ts @@ -15,7 +15,7 @@ export interface FetchResponse { headers: Array<[string, string]>; } -export async function fetch( +export function fetch( args: FetchRequest, body: ArrayBufferView | undefined ): Promise<FetchResponse> { diff --git a/cli/js/ops/fs/make_temp.ts b/cli/js/ops/fs/make_temp.ts index aeab9afc7..85dea5f20 100644 --- a/cli/js/ops/fs/make_temp.ts +++ b/cli/js/ops/fs/make_temp.ts @@ -11,9 +11,7 @@ export function makeTempDirSync(options: MakeTempOptions = {}): string { return sendSync("op_make_temp_dir", options); } -export async function makeTempDir( - options: MakeTempOptions = {} -): Promise<string> { +export function makeTempDir(options: MakeTempOptions = {}): Promise<string> { return sendAsync("op_make_temp_dir", options); } @@ -21,8 +19,6 @@ export function makeTempFileSync(options: MakeTempOptions = {}): string { return sendSync("op_make_temp_file", options); } -export async function makeTempFile( - options: MakeTempOptions = {} -): Promise<string> { +export function makeTempFile(options: MakeTempOptions = {}): Promise<string> { return sendAsync("op_make_temp_file", options); } diff --git a/cli/js/ops/fs/open.ts b/cli/js/ops/fs/open.ts index 2ac5c715c..87696935f 100644 --- a/cli/js/ops/fs/open.ts +++ b/cli/js/ops/fs/open.ts @@ -26,7 +26,7 @@ export function openSync( return sendSync("op_open", { path, options, openMode, mode }); } -export async function open( +export function open( path: string, openMode: OpenMode | undefined, options: OpenOptions | undefined diff --git a/cli/js/ops/fs/read_link.ts b/cli/js/ops/fs/read_link.ts index 403cd6def..4ac8db3db 100644 --- a/cli/js/ops/fs/read_link.ts +++ b/cli/js/ops/fs/read_link.ts @@ -5,6 +5,6 @@ export function readlinkSync(path: string): string { return sendSync("op_read_link", { path }); } -export async function readlink(path: string): Promise<string> { +export function readlink(path: string): Promise<string> { return sendAsync("op_read_link", { path }); } diff --git a/cli/js/ops/fs/realpath.ts b/cli/js/ops/fs/realpath.ts index e68e32bf0..e8a904079 100644 --- a/cli/js/ops/fs/realpath.ts +++ b/cli/js/ops/fs/realpath.ts @@ -5,6 +5,6 @@ export function realpathSync(path: string): string { return sendSync("op_realpath", { path }); } -export async function realpath(path: string): Promise<string> { +export function realpath(path: string): Promise<string> { return sendAsync("op_realpath", { path }); } diff --git a/cli/js/ops/fs/seek.ts b/cli/js/ops/fs/seek.ts index dfac9bf63..c7e4c9172 100644 --- a/cli/js/ops/fs/seek.ts +++ b/cli/js/ops/fs/seek.ts @@ -10,7 +10,7 @@ export function seekSync( return sendSync("op_seek", { rid, offset, whence }); } -export async function seek( +export function seek( rid: number, offset: number, whence: SeekMode diff --git a/cli/js/ops/fs_events.ts b/cli/js/ops/fs_events.ts index 706efc1b0..4c08995b8 100644 --- a/cli/js/ops/fs_events.ts +++ b/cli/js/ops/fs_events.ts @@ -15,15 +15,15 @@ class FsEvents implements AsyncIterableIterator<FsEvent> { this.rid = sendSync("op_fs_events_open", { recursive, paths }); } - async next(): Promise<IteratorResult<FsEvent>> { + next(): Promise<IteratorResult<FsEvent>> { return sendAsync("op_fs_events_poll", { rid: this.rid }); } - async return(value?: FsEvent): Promise<IteratorResult<FsEvent>> { + return(value?: FsEvent): Promise<IteratorResult<FsEvent>> { close(this.rid); - return { value, done: true }; + return Promise.resolve({ value, done: true }); } [Symbol.asyncIterator](): AsyncIterableIterator<FsEvent> { diff --git a/cli/js/ops/net.ts b/cli/js/ops/net.ts index 5a72be8c6..25f3a8322 100644 --- a/cli/js/ops/net.ts +++ b/cli/js/ops/net.ts @@ -31,7 +31,7 @@ interface AcceptResponse { }; } -export async function accept(rid: number): Promise<AcceptResponse> { +export function accept(rid: number): Promise<AcceptResponse> { return sendAsync("op_accept", { rid }); } @@ -74,7 +74,7 @@ export interface ConnectRequest { port: number; } -export async function connect(args: ConnectRequest): Promise<ConnectResponse> { +export function connect(args: ConnectRequest): Promise<ConnectResponse> { return sendAsync("op_connect", args); } @@ -87,7 +87,7 @@ interface ReceiveResponse { }; } -export async function receive( +export function receive( rid: number, zeroCopy: Uint8Array ): Promise<ReceiveResponse> { diff --git a/cli/js/ops/process.ts b/cli/js/ops/process.ts index 845909d5d..384718cef 100644 --- a/cli/js/ops/process.ts +++ b/cli/js/ops/process.ts @@ -12,7 +12,7 @@ interface RunStatusResponse { exitSignal: number; } -export async function runStatus(rid: number): Promise<RunStatusResponse> { +export function runStatus(rid: number): Promise<RunStatusResponse> { return sendAsync("op_run_status", { rid }); } diff --git a/cli/js/ops/repl.ts b/cli/js/ops/repl.ts index 3f40f4456..1781aa089 100644 --- a/cli/js/ops/repl.ts +++ b/cli/js/ops/repl.ts @@ -6,6 +6,6 @@ export function startRepl(historyFile: string): number { return sendSync("op_repl_start", { historyFile }); } -export async function readline(rid: number, prompt: string): Promise<string> { +export function readline(rid: number, prompt: string): Promise<string> { return sendAsync("op_repl_readline", { rid, prompt }); } diff --git a/cli/js/ops/runtime_compiler.ts b/cli/js/ops/runtime_compiler.ts index 035a4ef59..b46670ace 100644 --- a/cli/js/ops/runtime_compiler.ts +++ b/cli/js/ops/runtime_compiler.ts @@ -9,7 +9,7 @@ interface CompileRequest { bundle: boolean; } -export async function compile(request: CompileRequest): Promise<string> { +export function compile(request: CompileRequest): Promise<string> { return sendAsync("op_compile", request); } @@ -18,6 +18,6 @@ interface TranspileRequest { options?: string; } -export async function transpile(request: TranspileRequest): Promise<string> { +export function transpile(request: TranspileRequest): Promise<string> { return sendAsync("op_transpile", request); } diff --git a/cli/js/ops/signal.ts b/cli/js/ops/signal.ts index 3c8d021a0..09c178105 100644 --- a/cli/js/ops/signal.ts +++ b/cli/js/ops/signal.ts @@ -5,7 +5,7 @@ export function bindSignal(signo: number): { rid: number } { return sendSync("op_signal_bind", { signo }); } -export async function pollSignal(rid: number): Promise<{ done: boolean }> { +export function pollSignal(rid: number): Promise<{ done: boolean }> { return sendAsync("op_signal_poll", { rid }); } diff --git a/cli/js/ops/tls.ts b/cli/js/ops/tls.ts index b52ad65bb..e52143cb0 100644 --- a/cli/js/ops/tls.ts +++ b/cli/js/ops/tls.ts @@ -23,7 +23,7 @@ interface ConnectTLSResponse { }; } -export async function connectTLS( +export function connectTLS( args: ConnectTLSRequest ): Promise<ConnectTLSResponse> { return sendAsync("op_connect_tls", args); @@ -43,7 +43,7 @@ interface AcceptTLSResponse { }; } -export async function acceptTLS(rid: number): Promise<AcceptTLSResponse> { +export function acceptTLS(rid: number): Promise<AcceptTLSResponse> { return sendAsync("op_accept_tls", { rid }); } diff --git a/cli/js/ops/worker_host.ts b/cli/js/ops/worker_host.ts index 1a7e671f4..0b9f81795 100644 --- a/cli/js/ops/worker_host.ts +++ b/cli/js/ops/worker_host.ts @@ -24,6 +24,6 @@ export function hostPostMessage(id: number, data: Uint8Array): void { sendSync("op_host_post_message", { id }, data); } -export async function hostGetMessage(id: number): Promise<any> { +export function hostGetMessage(id: number): Promise<any> { return sendAsync("op_host_get_message", { id }); } diff --git a/cli/js/permissions.ts b/cli/js/permissions.ts index 097c5048a..8c2025319 100644 --- a/cli/js/permissions.ts +++ b/cli/js/permissions.ts @@ -47,19 +47,19 @@ export class PermissionStatus { } export class Permissions { - async query(desc: PermissionDescriptor): Promise<PermissionStatus> { + query(desc: PermissionDescriptor): Promise<PermissionStatus> { const state = permissionsOps.query(desc); - return new PermissionStatus(state); + return Promise.resolve(new PermissionStatus(state)); } - async revoke(desc: PermissionDescriptor): Promise<PermissionStatus> { + revoke(desc: PermissionDescriptor): Promise<PermissionStatus> { const state = permissionsOps.revoke(desc); - return new PermissionStatus(state); + return Promise.resolve(new PermissionStatus(state)); } - async request(desc: PermissionDescriptor): Promise<PermissionStatus> { + request(desc: PermissionDescriptor): Promise<PermissionStatus> { const state = permissionsOps.request(desc); - return new PermissionStatus(state); + return Promise.resolve(new PermissionStatus(state)); } } diff --git a/cli/js/process.ts b/cli/js/process.ts index 991133047..ded1458a2 100644 --- a/cli/js/process.ts +++ b/cli/js/process.ts @@ -55,7 +55,7 @@ export class Process { } } - async status(): Promise<ProcessStatus> { + status(): Promise<ProcessStatus> { return runStatus(this.rid); } diff --git a/cli/js/testing.ts b/cli/js/testing.ts index 08bb2db87..22e719719 100644 --- a/cli/js/testing.ts +++ b/cli/js/testing.ts @@ -289,7 +289,7 @@ export class ConsoleTestReporter implements TestReporter { this.encoder = new TextEncoder(); } - private log(msg: string, noNewLine = false): void { + private log(msg: string, noNewLine = false): Promise<void> { if (!noNewLine) { msg += "\n"; } @@ -298,19 +298,22 @@ export class ConsoleTestReporter implements TestReporter { // compared to `console.log`; `core.print` on the other hand // is line-buffered and doesn't output message without newline stdout.writeSync(this.encoder.encode(msg)); + return Promise.resolve(); } - async start(event: TestEventStart): Promise<void> { + start(event: TestEventStart): Promise<void> { this.log(`running ${event.tests} tests`); + return Promise.resolve(); } - async testStart(event: TestEventTestStart): Promise<void> { + testStart(event: TestEventTestStart): Promise<void> { const { name } = event; this.log(`test ${name} ... `, true); + return Promise.resolve(); } - async testEnd(event: TestEventTestEnd): Promise<void> { + testEnd(event: TestEventTestEnd): Promise<void> { const { result } = event; switch (result.status) { @@ -324,9 +327,11 @@ export class ConsoleTestReporter implements TestReporter { this.log(`${YELLOW_IGNORED} ${formatDuration(result.duration)}`); break; } + + return Promise.resolve(); } - async end(event: TestEventEnd): Promise<void> { + end(event: TestEventEnd): Promise<void> { const { stats, duration, results } = event; // Attempting to match the output of Rust's test runner. const failedTests = results.filter(r => r.error); @@ -354,6 +359,8 @@ export class ConsoleTestReporter implements TestReporter { `${stats.filtered} filtered out ` + `${formatDuration(duration)}\n` ); + + return Promise.resolve(); } } diff --git a/cli/js/tests/dispatch_json_test.ts b/cli/js/tests/dispatch_json_test.ts index a2306dda8..4e95b86a2 100644 --- a/cli/js/tests/dispatch_json_test.ts +++ b/cli/js/tests/dispatch_json_test.ts @@ -19,7 +19,7 @@ unitTest( } ); -unitTest(async function malformedJsonControlBuffer(): Promise<void> { +unitTest(function malformedJsonControlBuffer(): void { // @ts-ignore const opId = Deno.core.ops()["op_open"]; // @ts-ignore diff --git a/cli/js/tests/dispatch_minimal_test.ts b/cli/js/tests/dispatch_minimal_test.ts index 724a41698..60bb620db 100644 --- a/cli/js/tests/dispatch_minimal_test.ts +++ b/cli/js/tests/dispatch_minimal_test.ts @@ -25,7 +25,7 @@ unitTest(async function sendAsyncStackTrace(): Promise<void> { } }); -unitTest(async function malformedMinimalControlBuffer(): Promise<void> { +unitTest(function malformedMinimalControlBuffer(): void { // @ts-ignore const readOpId = Deno.core.ops()["op_read"]; // @ts-ignore diff --git a/cli/js/tests/event_target_test.ts b/cli/js/tests/event_target_test.ts index 09d47f704..020db1acd 100644 --- a/cli/js/tests/event_target_test.ts +++ b/cli/js/tests/event_target_test.ts @@ -185,7 +185,7 @@ unitTest(function eventTargetShouldAcceptAsyncFunction(): void { const event = new Event("foo", { bubbles: true, cancelable: false }); let callCount = 0; - const listener = async (e: Event): Promise<void> => { + const listener = (e: Event): void => { assertEquals(e, event); ++callCount; }; @@ -210,7 +210,7 @@ unitTest( let callCount = 0; const listener = { - async handleEvent(e: Event): Promise<void> { + handleEvent(e: Event): void { assertEquals(e, event); ++callCount; } diff --git a/cli/js/tests/files_test.ts b/cli/js/tests/files_test.ts index b087d7398..39af460b8 100644 --- a/cli/js/tests/files_test.ts +++ b/cli/js/tests/files_test.ts @@ -51,16 +51,16 @@ unitTest(async function readerToAsyncIterator(): Promise<void> { constructor(private readonly s: string) {} - async read(p: Uint8Array): Promise<number | Deno.EOF> { + read(p: Uint8Array): Promise<number | Deno.EOF> { const n = Math.min(p.byteLength, this.buf.byteLength - this.offset); p.set(this.buf.slice(this.offset, this.offset + n)); this.offset += n; if (n === 0) { - return Deno.EOF; + return Promise.resolve(Deno.EOF); } - return n; + return Promise.resolve(n); } } diff --git a/cli/js/tests/process_test.ts b/cli/js/tests/process_test.ts index 77c3065eb..e2da6cab5 100644 --- a/cli/js/tests/process_test.ts +++ b/cli/js/tests/process_test.ts @@ -359,9 +359,7 @@ if (Deno.build.os !== "win") { p.close(); }); - unitTest({ perms: { run: true } }, async function killFailed(): Promise< - void - > { + unitTest({ perms: { run: true } }, function killFailed(): void { const p = run({ args: ["python", "-c", "from time import sleep; sleep(10000)"] }); diff --git a/cli/js/tests/read_link_test.ts b/cli/js/tests/read_link_test.ts index 409f37110..156b31070 100644 --- a/cli/js/tests/read_link_test.ts +++ b/cli/js/tests/read_link_test.ts @@ -18,9 +18,7 @@ unitTest( } ); -unitTest({ perms: { read: false } }, async function readlinkSyncPerm(): Promise< - void -> { +unitTest({ perms: { read: false } }, function readlinkSyncPerm(): void { let caughtError = false; try { Deno.readlinkSync("/symlink"); diff --git a/cli/js/tests/signal_test.ts b/cli/js/tests/signal_test.ts index e4339e290..c966e696b 100644 --- a/cli/js/tests/signal_test.ts +++ b/cli/js/tests/signal_test.ts @@ -15,7 +15,7 @@ function defer(n: number): Promise<void> { unitTest( { ignore: Deno.build.os !== "win" }, - async function signalsNotImplemented(): Promise<void> { + function signalsNotImplemented(): void { assertThrows( () => { Deno.signal(1); @@ -162,7 +162,7 @@ unitTest( unitTest( { ignore: Deno.build.os === "win", perms: { run: true } }, - async function signalShorthandsTest(): Promise<void> { + function signalShorthandsTest(): void { let s: Deno.SignalStream; s = Deno.signals.alarm(); // for SIGALRM assert(s instanceof Deno.SignalStream); diff --git a/cli/js/tests/stat_test.ts b/cli/js/tests/stat_test.ts index e51204b6e..78582900e 100644 --- a/cli/js/tests/stat_test.ts +++ b/cli/js/tests/stat_test.ts @@ -3,9 +3,7 @@ import { unitTest, assert, assertEquals } from "./test_util.ts"; // TODO Add tests for modified, accessed, and created fields once there is a way // to create temp files. -unitTest({ perms: { read: true } }, async function statSyncSuccess(): Promise< - void -> { +unitTest({ perms: { read: true } }, function statSyncSuccess(): void { const packageInfo = Deno.statSync("README.md"); assert(packageInfo.isFile()); assert(!packageInfo.isSymlink()); @@ -19,9 +17,7 @@ unitTest({ perms: { read: true } }, async function statSyncSuccess(): Promise< assert(!testsInfo.isSymlink()); }); -unitTest({ perms: { read: false } }, async function statSyncPerm(): Promise< - void -> { +unitTest({ perms: { read: false } }, function statSyncPerm(): void { let caughtError = false; try { Deno.statSync("README.md"); @@ -32,9 +28,7 @@ unitTest({ perms: { read: false } }, async function statSyncPerm(): Promise< assert(caughtError); }); -unitTest({ perms: { read: true } }, async function statSyncNotFound(): Promise< - void -> { +unitTest({ perms: { read: true } }, function statSyncNotFound(): void { let caughtError = false; let badInfo; @@ -49,9 +43,7 @@ unitTest({ perms: { read: true } }, async function statSyncNotFound(): Promise< assertEquals(badInfo, undefined); }); -unitTest({ perms: { read: true } }, async function lstatSyncSuccess(): Promise< - void -> { +unitTest({ perms: { read: true } }, function lstatSyncSuccess(): void { const packageInfo = Deno.lstatSync("README.md"); assert(packageInfo.isFile()); assert(!packageInfo.isSymlink()); @@ -65,9 +57,7 @@ unitTest({ perms: { read: true } }, async function lstatSyncSuccess(): Promise< assert(!coreInfo.isSymlink()); }); -unitTest({ perms: { read: false } }, async function lstatSyncPerm(): Promise< - void -> { +unitTest({ perms: { read: false } }, function lstatSyncPerm(): void { let caughtError = false; try { Deno.lstatSync("README.md"); @@ -78,9 +68,7 @@ unitTest({ perms: { read: false } }, async function lstatSyncPerm(): Promise< assert(caughtError); }); -unitTest({ perms: { read: true } }, async function lstatSyncNotFound(): Promise< - void -> { +unitTest({ perms: { read: true } }, function lstatSyncNotFound(): void { let caughtError = false; let badInfo; @@ -185,7 +173,7 @@ unitTest({ perms: { read: true } }, async function lstatNotFound(): Promise< unitTest( { ignore: Deno.build.os !== "win", perms: { read: true, write: true } }, - async function statNoUnixFields(): Promise<void> { + function statNoUnixFields(): void { const enc = new TextEncoder(); const data = enc.encode("Hello"); const tempDir = Deno.makeTempDirSync(); @@ -206,7 +194,7 @@ unitTest( unitTest( { ignore: Deno.build.os === "win", perms: { read: true, write: true } }, - async function statUnixFields(): Promise<void> { + function statUnixFields(): void { const enc = new TextEncoder(); const data = enc.encode("Hello"); const tempDir = Deno.makeTempDirSync(); diff --git a/cli/js/tests/test_util.ts b/cli/js/tests/test_util.ts index 42301cf72..980d32bac 100644 --- a/cli/js/tests/test_util.ts +++ b/cli/js/tests/test_util.ts @@ -328,7 +328,7 @@ unitTest(function permissionsMatches(): void { */ unitTest( { perms: { read: true } }, - async function assertAllUnitTestFilesImported(): Promise<void> { + function assertAllUnitTestFilesImported(): void { const directoryTestFiles = Deno.readdirSync("./cli/js/tests/") .map(k => k.name) .filter( diff --git a/cli/js/tests/timers_test.ts b/cli/js/tests/timers_test.ts index 077e27ae6..b7da6a847 100644 --- a/cli/js/tests/timers_test.ts +++ b/cli/js/tests/timers_test.ts @@ -27,7 +27,7 @@ function deferred(): { }; } -async function waitForMs(ms: number): Promise<number> { +function waitForMs(ms: number): Promise<number> { return new Promise((resolve: () => void): number => setTimeout(resolve, ms)); } @@ -158,7 +158,7 @@ unitTest(async function intervalOrdering(): Promise<void> { assertEquals(timeouts, 1); }); -unitTest(async function intervalCancelInvalidSilentFail(): Promise<void> { +unitTest(function intervalCancelInvalidSilentFail(): void { // Should silently fail (no panic) clearInterval(2147483647); }); @@ -234,7 +234,7 @@ unitTest(async function timeoutBindThis(): Promise<void> { } }); -unitTest(async function clearTimeoutShouldConvertToNumber(): Promise<void> { +unitTest(function clearTimeoutShouldConvertToNumber(): void { let called = false; const obj = { valueOf(): number { diff --git a/cli/js/tests/tls_test.ts b/cli/js/tests/tls_test.ts index b405a94dd..20dd62f9b 100644 --- a/cli/js/tests/tls_test.ts +++ b/cli/js/tests/tls_test.ts @@ -39,7 +39,7 @@ unitTest(async function connectTLSCertFileNoReadPerm(): Promise<void> { unitTest( { perms: { read: true, net: true } }, - async function listenTLSNonExistentCertKeyFiles(): Promise<void> { + function listenTLSNonExistentCertKeyFiles(): void { let err; const options = { hostname: "localhost", @@ -70,30 +70,27 @@ unitTest( } ); -unitTest( - { perms: { net: true } }, - async function listenTLSNoReadPerm(): Promise<void> { - let err; - try { - Deno.listenTLS({ - hostname: "localhost", - port: 4500, - certFile: "cli/tests/tls/localhost.crt", - keyFile: "cli/tests/tls/localhost.key" - }); - } catch (e) { - err = e; - } - assert(err instanceof Deno.errors.PermissionDenied); - assertEquals(err.name, "PermissionDenied"); +unitTest({ perms: { net: true } }, function listenTLSNoReadPerm(): void { + let err; + try { + Deno.listenTLS({ + hostname: "localhost", + port: 4500, + certFile: "cli/tests/tls/localhost.crt", + keyFile: "cli/tests/tls/localhost.key" + }); + } catch (e) { + err = e; } -); + assert(err instanceof Deno.errors.PermissionDenied); + assertEquals(err.name, "PermissionDenied"); +}); unitTest( { perms: { read: true, write: true, net: true } }, - async function listenTLSEmptyKeyFile(): Promise<void> { + function listenTLSEmptyKeyFile(): void { let err; const options = { hostname: "localhost", @@ -122,7 +119,7 @@ unitTest( unitTest( { perms: { read: true, write: true, net: true } }, - async function listenTLSEmptyCertFile(): Promise<void> { + function listenTLSEmptyCertFile(): void { let err; const options = { hostname: "localhost", diff --git a/cli/js/web/body.ts b/cli/js/web/body.ts index ed21fa0ec..03c35848a 100644 --- a/cli/js/web/body.ts +++ b/cli/js/web/body.ts @@ -306,7 +306,7 @@ export class Body implements domTypes.Body { return JSON.parse(raw); } - public async arrayBuffer(): Promise<ArrayBuffer> { + public arrayBuffer(): Promise<ArrayBuffer> { if ( this._bodySource instanceof Int8Array || this._bodySource instanceof Int16Array || @@ -318,20 +318,24 @@ export class Body implements domTypes.Body { this._bodySource instanceof Float32Array || this._bodySource instanceof Float64Array ) { - return this._bodySource.buffer as ArrayBuffer; + return Promise.resolve(this._bodySource.buffer as ArrayBuffer); } else if (this._bodySource instanceof ArrayBuffer) { - return this._bodySource; + return Promise.resolve(this._bodySource); } else if (typeof this._bodySource === "string") { const enc = new TextEncoder(); - return enc.encode(this._bodySource).buffer as ArrayBuffer; + return Promise.resolve( + enc.encode(this._bodySource).buffer as ArrayBuffer + ); } else if (this._bodySource instanceof ReadableStream) { // @ts-ignore return bufferFromStream(this._bodySource.getReader()); } else if (this._bodySource instanceof FormData) { const enc = new TextEncoder(); - return enc.encode(this._bodySource.toString()).buffer as ArrayBuffer; + return Promise.resolve( + enc.encode(this._bodySource.toString()).buffer as ArrayBuffer + ); } else if (!this._bodySource) { - return new ArrayBuffer(0); + return Promise.resolve(new ArrayBuffer(0)); } throw new Error( `Body type not yet implemented: ${this._bodySource.constructor.name}` diff --git a/cli/js/web/fetch.ts b/cli/js/web/fetch.ts index 7ab68d2e4..62e5d7928 100644 --- a/cli/js/web/fetch.ts +++ b/cli/js/web/fetch.ts @@ -60,6 +60,7 @@ class Body implements domTypes.Body, domTypes.ReadableStream, io.ReadCloser { return this._data; } + // eslint-disable-next-line require-await async arrayBuffer(): Promise<ArrayBuffer> { // If we've already bufferred the response, just return it. if (this._data != null) { @@ -223,11 +224,12 @@ class Body implements domTypes.Body, domTypes.ReadableStream, io.ReadCloser { return read(this.rid, p); } - close(): void { + close(): Promise<void> { close(this.rid); + return Promise.resolve(); } - async cancel(): Promise<void> { + cancel(): Promise<void> { return notImplemented(); } @@ -346,7 +348,7 @@ export class Response implements domTypes.Response { return false; } - async arrayBuffer(): Promise<ArrayBuffer> { + arrayBuffer(): Promise<ArrayBuffer> { /* You have to do the null check here and not in the function because * otherwise TS complains about this.body potentially being null */ if (this.bodyViewable() || this.body == null) { @@ -355,14 +357,14 @@ export class Response implements domTypes.Response { return this.body.arrayBuffer(); } - async blob(): Promise<domTypes.Blob> { + blob(): Promise<domTypes.Blob> { if (this.bodyViewable() || this.body == null) { return Promise.reject(new Error("Response body is null")); } return this.body.blob(); } - async formData(): Promise<domTypes.FormData> { + formData(): Promise<domTypes.FormData> { if (this.bodyViewable() || this.body == null) { return Promise.reject(new Error("Response body is null")); } @@ -370,14 +372,14 @@ export class Response implements domTypes.Response { } // eslint-disable-next-line @typescript-eslint/no-explicit-any - async json(): Promise<any> { + json(): Promise<any> { if (this.bodyViewable() || this.body == null) { return Promise.reject(new Error("Response body is null")); } return this.body.json(); } - async text(): Promise<string> { + text(): Promise<string> { if (this.bodyViewable() || this.body == null) { return Promise.reject(new Error("Response body is null")); } @@ -437,7 +439,7 @@ export class Response implements domTypes.Response { } } -async function sendFetchReq( +function sendFetchReq( url: string, method: string | null, headers: domTypes.Headers | null, diff --git a/cli/tests/018_async_catch.ts b/cli/tests/018_async_catch.ts index 0d034d798..a16f11696 100644 --- a/cli/tests/018_async_catch.ts +++ b/cli/tests/018_async_catch.ts @@ -1,4 +1,4 @@ -async function fn(): Promise<never> { +function fn(): Promise<never> { throw new Error("message"); } async function call(): Promise<void> { diff --git a/cli/tests/async_error.ts b/cli/tests/async_error.ts index 81c983a50..b37369bac 100644 --- a/cli/tests/async_error.ts +++ b/cli/tests/async_error.ts @@ -1,4 +1,5 @@ console.log("hello"); +// eslint-disable-next-line require-await const foo = async (): Promise<never> => { console.log("before error"); throw Error("error"); diff --git a/cli/tests/async_error.ts.out b/cli/tests/async_error.ts.out index d07ba8cfe..6e22799c2 100644 --- a/cli/tests/async_error.ts.out +++ b/cli/tests/async_error.ts.out @@ -2,10 +2,10 @@ before error world error: Uncaught Error: error -[WILDCARD]tests/async_error.ts:4:9 +[WILDCARD]tests/async_error.ts:5:9 -4 throw Error("error"); +5 throw Error("error"); ^ - at foo ([WILDCARD]tests/async_error.ts:4:9) - at [WILDCARD]tests/async_error.ts:7:1 + at foo ([WILDCARD]tests/async_error.ts:5:9) + at [WILDCARD]tests/async_error.ts:8:1 diff --git a/cli/tests/permission_test.ts b/cli/tests/permission_test.ts index 763e429b6..11b95cf3a 100644 --- a/cli/tests/permission_test.ts +++ b/cli/tests/permission_test.ts @@ -3,8 +3,9 @@ const { args, listen, env, exit, makeTempDirSync, readFileSync, run } = Deno; const name = args[0]; const test: { [key: string]: Function } = { - async readRequired(): Promise<void> { + readRequired(): Promise<void> { readFileSync("README.md"); + return Promise.resolve(); }, writeRequired(): void { makeTempDirSync(); diff --git a/cli/tests/top_level_for_await.js b/cli/tests/top_level_for_await.js index fa3b496a8..54742ce52 100644 --- a/cli/tests/top_level_for_await.js +++ b/cli/tests/top_level_for_await.js @@ -1,4 +1,4 @@ -async function* asyncGenerator() { +function* asyncGenerator() { let i = 0; while (i < 3) { yield i++; diff --git a/cli/tests/top_level_for_await.ts b/cli/tests/top_level_for_await.ts index 9179322d7..92d8af30a 100644 --- a/cli/tests/top_level_for_await.ts +++ b/cli/tests/top_level_for_await.ts @@ -1,3 +1,4 @@ +// eslint-disable-next-line require-await async function* asyncGenerator(): AsyncIterableIterator<number> { let i = 0; while (i < 3) { diff --git a/core/examples/http_bench.js b/core/examples/http_bench.js index 4314ba680..72f53550d 100644 --- a/core/examples/http_bench.js +++ b/core/examples/http_bench.js @@ -84,7 +84,7 @@ function listen() { } /** Accepts a connection, returns rid. */ -async function accept(rid) { +function accept(rid) { return sendAsync(ops["accept"], rid); } @@ -92,12 +92,12 @@ async function accept(rid) { * Reads a packet from the rid, presumably an http request. data is ignored. * Returns bytes read. */ -async function read(rid, data) { +function read(rid, data) { return sendAsync(ops["read"], rid, data); } /** Writes a fixed HTTP response to the socket rid. Returns bytes written. */ -async function write(rid, data) { +function write(rid, data) { return sendAsync(ops["write"], rid, data); } diff --git a/std/encoding/binary_test.ts b/std/encoding/binary_test.ts index 936fcbb63..54f8cbded 100644 --- a/std/encoding/binary_test.ts +++ b/std/encoding/binary_test.ts @@ -24,12 +24,12 @@ Deno.test(async function testGetNBytes(): Promise<void> { Deno.test(async function testGetNBytesThrows(): Promise<void> { const data = new Uint8Array([1, 2, 3, 4]); const buff = new Deno.Buffer(data.buffer); - assertThrowsAsync(async () => { + await assertThrowsAsync(async () => { await getNBytes(buff, 8); }, Deno.errors.UnexpectedEof); }); -Deno.test(async function testPutVarbig(): Promise<void> { +Deno.test(function testPutVarbig(): void { const buff = new Uint8Array(8); putVarbig(buff, 0xffeeddccbbaa9988n); assertEquals( @@ -38,7 +38,7 @@ Deno.test(async function testPutVarbig(): Promise<void> { ); }); -Deno.test(async function testPutVarbigLittleEndian(): Promise<void> { +Deno.test(function testPutVarbigLittleEndian(): void { const buff = new Uint8Array(8); putVarbig(buff, 0x8899aabbccddeeffn, { endian: "little" }); assertEquals( @@ -47,13 +47,13 @@ Deno.test(async function testPutVarbigLittleEndian(): Promise<void> { ); }); -Deno.test(async function testPutVarnum(): Promise<void> { +Deno.test(function testPutVarnum(): void { const buff = new Uint8Array(4); putVarnum(buff, 0xffeeddcc); assertEquals(buff, new Uint8Array([0xff, 0xee, 0xdd, 0xcc])); }); -Deno.test(async function testPutVarnumLittleEndian(): Promise<void> { +Deno.test(function testPutVarnumLittleEndian(): void { const buff = new Uint8Array(4); putVarnum(buff, 0xccddeeff, { endian: "little" }); assertEquals(buff, new Uint8Array([0xff, 0xee, 0xdd, 0xcc])); diff --git a/std/encoding/yaml/example/sample_document.ts b/std/encoding/yaml/example/sample_document.ts index c9372e8ec..da969d679 100644 --- a/std/encoding/yaml/example/sample_document.ts +++ b/std/encoding/yaml/example/sample_document.ts @@ -5,7 +5,7 @@ import { parse } from "../../yaml.ts"; const { readFileSync, cwd } = Deno; -(async () => { +(() => { const yml = readFileSync(`${cwd()}/example/sample_document.yml`); const document = new TextDecoder().decode(yml); diff --git a/std/examples/chat/server.ts b/std/examples/chat/server.ts index 3c968e44e..08aede05b 100644 --- a/std/examples/chat/server.ts +++ b/std/examples/chat/server.ts @@ -8,7 +8,7 @@ import { const clients = new Map<number, WebSocket>(); let clientId = 0; -async function dispatch(msg: string): Promise<void> { +function dispatch(msg: string): void { for (const client of clients.values()) { client.send(msg); } diff --git a/std/examples/chat/server_test.ts b/std/examples/chat/server_test.ts index 899eb1b32..0d21b3787 100644 --- a/std/examples/chat/server_test.ts +++ b/std/examples/chat/server_test.ts @@ -18,7 +18,7 @@ async function startServer(): Promise<Deno.Process> { const r = new TextProtoReader(new BufReader(server.stdout)); const s = await r.readLine(); assert(s !== Deno.EOF && s.includes("chat server starting")); - } catch { + } catch (err) { server.stdout!.close(); server.close(); } diff --git a/std/fs/copy_test.ts b/std/fs/copy_test.ts index fb8827f0c..9ba5f2b21 100644 --- a/std/fs/copy_test.ts +++ b/std/fs/copy_test.ts @@ -17,10 +17,7 @@ const testdataDir = path.resolve("fs", "testdata"); // TODO(axetroy): Add test for Windows once symlink is implemented for Windows. const isWindows = Deno.build.os === "win"; -async function testCopy( - name: string, - cb: (tempDir: string) => Promise<void> -): Promise<void> { +function testCopy(name: string, cb: (tempDir: string) => Promise<void>): void { Deno.test({ name, async fn(): Promise<void> { diff --git a/std/fs/exists.ts b/std/fs/exists.ts index ae64cb1f3..f9e5a0925 100644 --- a/std/fs/exists.ts +++ b/std/fs/exists.ts @@ -4,15 +4,16 @@ const { lstat, lstatSync } = Deno; * Test whether or not the given path exists by checking with the file system */ export async function exists(filePath: string): Promise<boolean> { - return lstat(filePath) - .then((): boolean => true) - .catch((err: Error): boolean => { - if (err instanceof Deno.errors.NotFound) { - return false; - } + try { + await lstat(filePath); + return true; + } catch (err) { + if (err instanceof Deno.errors.NotFound) { + return false; + } - throw err; - }); + throw err; + } } /** diff --git a/std/fs/walk_test.ts b/std/fs/walk_test.ts index c2518cee3..96bfcae67 100644 --- a/std/fs/walk_test.ts +++ b/std/fs/walk_test.ts @@ -5,11 +5,11 @@ import { assert, assertEquals, assertThrowsAsync } from "../testing/asserts.ts"; const isWindows = Deno.build.os == "win"; -export async function testWalk( +export function testWalk( setup: (arg0: string) => void | Promise<void>, t: Deno.TestFunction, ignore = false -): Promise<void> { +): void { const name = t.name; async function fn(): Promise<void> { const origCwd = cwd(); diff --git a/std/http/file_server.ts b/std/http/file_server.ts index 18a68aa49..20d5d61e6 100755 --- a/std/http/file_server.ts +++ b/std/http/file_server.ts @@ -158,17 +158,17 @@ async function serveDir( return res; } -async function serveFallback(req: ServerRequest, e: Error): Promise<Response> { +function serveFallback(req: ServerRequest, e: Error): Promise<Response> { if (e instanceof Deno.errors.NotFound) { - return { + return Promise.resolve({ status: 404, body: encoder.encode("Not found") - }; + }); } else { - return { + return Promise.resolve({ status: 500, body: encoder.encode("Internal server error") - }; + }); } } diff --git a/std/http/io.ts b/std/http/io.ts index 5518146a8..6d5d1f665 100644 --- a/std/http/io.ts +++ b/std/http/io.ts @@ -7,8 +7,8 @@ import { STATUS_TEXT } from "./http_status.ts"; export function emptyReader(): Deno.Reader { return { - async read(_: Uint8Array): Promise<number | Deno.EOF> { - return Deno.EOF; + read(_: Uint8Array): Promise<number | Deno.EOF> { + return Promise.resolve(Deno.EOF); } }; } diff --git a/std/http/mock.ts b/std/http/mock.ts index 3a4eeed82..cee697bed 100644 --- a/std/http/mock.ts +++ b/std/http/mock.ts @@ -14,11 +14,11 @@ export function mockConn(base: Partial<Deno.Conn> = {}): Deno.Conn { rid: -1, closeRead: (): void => {}, closeWrite: (): void => {}, - read: async (): Promise<number | Deno.EOF> => { - return 0; + read: (): Promise<number | Deno.EOF> => { + return Promise.resolve(0); }, - write: async (): Promise<number> => { - return -1; + write: (): Promise<number> => { + return Promise.resolve(-1); }, close: (): void => {}, ...base diff --git a/std/http/server_test.ts b/std/http/server_test.ts index 0a4986dcf..2a7c46134 100644 --- a/std/http/server_test.ts +++ b/std/http/server_test.ts @@ -68,7 +68,7 @@ test(async function responseWrite(): Promise<void> { } }); -test(async function requestContentLength(): Promise<void> { +test(function requestContentLength(): void { // Has content length { const req = new ServerRequest(); diff --git a/std/io/bufio.ts b/std/io/bufio.ts index 12b5c2d2b..a944adfed 100644 --- a/std/io/bufio.ts +++ b/std/io/bufio.ts @@ -602,6 +602,7 @@ export async function* readStringDelim( } /** Read strings line-by-line from a Reader. */ +// eslint-disable-next-line require-await export async function* readLines( reader: Reader ): AsyncIterableIterator<string> { diff --git a/std/io/bufio_test.ts b/std/io/bufio_test.ts index d925175f1..ae38f6667 100644 --- a/std/io/bufio_test.ts +++ b/std/io/bufio_test.ts @@ -191,7 +191,7 @@ const testOutput = encoder.encode("0123456789abcdefghijklmnopqrstuvwxy"); class TestReader implements Reader { constructor(private data: Uint8Array, private stride: number) {} - async read(buf: Uint8Array): Promise<number | Deno.EOF> { + read(buf: Uint8Array): Promise<number | Deno.EOF> { let nread = this.stride; if (nread > this.data.byteLength) { nread = this.data.byteLength; @@ -200,11 +200,11 @@ class TestReader implements Reader { nread = buf.byteLength; } if (nread === 0) { - return Deno.EOF; + return Promise.resolve(Deno.EOF); } copyBytes(buf as Uint8Array, this.data); this.data = this.data.subarray(nread); - return nread; + return Promise.resolve(nread); } } diff --git a/std/io/iotest.ts b/std/io/iotest.ts index 1e922e33f..e2cf315aa 100644 --- a/std/io/iotest.ts +++ b/std/io/iotest.ts @@ -10,14 +10,14 @@ type Reader = Deno.Reader; export class OneByteReader implements Reader { constructor(readonly r: Reader) {} - async read(p: Uint8Array): Promise<number | Deno.EOF> { + read(p: Uint8Array): Promise<number | Deno.EOF> { if (p.byteLength === 0) { - return 0; + return Promise.resolve(0); } if (!(p instanceof Uint8Array)) { throw Error("expected Uint8Array"); } - return this.r.read(p.subarray(0, 1)); + return Promise.resolve(this.r.read(p.subarray(0, 1))); } } @@ -27,12 +27,12 @@ export class OneByteReader implements Reader { export class HalfReader implements Reader { constructor(readonly r: Reader) {} - async read(p: Uint8Array): Promise<number | Deno.EOF> { + read(p: Uint8Array): Promise<number | Deno.EOF> { if (!(p instanceof Uint8Array)) { throw Error("expected Uint8Array"); } const half = Math.floor((p.byteLength + 1) / 2); - return this.r.read(p.subarray(0, half)); + return Promise.resolve(this.r.read(p.subarray(0, half))); } } @@ -43,11 +43,11 @@ export class TimeoutReader implements Reader { count = 0; constructor(readonly r: Reader) {} - async read(p: Uint8Array): Promise<number | Deno.EOF> { + read(p: Uint8Array): Promise<number | Deno.EOF> { this.count++; if (this.count === 2) { throw new Deno.errors.TimedOut(); } - return this.r.read(p); + return Promise.resolve(this.r.read(p)); } } diff --git a/std/io/ioutil_test.ts b/std/io/ioutil_test.ts index 261f4def0..3d85a0fa1 100644 --- a/std/io/ioutil_test.ts +++ b/std/io/ioutil_test.ts @@ -17,10 +17,10 @@ class BinaryReader implements Reader { constructor(private bytes: Uint8Array = new Uint8Array(0)) {} - async read(p: Uint8Array): Promise<number | Deno.EOF> { + read(p: Uint8Array): Promise<number | Deno.EOF> { p.set(this.bytes.subarray(this.index, p.byteLength)); this.index += p.byteLength; - return p.byteLength; + return Promise.resolve(p.byteLength); } } @@ -52,7 +52,7 @@ Deno.test(async function testReadLong2(): Promise<void> { assertEquals(long, 0x12345678); }); -Deno.test(async function testSliceLongToBytes(): Promise<void> { +Deno.test(function testSliceLongToBytes(): void { const arr = sliceLongToBytes(0x1234567890abcdef); const actual = readLong(new BufReader(new BinaryReader(new Uint8Array(arr)))); const expected = readLong( @@ -65,7 +65,7 @@ Deno.test(async function testSliceLongToBytes(): Promise<void> { assertEquals(actual, expected); }); -Deno.test(async function testSliceLongToBytes2(): Promise<void> { +Deno.test(function testSliceLongToBytes2(): void { const arr = sliceLongToBytes(0x12345678); assertEquals(arr, [0, 0, 0, 0, 0x12, 0x34, 0x56, 0x78]); }); diff --git a/std/io/readers.ts b/std/io/readers.ts index 5b1bf1948..2d81e246f 100644 --- a/std/io/readers.ts +++ b/std/io/readers.ts @@ -9,14 +9,14 @@ export class StringReader implements Reader { constructor(private readonly s: string) {} - async read(p: Uint8Array): Promise<number | Deno.EOF> { + read(p: Uint8Array): Promise<number | Deno.EOF> { const n = Math.min(p.byteLength, this.buf.byteLength - this.offs); p.set(this.buf.slice(this.offs, this.offs + n)); this.offs += n; if (n === 0) { - return Deno.EOF; + return Promise.resolve(Deno.EOF); } - return n; + return Promise.resolve(n); } } diff --git a/std/io/writers.ts b/std/io/writers.ts index 722e0297f..b9a6a5e70 100644 --- a/std/io/writers.ts +++ b/std/io/writers.ts @@ -14,11 +14,11 @@ export class StringWriter implements Writer { this.byteLength += c.byteLength; } - async write(p: Uint8Array): Promise<number> { + write(p: Uint8Array): Promise<number> { this.chunks.push(p); this.byteLength += p.byteLength; this.cache = undefined; - return p.byteLength; + return Promise.resolve(p.byteLength); } toString(): string { diff --git a/std/node/_fs/_fs_close.ts b/std/node/_fs/_fs_close.ts index e19eb932e..4ec10eefb 100644 --- a/std/node/_fs/_fs_close.ts +++ b/std/node/_fs/_fs_close.ts @@ -3,7 +3,7 @@ import { CallbackWithError } from "./_fs_common.ts"; export function close(fd: number, callback: CallbackWithError): void { - new Promise(async (resolve, reject) => { + new Promise((resolve, reject) => { try { Deno.close(fd); resolve(); diff --git a/std/node/_fs/_fs_close_test.ts b/std/node/_fs/_fs_close_test.ts index 2c7117248..7c6dd684c 100644 --- a/std/node/_fs/_fs_close_test.ts +++ b/std/node/_fs/_fs_close_test.ts @@ -16,7 +16,7 @@ test({ else resolve(); }); }) - .then(async () => { + .then(() => { assert(!Deno.resources()[file.rid]); }) .catch(() => { diff --git a/std/node/_fs/_fs_dir_test.ts b/std/node/_fs/_fs_dir_test.ts index 3b8c5b341..be276887b 100644 --- a/std/node/_fs/_fs_dir_test.ts +++ b/std/node/_fs/_fs_dir_test.ts @@ -5,7 +5,7 @@ import Dirent from "./_fs_dirent.ts"; test({ name: "Closing current directory with callback is successful", - async fn() { + fn() { let calledBack = false; // eslint-disable-next-line @typescript-eslint/no-explicit-any new Dir(".").close((valOrErr: any) => { @@ -25,7 +25,7 @@ test({ test({ name: "Closing current directory synchronously works", - async fn() { + fn() { new Dir(".").closeSync(); } }); diff --git a/std/testing/bench.ts b/std/testing/bench.ts index 5cec3ea39..1c4b01c0b 100644 --- a/std/testing/bench.ts +++ b/std/testing/bench.ts @@ -169,11 +169,12 @@ export async function runBenchmarks({ } /** Runs specified benchmarks if the enclosing script is main. */ -export async function runIfMain( +export function runIfMain( meta: ImportMeta, opts: BenchmarkRunOptions = {} ): Promise<void> { if (meta.main) { return runBenchmarks(opts); } + return Promise.resolve(undefined); } diff --git a/std/textproto/reader_test.ts b/std/textproto/reader_test.ts index 7aead064b..f0ae63894 100644 --- a/std/textproto/reader_test.ts +++ b/std/textproto/reader_test.ts @@ -21,9 +21,10 @@ function reader(s: string): TextProtoReader { test({ ignore: true, name: "[textproto] Reader : DotBytes", - async fn(): Promise<void> { + fn(): Promise<void> { const _input = "dotlines\r\n.foo\r\n..bar\n...baz\nquux\r\n\r\n.\r\nanot.her\r\n"; + return Promise.resolve(); } }); diff --git a/std/textproto/test.ts b/std/textproto/test.ts index 5b67bbf95..9a992a2cf 100644 --- a/std/textproto/test.ts +++ b/std/textproto/test.ts @@ -7,7 +7,7 @@ import { append } from "./mod.ts"; import { assertEquals } from "../testing/asserts.ts"; const { test } = Deno; -test(async function textprotoAppend(): Promise<void> { +test(function textprotoAppend(): void { const enc = new TextEncoder(); const dec = new TextDecoder(); const u1 = enc.encode("Hello "); diff --git a/std/util/async_test.ts b/std/util/async_test.ts index 4607cf6cd..d81b52b43 100644 --- a/std/util/async_test.ts +++ b/std/util/async_test.ts @@ -3,17 +3,20 @@ const { test } = Deno; import { assert, assertEquals, assertStrictEq } from "../testing/asserts.ts"; import { collectUint8Arrays, deferred, MuxAsyncIterator } from "./async.ts"; -test(async function asyncDeferred(): Promise<void> { +test(function asyncDeferred(): Promise<void> { const d = deferred<number>(); d.resolve(12); + return Promise.resolve(); }); +// eslint-disable-next-line require-await async function* gen123(): AsyncIterableIterator<number> { yield 1; yield 2; yield 3; } +// eslint-disable-next-line require-await async function* gen456(): AsyncIterableIterator<number> { yield 4; yield 5; @@ -47,6 +50,7 @@ test(async function collectUint8Arrays0(): Promise<void> { test(async function collectUint8Arrays1(): Promise<void> { const buf = new Uint8Array([1, 2, 3]); + // eslint-disable-next-line require-await async function* gen(): AsyncIterableIterator<Uint8Array> { yield buf; } @@ -56,6 +60,7 @@ test(async function collectUint8Arrays1(): Promise<void> { }); test(async function collectUint8Arrays4(): Promise<void> { + // eslint-disable-next-line require-await async function* gen(): AsyncIterableIterator<Uint8Array> { yield new Uint8Array([1, 2, 3]); yield new Uint8Array([]); diff --git a/std/ws/mod.ts b/std/ws/mod.ts index 809654a06..3332ed8dd 100644 --- a/std/ws/mod.ts +++ b/std/ws/mod.ts @@ -322,7 +322,7 @@ class WebSocketImpl implements WebSocket { return d; } - async send(data: WebSocketMessage): Promise<void> { + send(data: WebSocketMessage): Promise<void> { const opcode = typeof data === "string" ? OpCode.TextFrame : OpCode.BinaryFrame; const payload = typeof data === "string" ? encode(data) : data; @@ -336,7 +336,7 @@ class WebSocketImpl implements WebSocket { return this.enqueue(frame); } - async ping(data: WebSocketMessage = ""): Promise<void> { + ping(data: WebSocketMessage = ""): Promise<void> { const payload = typeof data === "string" ? encode(data) : data; const frame = { isLastFrame: true, diff --git a/std/ws/test.ts b/std/ws/test.ts index 820fe1423..f1efa8e40 100644 --- a/std/ws/test.ts +++ b/std/ws/test.ts @@ -126,7 +126,7 @@ test("[ws] read unmasked bigger binary frame", async () => { assertEquals(bin.payload.length, payloadLength); }); -test("[ws] createSecAccept", async () => { +test("[ws] createSecAccept", () => { const nonce = "dGhlIHNhbXBsZSBub25jZQ=="; const d = createSecAccept(nonce); assertEquals(d, "s3pPLMBiTxaQ9kYGzzhZRbK+xOo="); @@ -335,8 +335,8 @@ test("[ws] createSecKeyHasCorrectLength", () => { test("[ws] WebSocket should throw `Deno.errors.ConnectionReset` when peer closed connection without close frame", async () => { const buf = new Buffer(); const eofReader: Deno.Reader = { - async read(_: Uint8Array): Promise<number | Deno.EOF> { - return Deno.EOF; + read(_: Uint8Array): Promise<number | Deno.EOF> { + return Promise.resolve(Deno.EOF); } }; const conn = dummyConn(eofReader, buf); @@ -353,8 +353,8 @@ test("[ws] WebSocket should throw `Deno.errors.ConnectionReset` when peer closed test("[ws] WebSocket shouldn't throw `Deno.errors.UnexpectedEof` on recive()", async () => { const buf = new Buffer(); const eofReader: Deno.Reader = { - async read(_: Uint8Array): Promise<number | Deno.EOF> { - return Deno.EOF; + read(_: Uint8Array): Promise<number | Deno.EOF> { + return Promise.resolve(Deno.EOF); } }; const conn = dummyConn(eofReader, buf); @@ -372,7 +372,7 @@ test({ const buf = new Buffer(); let timer: number | undefined; const lazyWriter: Deno.Writer = { - async write(_: Uint8Array): Promise<number> { + write(_: Uint8Array): Promise<number> { return new Promise(resolve => { timer = setTimeout(() => resolve(0), 1000); }); diff --git a/tools/node_tcp_promise.js b/tools/node_tcp_promise.js index 547d97845..d522f1751 100644 --- a/tools/node_tcp_promise.js +++ b/tools/node_tcp_promise.js @@ -8,11 +8,11 @@ const response = Buffer.from( "HTTP/1.1 200 OK\r\nContent-Length: 12\r\n\r\nHello World\n" ); -async function write(socket, buffer) { +function write(socket, buffer) { const p = new Promise((resolve, _) => { socket.write(buffer, resolve); }); - return p; + return Promise.resolve(p); } Server(async socket => { @@ -20,6 +20,6 @@ Server(async socket => { socket.destroy(); }); for await (const _ of socket) { - write(socket, response); + await write(socket, response); } }).listen(port); |