mirror of
https://github.com/denoland/deno.git
synced 2025-01-03 04:48:52 -05:00
fix: [prettier] deno fmt should format jsx/tsx files (#3118)
This commit is contained in:
parent
4b7204babe
commit
5f5583cf19
4 changed files with 16 additions and 5 deletions
|
@ -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";
|
||||
|
|
|
@ -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<void> {
|
|||
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<void> {
|
|||
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]);
|
||||
|
|
2
std/prettier/testdata/3.jsx
vendored
Normal file
2
std/prettier/testdata/3.jsx
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
<div>
|
||||
</div>
|
3
std/prettier/testdata/4.tsx
vendored
Normal file
3
std/prettier/testdata/4.tsx
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
<div>
|
||||
</div>
|
||||
|
Loading…
Reference in a new issue