Do not print trailing commas in arrow function type parameter lists in ts code blocks (#15286)
* Remove trailing comma for `ts` code blocks * Add changelog * Support `typescript` * Update link * Update tests
This commit is contained in:
1 parent
347c60730e
commit
90fab608ae
5 files changed
+62
-2
No files matched your search
@@ -0,0 +1,19 @@
|
||||
#### Do not print trailing commas in arrow function type parameter lists in `ts` code blocks (#15286 by @sosukesuzuki)
|
||||
|
||||
<!-- prettier-ignore -->
|
||||
````md
|
||||
<!-- Input -->
|
||||
```ts
|
||||
const foo = <T>() => {}
|
||||
```
|
||||
|
||||
<!-- Prettier stable -->
|
||||
```ts
|
||||
const foo = <T,>() => {}
|
||||
```
|
||||
|
||||
<!-- Prettier main -->
|
||||
```ts
|
||||
const foo = <T>() => {}
|
||||
```
|
||||
````
|
||||
@@ -40,7 +40,7 @@ function createParseError(error) {
|
||||
});
|
||||
}
|
||||
|
||||
// https://typescript-eslint.io/architecture/parser/#jsx
|
||||
// https://typescript-eslint.io/packages/parser/#jsx
|
||||
const isKnownFileType = (filepath) =>
|
||||
/\.(?:js|mjs|cjs|jsx|ts|mts|cts|tsx)$/i.test(filepath);
|
||||
|
||||
|
||||
@@ -17,7 +17,14 @@ function embed(path, options) {
|
||||
Math.max(3, getMaxContinuousCount(node.value, styleUnit) + 1),
|
||||
);
|
||||
const newOptions = { parser };
|
||||
if (node.lang === "tsx") {
|
||||
|
||||
// Override the filepath option.
|
||||
// This is because whether the trailing comma of type parameters
|
||||
// should be printed depends on whether it is `*.ts` or `*.tsx`.
|
||||
// https://github.com/prettier/prettier/issues/15282
|
||||
if (node.lang === "ts" || node.lang === "typescript") {
|
||||
newOptions.filepath = "dummy.ts";
|
||||
} else if (node.lang === "tsx") {
|
||||
newOptions.filepath = "dummy.tsx";
|
||||
}
|
||||
|
||||
|
||||
@@ -291,6 +291,33 @@ hello world
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`ts-trailing-comma.md - {"proseWrap":"always"} format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["markdown"]
|
||||
printWidth: 80
|
||||
proseWrap: "always"
|
||||
| printWidth
|
||||
=====================================input======================================
|
||||
\`\`\`ts
|
||||
const test = <T,>(value: T) => {};
|
||||
\`\`\`
|
||||
|
||||
\`\`\`typescript
|
||||
const test = <T,>(value: T) => {};
|
||||
\`\`\`
|
||||
|
||||
=====================================output=====================================
|
||||
\`\`\`ts
|
||||
const test = <T>(value: T) => {};
|
||||
\`\`\`
|
||||
|
||||
\`\`\`typescript
|
||||
const test = <T>(value: T) => {};
|
||||
\`\`\`
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`tsx-trailing-comma.md - {"proseWrap":"always"} format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["markdown"]
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
```ts
|
||||
const test = <T,>(value: T) => {};
|
||||
```
|
||||
|
||||
```typescript
|
||||
const test = <T,>(value: T) => {};
|
||||
```
|
||||
Reference in new issue
Block a user