Skip to content

Commit

Permalink
Flow: Print trailing comma in type parameters when `--trailing-comma=…
Browse files Browse the repository at this point in the history
…es5` (#14085)
  • Loading branch information
fisker committed Feb 9, 2023
1 parent be84156 commit 62827ab
Show file tree
Hide file tree
Showing 18 changed files with 1,338 additions and 187 deletions.
40 changes: 40 additions & 0 deletions changelog_unreleased/flow/14085.md
@@ -0,0 +1,40 @@
#### [BREAKING] Print trailing comma in type parameters and tuple types when `--trailing-comma=es5` (#14086, #14085 by @fisker)

<!-- prettier-ignore -->
```js
// Input
type Foo = [
{
from: string,
to: string,
}, // <- 1
];
type Foo = Promise<
| { ok: true, bar: string, baz: SomeOtherLongType }
| { ok: false, bar: SomeOtherLongType }, // <- 2
>;

// Prettier stable
type Foo = [
{
from: string,
to: string,
} // <- 1
];
type Foo = Promise<
| { ok: true, bar: string, baz: SomeOtherLongType }
| { ok: false, bar: SomeOtherLongType } // <- 2
>;

// Prettier main
type Foo = [
{
from: string,
to: string,
}, // <- 1
];
type Foo = Promise<
| { ok: true, bar: string, baz: SomeOtherLongType }
| { ok: false, bar: SomeOtherLongType }, // <- 2
>;
```
2 changes: 1 addition & 1 deletion src/language-js/print/type-parameters.js
Expand Up @@ -79,7 +79,7 @@ function printTypeParameters(path, options, print, paramsKey) {
!node[paramsKey][0].constraint &&
path.parent.type === "ArrowFunctionExpression"
? ","
: shouldPrintComma(options, "all")
: shouldPrintComma(options)
? ifBreak(",")
: "";

Expand Down
Expand Up @@ -69,7 +69,7 @@ const selectorByPath:
const selectorByPath: (Path) => SomethingSelector<
SomethingUEditorContextType,
SomethingUEditorContextType,
SomethingBulkValue<string>
SomethingBulkValue<string>,
> = memoizeWithArgs(/* ... */);
================================================================================
Expand Down
6 changes: 3 additions & 3 deletions tests/format/flow/generic/__snapshots__/jsfmt.spec.js.snap
Expand Up @@ -63,7 +63,7 @@ var X = {
E,
F,
G,
T: (a: A, b: B, c: C, d: D, e: E, f: F) => G // eslint-disable-line space-before-function-paren
T: (a: A, b: B, c: C, d: D, e: E, f: F) => G, // eslint-disable-line space-before-function-paren
>(method: T, scope: any, a: A, b: B, c: C, d: D, e: E, f: F): G {},
};
Expand Down Expand Up @@ -316,7 +316,7 @@ type State = {
type State = {
errors: Immutable.Map<
Ahohohhohohohohohohohohohohooh,
Fbt | Immutable.Map<ErrorIndex, Fbt>
Fbt | Immutable.Map<ErrorIndex, Fbt>,
>,
shouldValidate: boolean,
};
Expand Down Expand Up @@ -398,7 +398,7 @@ type Foo = Promise<
=====================================output=====================================
type Foo = Promise<
| { ok: true, bar: string, baz: SomeOtherLongType }
| { ok: false, bar: SomeOtherLongType }
| { ok: false, bar: SomeOtherLongType },
>;
================================================================================
Expand Down

0 comments on commit 62827ab

Please sign in to comment.