From e6534ae132ad3897eeed1fd9ca0de93df7a2c836 Mon Sep 17 00:00:00 2001 From: sigmaSd Date: Sun, 17 Dec 2023 10:21:50 +0100 Subject: [PATCH] chore: lint blocking calls (#180) --- deno.json | 5 ++++- mod.test.ts | 6 +++--- src/commands/cat.ts | 2 +- src/deps.test.ts | 2 +- src/request.test.ts | 8 ++++---- 5 files changed, 13 insertions(+), 10 deletions(-) diff --git a/deno.json b/deno.json index e33c950..64c9628 100644 --- a/deno.json +++ b/deno.json @@ -9,7 +9,10 @@ }, "lint": { "rules": { - "exclude": ["ban-types", "no-explicit-any", "no-this-alias"] + "exclude": ["ban-types", "no-explicit-any", "no-this-alias"], + "include": [ + "no-sync-fn-in-async-fn" + ] } }, "exclude": [ diff --git a/mod.test.ts b/mod.test.ts index a454ada..5f4233b 100644 --- a/mod.test.ts +++ b/mod.test.ts @@ -1274,7 +1274,7 @@ Deno.test("cp test2", async () => { await withTempDir(async (dir) => { await $`mkdir -p a/d1`; await $`mkdir -p a/d2`; - Deno.createSync("a/d1/f").close(); + await Deno.create("a/d1/f").then((f) => f.close()); await $`cp a/d1/f a/d2`; assert(dir.join("a/d2/f").existsSync()); }); @@ -1430,12 +1430,12 @@ Deno.test("cd", () => { Deno.test("cat", async () => { await withTempDir(async () => { - Deno.writeTextFileSync("hello", "hello world"); + await Deno.writeTextFile("hello", "hello world"); assertEquals( await $`cat hello`.text(), "hello world", ); - Deno.writeTextFileSync("hello2", "hello world2"); + await Deno.writeTextFile("hello2", "hello world2"); assertEquals( await $`cat hello hello2`.text(), "hello worldhello world2", diff --git a/src/commands/cat.ts b/src/commands/cat.ts index 971b206..f516150 100644 --- a/src/commands/cat.ts +++ b/src/commands/cat.ts @@ -39,7 +39,7 @@ async function executeCat(context: CommandContext) { } else { let file; try { - file = Deno.openSync(pathUtils.join(context.cwd, path), { read: true }); + file = await Deno.open(pathUtils.join(context.cwd, path), { read: true }); while (true) { // NOTE: rust supports cancellation here const size = file.readSync(buf); diff --git a/src/deps.test.ts b/src/deps.test.ts index 1fbc553..0f2127c 100644 --- a/src/deps.test.ts +++ b/src/deps.test.ts @@ -18,7 +18,7 @@ export { serve } from "https://deno.land/std@0.201.0/http/server.ts"; */ export async function withTempDir(action: (path: PathRef) => Promise | void) { const originalDirPath = Deno.cwd(); - const dirPath = Deno.makeTempDirSync(); + const dirPath = await Deno.makeTempDir(); Deno.chdir(dirPath); try { await action(createPathRef(dirPath).resolve()); diff --git a/src/request.test.ts b/src/request.test.ts index 65148fc..f1de046 100644 --- a/src/request.test.ts +++ b/src/request.test.ts @@ -108,7 +108,7 @@ Deno.test("$.request", (t) => { }); step("pipeToPath", async () => { - const testFilePath = Deno.makeTempFileSync(); + const testFilePath = await Deno.makeTempFile(); const originDir = Deno.cwd(); try { { @@ -121,7 +121,7 @@ Deno.test("$.request", (t) => { } { // test default path - Deno.chdir(Deno.makeTempDirSync()); // change path just to not download to the current dir + Deno.chdir(await Deno.makeTempDir()); // change path just to not download to the current dir const downloadedFilePath = await new RequestBuilder() .url(new URL("/text-file", serverUrl)) .showProgress() @@ -151,7 +151,7 @@ Deno.test("$.request", (t) => { } { // test downloading to a directory - const tempDir = Deno.makeTempDirSync(); + const tempDir = await Deno.makeTempDir(); const downloadedFilePath = await new RequestBuilder() .url(new URL("/text-file", serverUrl)) .showProgress() @@ -162,7 +162,7 @@ Deno.test("$.request", (t) => { } finally { try { Deno.chdir(originDir); - Deno.removeSync(testFilePath); + await Deno.remove(testFilePath); } catch { // do nothing }