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

Add heuristics to detect assignments whose id has complex type annotations #10916

Merged
merged 6 commits into from May 23, 2021

Conversation

sosukesuzuki
Copy link
Member

@sosukesuzuki sosukesuzuki commented May 19, 2021

Description

Fixes #10850

Checklist

  • I’ve added tests to confirm my change works.
  • (If the change is user-facing) I’ve added my changes to changelog_unreleased/*/XXXX.md file following changelog_unreleased/TEMPLATE.md.
  • I’ve read the contributing guidelines.

Try the playground for this PR

}
}
}
return false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we return early?

@@ -0,0 +1 @@
run_spec(__dirname, ["babel-flow"]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Run test on flow parser too?

@@ -269,6 +273,48 @@ function isTypeAlias(node) {
return node.type === "TSTypeAliasDeclaration" || node.type === "TypeAlias";
}

function isComplexTypeAnnotationForAssignments(node) {
if (isAssignmentOrVariableDeclarator(node)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (isAssignmentOrVariableDeclarator(node)) {
if (node.type === "VariableDeclarator") {

@@ -269,6 +273,48 @@ function isTypeAlias(node) {
return node.type === "TSTypeAliasDeclaration" || node.type === "TypeAlias";
}

function isComplexTypeAnnotationForAssignments(node) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's rename to hasComplexTypeAnnotation

@@ -139,7 +139,7 @@ function chooseLayout(path, options, print, leftDoc, rightPropertyName) {
if (
isComplexDestructuring(node) ||
isComplexTypeAliasParams(node) ||
isComplexTypeAnnotationForAssignments(node)
isComplexTypeAnnotation(node)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant has..., not is.... The node itself isn't a type annotation.

@thorn0 thorn0 merged commit c40a0cf into prettier:main May 23, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 24, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ugly formatting for complex Map types in Flow and TS
3 participants