From 5f5583cf19349d19f717f65312558588825ad7b8 Mon Sep 17 00:00:00 2001 From: Yusuke Sakurai Date: Sun, 13 Oct 2019 04:55:05 +0900 Subject: [PATCH] fix: [prettier] deno fmt should format jsx/tsx files (#3118) --- std/prettier/main.ts | 4 ++-- std/prettier/main_test.ts | 12 +++++++++--- std/prettier/testdata/3.jsx | 2 ++ std/prettier/testdata/4.tsx | 3 +++ 4 files changed, 16 insertions(+), 5 deletions(-) create mode 100644 std/prettier/testdata/3.jsx create mode 100644 std/prettier/testdata/4.tsx diff --git a/std/prettier/main.ts b/std/prettier/main.ts index bd9238be20..2937a9751d 100755 --- a/std/prettier/main.ts +++ b/std/prettier/main.ts @@ -191,9 +191,9 @@ async function formatFile( * Selects the right prettier parser for the given path. */ function selectParser(path: string): ParserLabel | null { - if (/\.ts$/.test(path)) { + if (/\.tsx?$/.test(path)) { return "typescript"; - } else if (/\.js$/.test(path)) { + } else if (/\.jsx?$/.test(path)) { return "babel"; } else if (/\.json$/.test(path)) { return "json"; diff --git a/std/prettier/main_test.ts b/std/prettier/main_test.ts index 56d031b649..65a963c02a 100644 --- a/std/prettier/main_test.ts +++ b/std/prettier/main_test.ts @@ -26,8 +26,9 @@ const cmd = [ "--allow-run", "--allow-write", "--allow-read", - "prettier/main.ts" + "./prettier/main.ts" ]; + const testdata = join("prettier", "testdata"); function normalizeOutput(output: string): string { @@ -51,7 +52,9 @@ test(async function testPrettierCheckAndFormatFiles(): Promise { const files = [ join(tempDir, "0.ts"), join(tempDir, "1.js"), - join(tempDir, "2.ts") + join(tempDir, "2.ts"), + join(tempDir, "3.jsx"), + join(tempDir, "4.tsx") ]; let p = await run([...cmd, "--check", ...files]); @@ -63,7 +66,10 @@ test(async function testPrettierCheckAndFormatFiles(): Promise { assertEquals( normalizeOutput(p.stdout), normalizeOutput(`Formatting ${tempDir}/0.ts -Formatting ${tempDir}/1.js`) +Formatting ${tempDir}/1.js +Formatting ${tempDir}/3.jsx +Formatting ${tempDir}/4.tsx +`) ); p = await run([...cmd, "--check", ...files]); diff --git a/std/prettier/testdata/3.jsx b/std/prettier/testdata/3.jsx new file mode 100644 index 0000000000..d58db9e7bf --- /dev/null +++ b/std/prettier/testdata/3.jsx @@ -0,0 +1,2 @@ +
+
diff --git a/std/prettier/testdata/4.tsx b/std/prettier/testdata/4.tsx new file mode 100644 index 0000000000..88d34f7faa --- /dev/null +++ b/std/prettier/testdata/4.tsx @@ -0,0 +1,3 @@ +
+
+