From 1edb20b399944c6eec1d7c555ab170b6dd276840 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Mon, 16 Mar 2020 10:22:16 +0100 Subject: [PATCH] refactor: add no-return-await lint rule (#4384) --- .eslintrc.json | 3 ++- cli/js/ops/fetch.ts | 2 +- cli/js/ops/fs/make_temp.ts | 4 ++-- cli/js/ops/fs/open.ts | 2 +- cli/js/ops/fs/read_link.ts | 2 +- cli/js/ops/fs/realpath.ts | 2 +- cli/js/ops/fs/seek.ts | 2 +- cli/js/ops/fs_events.ts | 2 +- cli/js/ops/net.ts | 6 +++--- cli/js/ops/process.ts | 2 +- cli/js/ops/signal.ts | 2 +- cli/js/ops/tls.ts | 4 ++-- cli/js/ops/worker_host.ts | 2 +- cli/js/process.ts | 2 +- cli/js/tests/unit_test_runner.ts | 4 ++-- cli/js/web/fetch.ts | 2 +- core/examples/http_bench.js | 6 +++--- std/http/file_server.ts | 2 +- 18 files changed, 26 insertions(+), 25 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index a58eb0df9d..7c95884129 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -21,7 +21,8 @@ { "argsIgnorePattern": "^_", "varsIgnorePattern": "^_" } ], "@typescript-eslint/ban-ts-ignore": ["off"], - "@typescript-eslint/no-empty-function": ["off"] + "@typescript-eslint/no-empty-function": ["off"], + "no-return-await": "error" }, "overrides": [ { diff --git a/cli/js/ops/fetch.ts b/cli/js/ops/fetch.ts index c5c0cb883c..8d6a461ab3 100644 --- a/cli/js/ops/fetch.ts +++ b/cli/js/ops/fetch.ts @@ -24,5 +24,5 @@ export async function fetch( zeroCopy = new Uint8Array(body.buffer, body.byteOffset, body.byteLength); } - return await sendAsync("op_fetch", args, zeroCopy); + return sendAsync("op_fetch", args, zeroCopy); } diff --git a/cli/js/ops/fs/make_temp.ts b/cli/js/ops/fs/make_temp.ts index cc8a76435e..aeab9afc7a 100644 --- a/cli/js/ops/fs/make_temp.ts +++ b/cli/js/ops/fs/make_temp.ts @@ -14,7 +14,7 @@ export function makeTempDirSync(options: MakeTempOptions = {}): string { export async function makeTempDir( options: MakeTempOptions = {} ): Promise { - return await sendAsync("op_make_temp_dir", options); + return sendAsync("op_make_temp_dir", options); } export function makeTempFileSync(options: MakeTempOptions = {}): string { @@ -24,5 +24,5 @@ export function makeTempFileSync(options: MakeTempOptions = {}): string { export async function makeTempFile( options: MakeTempOptions = {} ): Promise { - return await sendAsync("op_make_temp_file", options); + return sendAsync("op_make_temp_file", options); } diff --git a/cli/js/ops/fs/open.ts b/cli/js/ops/fs/open.ts index 0d3c236675..4c9281909e 100644 --- a/cli/js/ops/fs/open.ts +++ b/cli/js/ops/fs/open.ts @@ -25,7 +25,7 @@ export async function open( mode: OpenMode | undefined, options: OpenOptions | undefined ): Promise { - return await sendAsync("op_open", { + return sendAsync("op_open", { path, options, mode diff --git a/cli/js/ops/fs/read_link.ts b/cli/js/ops/fs/read_link.ts index 3c74e1f2e9..403cd6def2 100644 --- a/cli/js/ops/fs/read_link.ts +++ b/cli/js/ops/fs/read_link.ts @@ -6,5 +6,5 @@ export function readlinkSync(path: string): string { } export async function readlink(path: string): Promise { - return await sendAsync("op_read_link", { path }); + return sendAsync("op_read_link", { path }); } diff --git a/cli/js/ops/fs/realpath.ts b/cli/js/ops/fs/realpath.ts index 625e6702dd..e68e32bf02 100644 --- a/cli/js/ops/fs/realpath.ts +++ b/cli/js/ops/fs/realpath.ts @@ -6,5 +6,5 @@ export function realpathSync(path: string): string { } export async function realpath(path: string): Promise { - return await sendAsync("op_realpath", { path }); + return sendAsync("op_realpath", { path }); } diff --git a/cli/js/ops/fs/seek.ts b/cli/js/ops/fs/seek.ts index a3b055c95b..dfac9bf636 100644 --- a/cli/js/ops/fs/seek.ts +++ b/cli/js/ops/fs/seek.ts @@ -15,5 +15,5 @@ export async function seek( offset: number, whence: SeekMode ): Promise { - return await sendAsync("op_seek", { rid, offset, whence }); + return sendAsync("op_seek", { rid, offset, whence }); } diff --git a/cli/js/ops/fs_events.ts b/cli/js/ops/fs_events.ts index 09e82c5155..706efc1b0d 100644 --- a/cli/js/ops/fs_events.ts +++ b/cli/js/ops/fs_events.ts @@ -16,7 +16,7 @@ class FsEvents implements AsyncIterableIterator { } async next(): Promise> { - return await sendAsync("op_fs_events_poll", { + return sendAsync("op_fs_events_poll", { rid: this.rid }); } diff --git a/cli/js/ops/net.ts b/cli/js/ops/net.ts index a108e1c721..5a72be8c6e 100644 --- a/cli/js/ops/net.ts +++ b/cli/js/ops/net.ts @@ -32,7 +32,7 @@ interface AcceptResponse { } export async function accept(rid: number): Promise { - return await sendAsync("op_accept", { rid }); + return sendAsync("op_accept", { rid }); } export interface ListenRequest { @@ -75,7 +75,7 @@ export interface ConnectRequest { } export async function connect(args: ConnectRequest): Promise { - return await sendAsync("op_connect", args); + return sendAsync("op_connect", args); } interface ReceiveResponse { @@ -91,7 +91,7 @@ export async function receive( rid: number, zeroCopy: Uint8Array ): Promise { - return await sendAsync("op_receive", { rid }, zeroCopy); + return sendAsync("op_receive", { rid }, zeroCopy); } export interface SendRequest { diff --git a/cli/js/ops/process.ts b/cli/js/ops/process.ts index 7644bf6e75..845909d5dd 100644 --- a/cli/js/ops/process.ts +++ b/cli/js/ops/process.ts @@ -13,7 +13,7 @@ interface RunStatusResponse { } export async function runStatus(rid: number): Promise { - return await sendAsync("op_run_status", { rid }); + return sendAsync("op_run_status", { rid }); } interface RunRequest { diff --git a/cli/js/ops/signal.ts b/cli/js/ops/signal.ts index 7f9304a82e..3c8d021a03 100644 --- a/cli/js/ops/signal.ts +++ b/cli/js/ops/signal.ts @@ -6,7 +6,7 @@ export function bindSignal(signo: number): { rid: number } { } export async function pollSignal(rid: number): Promise<{ done: boolean }> { - return await sendAsync("op_signal_poll", { rid }); + return sendAsync("op_signal_poll", { rid }); } export function unbindSignal(rid: number): void { diff --git a/cli/js/ops/tls.ts b/cli/js/ops/tls.ts index 3e49c1c936..b52ad65bbe 100644 --- a/cli/js/ops/tls.ts +++ b/cli/js/ops/tls.ts @@ -26,7 +26,7 @@ interface ConnectTLSResponse { export async function connectTLS( args: ConnectTLSRequest ): Promise { - return await sendAsync("op_connect_tls", args); + return sendAsync("op_connect_tls", args); } interface AcceptTLSResponse { @@ -44,7 +44,7 @@ interface AcceptTLSResponse { } export async function acceptTLS(rid: number): Promise { - return await sendAsync("op_accept_tls", { rid }); + return sendAsync("op_accept_tls", { rid }); } export interface ListenTLSRequest { diff --git a/cli/js/ops/worker_host.ts b/cli/js/ops/worker_host.ts index a409d2c77a..1a7e671f4e 100644 --- a/cli/js/ops/worker_host.ts +++ b/cli/js/ops/worker_host.ts @@ -25,5 +25,5 @@ export function hostPostMessage(id: number, data: Uint8Array): void { } export async function hostGetMessage(id: number): Promise { - return await sendAsync("op_host_get_message", { id }); + return sendAsync("op_host_get_message", { id }); } diff --git a/cli/js/process.ts b/cli/js/process.ts index 9d0751eca2..991133047d 100644 --- a/cli/js/process.ts +++ b/cli/js/process.ts @@ -56,7 +56,7 @@ export class Process { } async status(): Promise { - return await runStatus(this.rid); + return runStatus(this.rid); } async output(): Promise { diff --git a/cli/js/tests/unit_test_runner.ts b/cli/js/tests/unit_test_runner.ts index fea6aa8da2..f03f5ce697 100755 --- a/cli/js/tests/unit_test_runner.ts +++ b/cli/js/tests/unit_test_runner.ts @@ -312,14 +312,14 @@ async function main(): Promise { // Master mode if (args.master) { - return await masterRunnerMain(args.verbose, filter); + return masterRunnerMain(args.verbose, filter); } // Worker mode if (args.worker) { assertOrHelp(typeof args.addr === "string"); assertOrHelp(typeof args.perms === "string"); - return await workerRunnerMain(args.addr, args.perms, filter); + return workerRunnerMain(args.addr, args.perms, filter); } // Running tests matching current process permissions diff --git a/cli/js/web/fetch.ts b/cli/js/web/fetch.ts index 3972da4f29..c7209943fc 100644 --- a/cli/js/web/fetch.ts +++ b/cli/js/web/fetch.ts @@ -453,7 +453,7 @@ async function sendFetchReq( headers: headerArray }; - return await opFetch(args, body); + return opFetch(args, body); } export async function fetch( diff --git a/core/examples/http_bench.js b/core/examples/http_bench.js index abe81e41e3..4314ba680f 100644 --- a/core/examples/http_bench.js +++ b/core/examples/http_bench.js @@ -85,7 +85,7 @@ function listen() { /** Accepts a connection, returns rid. */ async function accept(rid) { - return await sendAsync(ops["accept"], rid); + return sendAsync(ops["accept"], rid); } /** @@ -93,12 +93,12 @@ async function accept(rid) { * Returns bytes read. */ async function read(rid, data) { - return await sendAsync(ops["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) { - return await sendAsync(ops["write"], rid, data); + return sendAsync(ops["write"], rid, data); } function close(rid) { diff --git a/std/http/file_server.ts b/std/http/file_server.ts index a259acb3c4..18a68aa49d 100755 --- a/std/http/file_server.ts +++ b/std/http/file_server.ts @@ -126,7 +126,7 @@ async function serveDir( const fileUrl = posix.join(dirUrl, fileInfo.name ?? ""); if (fileInfo.name === "index.html" && fileInfo.isFile()) { // in case index.html as dir... - return await serveFile(req, filePath); + return serveFile(req, filePath); } // Yuck! let mode = null;