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

Make identifier lambdas parenless #1692

Merged
merged 3 commits into from
Dec 9, 2017
Merged

Conversation

jordwalke
Copy link
Member

@jordwalke jordwalke commented Dec 9, 2017

This partially addresses the issue that @bobzhang and @glennsl brought up about the new syntax having too many parens. I tried formatting a large project and noticed that the most jarring use of parens was:

  • Single identifiers in lambdas that had parens included.
  • Records arguments to lambdas that had parens included.

We can't really remove the parens around record arguments to lambdas at the moment because then it opens up this precedent which we cannot uphold for tuples.
But still, single identifier lambda arguments were the biggest offender of paren-fatigue in my example project.

cc @IwanKaramazow @chenglou @rickyvetter

Summary: Stop printing unneeded parens around single identifier
lambdas. This brings us closer to compatibility with the JS convention.

Test Plan:

Reviewers:

CC:
@@ -19,42 +19,42 @@ fff >>= xx(yy) >>= aa(bb);
fff >>= (xx(yy) >>= aa(bb));

Copy link
Member Author

Choose a reason for hiding this comment

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

@glennsl This is the kind of stuff this diff cleans up.

@@ -205,7 +205,7 @@ let selfClosing3 =
b="cause the entire thing to wrap"
/>;

Copy link
Member Author

Choose a reason for hiding this comment

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

And jsx callback arguments.

@@ -1084,7 +1084,7 @@ let server = {
)
)
>>= (
(body) =>
body =>
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm forgot this case in the callback PR.
The body => should dock on the same line as >>= (, shouldn't it?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not sure - printing these have bigger issues - like knowing when exactly we can omit the parens. We're fairly certain that determining when the () can be omitted is such a hard problem that it requires integration with the parser.

@chenglou chenglou merged commit 192248e into master Dec 9, 2017
@chenglou chenglou deleted the MakeIdentifierLambdasParenless branch December 9, 2017 08:39
chenglou added a commit that referenced this pull request Dec 9, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants