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

Long names cause strange line-breaks with Arrow Functions #61

Closed
AndruC opened this issue Jan 10, 2017 · 5 comments
Closed

Long names cause strange line-breaks with Arrow Functions #61

AndruC opened this issue Jan 10, 2017 · 5 comments
Labels
locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting.

Comments

@AndruC
Copy link

AndruC commented Jan 10, 2017

I've found a strange case when using Arrow functions, chaining methods off an object inside the arrow function.
image

If I shorten the length of the variable name
image
or shorten the first method name
image
then it collapses and displays more correctly.

I also noticed that changing the name of the otherLongfunctionName doesn't have any effect. In either case above, both long names push the line length beyond the acceptable length. This causes the arrow function parameters to be put on a new line, even though line-breaking after this would lead to a better result. IMO the "problem" examples I provided are already formatted ideally.

@jlongster
Copy link
Member

I think you should just move it into a proper block:

var oneLongVariableName = (foo, bar) => {
  return this.longerMethodName(c, service).forEach(otherLongFunctionName);
}

We don't really support arrow functions without blocks with code on the next line. It would be a hard special-case to format correctly without breaking other formats that involve arrow expressions.

@RamIdeas
Copy link

(Watching the twitch live stream)

I possible solution that would respect the case above, and the chains of - for example - promises, could be to align on the period, like:

var variable = (foo, bar) => this.methodName(...)
                                 .forEach(...);
promise.then( () => ... )
       .then( () => ... )
       .then( () => ... )

@rattrayalex
Copy link
Collaborator

rattrayalex commented Jan 10, 2017

I would really love to see this re-opened... cool if I try to tackle it as a first contribution? 😉

(EDIT: he is working on it again)

@jlongster jlongster reopened this Jan 10, 2017
@jlongster
Copy link
Member

@rattrayalex Sure! If I didn't just solve it, I'll leave it up to you :) I think I may have something works.

@jlongster
Copy link
Member

Ok, let's try this. I'm curious if this causes any other awkward formatting, but I think this works.

@lock lock bot added the locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. label Jul 8, 2018
@lock lock bot locked as resolved and limited conversation to collaborators Jul 8, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting.
Projects
None yet
Development

No branches or pull requests

4 participants