From 4347148d507868d508782f154f2b49dbe6ea359b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Sun, 24 Mar 2019 16:26:47 +0100 Subject: [PATCH] Fix prettier check in empty files (denoland/deno_std#302) Original: https://github.com/denoland/deno_std/commit/e5a493e9e8df80abec51c06958dea755e19c40fd --- prettier/main.ts | 4 ++-- prettier/main_test.ts | 6 +++++- prettier/testdata/2.ts | 0 3 files changed, 7 insertions(+), 3 deletions(-) create mode 100644 prettier/testdata/2.ts diff --git a/prettier/main.ts b/prettier/main.ts index a5e11e79fd..f4a2232ccb 100755 --- a/prettier/main.ts +++ b/prettier/main.ts @@ -107,8 +107,8 @@ async function checkFile( const text = await readFileIfExists(filename); if (!text) { - // The file is deleted. Skip. - return; + // The file is empty. Skip. + return true; } const formatted = prettier.check(text, { diff --git a/prettier/main_test.ts b/prettier/main_test.ts index 0d60150803..10ad79e36b 100644 --- a/prettier/main_test.ts +++ b/prettier/main_test.ts @@ -48,7 +48,11 @@ async function clearTestdataChanges(): Promise { test(async function testPrettierCheckAndFormatFiles() { await clearTestdataChanges(); - const files = [join(testdata, "0.ts"), join(testdata, "1.js")]; + const files = [ + join(testdata, "0.ts"), + join(testdata, "1.js"), + join(testdata, "2.ts") + ]; var { code, stdout } = await run([...cmd, "--check", ...files]); assertEquals(code, 1); diff --git a/prettier/testdata/2.ts b/prettier/testdata/2.ts new file mode 100644 index 0000000000..e69de29bb2