Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix formatting of empty type parameters #14073

Merged
merged 9 commits into from Dec 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 13 additions & 0 deletions changelog_unreleased/flow/14073.md
@@ -0,0 +1,13 @@
#### Fix formatting of empty type parameters (#14073 by @fisker)

<!-- prettier-ignore -->
```jsx
// Input
const foo: bar</* comment */> = () => baz;

// Prettier stable
Error: Comment "comment" was not printed. Please report this error!

// Prettier main
const foo: bar</* comment */> = () => baz;
```
12 changes: 6 additions & 6 deletions src/language-js/print/type-parameters.js
Expand Up @@ -44,12 +44,12 @@ function printTypeParameters(path, options, print, paramsKey) {
);

const shouldInline =
!isArrowFunctionVariable &&
(isParameterInTestCall ||
node[paramsKey].length === 0 ||
(node[paramsKey].length === 1 &&
(node[paramsKey][0].type === "NullableTypeAnnotation" ||
shouldHugType(node[paramsKey][0]))));
node[paramsKey].length === 0 ||
(!isArrowFunctionVariable &&
(isParameterInTestCall ||
(node[paramsKey].length === 1 &&
(node[paramsKey][0].type === "NullableTypeAnnotation" ||
shouldHugType(node[paramsKey][0])))));

if (shouldInline) {
return [
Expand Down
@@ -0,0 +1,35 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`issue-13817.ts - {"arrowParens":"avoid","trailingComma":"all"} format 1`] = `
====================================options=====================================
arrowParens: "avoid"
parsers: ["typescript", "flow", "babel-flow"]
printWidth: 80
trailingComma: "all"
| printWidth
=====================================input======================================
const xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx: xxxxxxxxxxxxxxxxxxxxxx<> =
arg => null;

const xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx: xxxxxxxxxxxxxxxxxxxxxx</* comment */> =
arg => null;


const xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx: xxxxxxxxxxxxxxxxxxxxxx<
// comment
> =
arg => null;

=====================================output=====================================
const xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx: xxxxxxxxxxxxxxxxxxxxxx<> =
arg => null;

const xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx: xxxxxxxxxxxxxxxxxxxxxx</* comment */> =
arg => null;

const xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx: xxxxxxxxxxxxxxxxxxxxxx<
// comment
> = arg => null;

================================================================================
`;
@@ -0,0 +1,11 @@
const xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx: xxxxxxxxxxxxxxxxxxxxxx<> =
arg => null;

const xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx: xxxxxxxxxxxxxxxxxxxxxx</* comment */> =
arg => null;


const xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx: xxxxxxxxxxxxxxxxxxxxxx<
// comment
> =
arg => null;
@@ -0,0 +1,6 @@
run_spec(
__dirname,
["typescript", "flow", "babel-flow"],
// #13817 require those options to reproduce
{ arrowParens: "avoid", trailingComma: "all" }
);